Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ament to build #214

Open
wants to merge 9 commits into
base: ros2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 73 additions & 56 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,80 +1,97 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(serial)

# Find catkin
find_package(catkin REQUIRED)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Add support for C++11
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)

if(APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
endif()

if(UNIX AND NOT APPLE)
# If Linux, add rt and pthread
set(rt_LIBRARIES rt)
set(pthread_LIBRARIES pthread)
catkin_package(
LIBRARIES ${PROJECT_NAME}
INCLUDE_DIRS include
DEPENDS rt pthread
)
else()
# Otherwise normal call
catkin_package(
LIBRARIES ${PROJECT_NAME}
INCLUDE_DIRS include
)
set(RT_LIBRARIES rt)
set(PTHREAD_LIBRARIES pthread)
endif()

## Sources
set(serial_SRCS
src/serial.cc
include/serial/serial.h
include/serial/v8stdint.h
)
set(SERIAL_SRCS
src/serial.cc)

if(APPLE)
# If OSX
list(APPEND serial_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_osx.cc)
list(APPEND SERIAL_SRCS src/impl/unix.cc)
elseif(UNIX)
# If unix
list(APPEND serial_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_linux.cc)
list(APPEND SERIAL_SRCS src/impl/unix.cc)
else()
# If windows
list(APPEND serial_SRCS src/impl/win.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_win.cc)
list(APPEND SERIAL_SRCS src/impl/win.cc)
endif()

## Add serial library
add_library(${PROJECT_NAME} ${serial_SRCS})
add_library(${PROJECT_NAME} SHARED
${SERIAL_SRCS})

if(APPLE)
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
target_link_libraries(${PROJECT_NAME} rt pthread)
target_link_libraries(${PROJECT_NAME} rt pthread)
else()
target_link_libraries(${PROJECT_NAME} setupapi)
target_link_libraries(${PROJECT_NAME} setupapi)
endif()

## Uncomment for example
add_executable(serial_example examples/serial_example.cc)
add_dependencies(serial_example ${PROJECT_NAME})
target_link_libraries(serial_example ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

install(
DIRECTORY include/
DESTINATION include)

install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

## Include headers
include_directories(include)
ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})

## Install executable
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)
if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)

## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
if(UNIX)
ament_add_gmock(${PROJECT_NAME}-test
tests/unix_serial_tests.cc)

## Tests
if(CATKIN_ENABLE_TESTING)
add_subdirectory(tests)
if(TARGET ${PROJECT_NAME}-test)
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES})

if(NOT APPLE)
target_link_libraries(${PROJECT_NAME}-test util)
endif()
endif()
endif()

if(NOT APPLE) # these tests are unreliable on macOS
ament_add_gmock(${PROJECT_NAME}-test-timer
tests/unit/unix_timer_tests.cc)
target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME})
endif()
endif()

ament_package()
10 changes: 7 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<package>
<?xml version='1.0' encoding='utf-8'?>
<package format="2">
zmichaels11 marked this conversation as resolved.
Show resolved Hide resolved
<name>serial</name>
<version>1.2.1</version>
<description>
Expand All @@ -19,8 +19,12 @@
<author email="[email protected]">William Woodall</author>
<author email="[email protected]">John Harrison</author>

<buildtool_depend>catkin</buildtool_depend>
<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_cmake_gmock</test_depend>
<test_depend>boost</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
8 changes: 4 additions & 4 deletions src/impl/list_ports/list_ports_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ glob(const vector<string>& patterns)

glob_t glob_results;

int glob_retval = glob(patterns[0].c_str(), 0, NULL, &glob_results);
glob(patterns[0].c_str(), 0, NULL, &glob_results);

vector<string>::const_iterator iter = patterns.begin();

while(++iter != patterns.end())
{
glob_retval = glob(iter->c_str(), GLOB_APPEND, NULL, &glob_results);
glob(iter->c_str(), GLOB_APPEND, NULL, &glob_results);
}

for(int path_index = 0; path_index < glob_results.gl_pathc; path_index++)
for(unsigned int path_index = 0; path_index < glob_results.gl_pathc; path_index++)
{
paths_found.push_back(glob_results.gl_pathv[path_index]);
}
Expand Down Expand Up @@ -243,7 +243,7 @@ format(const char* format, ...)
{
done = true;
}
else if( return_value >= buffer_size_bytes )
else if(static_cast<unsigned int>(return_value) >= buffer_size_bytes)
{
// Realloc and try again.

Expand Down
12 changes: 0 additions & 12 deletions tests/CMakeLists.txt

This file was deleted.