From eefc0ef61683fbc5674f7e40c57afbdf0cad536a Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Thu, 7 Nov 2019 14:24:06 -0800 Subject: [PATCH 1/9] Convert catkin to ament --- CMakeLists.txt | 107 ++++++++++++++++++++++++++++++------------------- package.xml | 11 +++-- 2 files changed, 73 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1474ad1..7111d92b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,59 +1,74 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.5) project(serial) +# Add support for C++11 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif() + +find_package(ament_cmake REQUIRED) + +set(INCLUDE_DIRS include ${ament_cmake_INCLUDE_DIRS}) +include_directories(${INCLUDE_DIRS}) + +set(LIBRARY_DIRS ${ament_cmake_LIBRARY_DIRS}) + +link_directories(${LIBRARY_DIRS}) + +set(LIBS ${ament_cmake_LIBRARIES}) + +# Add support for C++11 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif() + +find_package(ament_cmake REQUIRED) + +set(INCLUDE_DIRS include ${ament_cmake_INCLUDE_DIRS}) + +set(LIBRARY_DIRS ${ament_cmake_LIBRARY_DIRS}) + +set(LIBS ${ament_cmake_LIBRARIES}) + # Find catkin -find_package(catkin 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 - ) + # If Linux, add rt and pthread + set(rt_LIBRARIES rt) + set(pthread_LIBRARIES pthread) else() - # Otherwise normal call - catkin_package( - LIBRARIES ${PROJECT_NAME} - INCLUDE_DIRS include - ) + # Otherwise normal call endif() ## Sources -set(serial_SRCS - src/serial.cc - include/serial/serial.h - include/serial/v8stdint.h -) +set(serial_SRCS src/serial.cc include/serial/serial.h include/serial/v8stdint.h) if(APPLE) - # If OSX - list(APPEND serial_SRCS src/impl/unix.cc) - list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc) + # If OSX + list(APPEND serial_SRCS src/impl/unix.cc) + list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.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) + # If unix + list(APPEND serial_SRCS src/impl/unix.cc) + list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc) else() - # If windows - list(APPEND serial_SRCS src/impl/win.cc) - list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc) + # If windows + list(APPEND serial_SRCS src/impl/win.cc) + list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc) endif() ## Add serial library add_library(${PROJECT_NAME} ${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 @@ -62,19 +77,27 @@ add_dependencies(serial_example ${PROJECT_NAME}) target_link_libraries(serial_example ${PROJECT_NAME}) ## Include headers -include_directories(include) ## Install executable -install(TARGETS ${PROJECT_NAME} - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -) +install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib) ## Install headers install(FILES include/serial/serial.h include/serial/v8stdint.h - DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial) + DESTINATION include/serial) ## Tests -if(CATKIN_ENABLE_TESTING) - add_subdirectory(tests) +if(BUILD_TESTING) + add_subdirectory(tests) endif() + +ament_export_dependencies(ament_cmake) +ament_export_include_directories(${INCLUDE_DIRS}) +ament_export_libraries(${PROJECT_NAME} ${LIBS}) + +ament_package() + +ament_export_dependencies(ament_cmake) +ament_export_include_directories(${INCLUDE_DIRS}) +ament_export_libraries(${PROJECT_NAME} ${LIBS}) + +ament_package() diff --git a/package.xml b/package.xml index 27781e14..c1a16cee 100644 --- a/package.xml +++ b/package.xml @@ -1,5 +1,5 @@ - - + + serial 1.2.1 @@ -19,8 +19,13 @@ William Woodall John Harrison - catkin + ament_cmake boost + + ament_cmake + + + ament_cmake From e7f16cb77ce41dda7152b16e7d9040b46feaff81 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 11 Nov 2019 09:48:05 -0800 Subject: [PATCH 2/9] Use ament in CMakeLists.txt Signed-off-by: Zachary Michaels --- CMakeLists.txt | 98 ++++++++++++++++++-------------------------------- package.xml | 4 +-- 2 files changed, 36 insertions(+), 66 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7111d92b..b98b02c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,22 @@ cmake_minimum_required(VERSION 3.5) project(serial) -# Add support for C++11 -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) +# Default to C99 +if(NOT CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 99) endif() -find_package(ament_cmake REQUIRED) - -set(INCLUDE_DIRS include ${ament_cmake_INCLUDE_DIRS}) -include_directories(${INCLUDE_DIRS}) - -set(LIBRARY_DIRS ${ament_cmake_LIBRARY_DIRS}) - -link_directories(${LIBRARY_DIRS}) - -set(LIBS ${ament_cmake_LIBRARIES}) - # Add support for C++11 if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD 14) endif() -find_package(ament_cmake REQUIRED) - -set(INCLUDE_DIRS include ${ament_cmake_INCLUDE_DIRS}) - -set(LIBRARY_DIRS ${ament_cmake_LIBRARY_DIRS}) - -set(LIBS ${ament_cmake_LIBRARIES}) +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic -Werror) +endif() -# Find catkin +# find dependencies +find_package(ament_cmake REQUIRED) if(APPLE) find_library(IOKIT_LIBRARY IOKit) @@ -38,31 +24,27 @@ if(APPLE) endif() if(UNIX AND NOT APPLE) - # If Linux, add rt and pthread - set(rt_LIBRARIES rt) - set(pthread_LIBRARIES pthread) -else() - # Otherwise normal call + 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}) elseif(UNIX) @@ -71,33 +53,21 @@ else() 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 + $ + $) -## Include headers +install( + DIRECTORY include/ + DESTINATION include) -## Install executable -install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib) +ament_export_include_directories(include) +ament_export_libraries(${PROJECT_NAME}) -## Install headers -install(FILES include/serial/serial.h include/serial/v8stdint.h - DESTINATION include/serial) - -## Tests if(BUILD_TESTING) - add_subdirectory(tests) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() endif() -ament_export_dependencies(ament_cmake) -ament_export_include_directories(${INCLUDE_DIRS}) -ament_export_libraries(${PROJECT_NAME} ${LIBS}) - -ament_package() - -ament_export_dependencies(ament_cmake) -ament_export_include_directories(${INCLUDE_DIRS}) -ament_export_libraries(${PROJECT_NAME} ${LIBS}) - ament_package() diff --git a/package.xml b/package.xml index c1a16cee..4e1946c0 100644 --- a/package.xml +++ b/package.xml @@ -21,11 +21,11 @@ ament_cmake + ament_lint_auto + ament_lint_common boost ament_cmake - - ament_cmake From 0b9d5d5f9fbbf19f14549ce023a7548e3a35e198 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 11 Nov 2019 09:57:00 -0800 Subject: [PATCH 3/9] cast to unsigned for comparisons --- src/impl/list_ports/list_ports_linux.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/impl/list_ports/list_ports_linux.cc b/src/impl/list_ports/list_ports_linux.cc index 9779d5eb..bd67fff3 100644 --- a/src/impl/list_ports/list_ports_linux.cc +++ b/src/impl/list_ports/list_ports_linux.cc @@ -54,16 +54,16 @@ glob(const vector& 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::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]); } @@ -243,7 +243,7 @@ format(const char* format, ...) { done = true; } - else if( return_value >= buffer_size_bytes ) + else if(static_cast(return_value) >= buffer_size_bytes) { // Realloc and try again. From 288e99447995c39edbe9d24f7a8f5b5d81c04fa7 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Thu, 14 Nov 2019 10:25:49 -0800 Subject: [PATCH 4/9] Disable linting Signed-off-by: Zachary Michaels --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b98b02c5..390b93a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,8 +66,6 @@ ament_export_include_directories(include) ament_export_libraries(${PROJECT_NAME}) if(BUILD_TESTING) - find_package(ament_lint_auto REQUIRED) - ament_lint_auto_find_test_dependencies() endif() ament_package() From 39cee03b6033ffa326dd8e17b7b556185be63610 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 18 Nov 2019 09:09:50 -0800 Subject: [PATCH 5/9] Enable tests Signed-off-by: Zachary Michaels --- CMakeLists.txt | 29 +++++++++++++++++++++++++++++ package.xml | 3 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 390b93a3..f6de602d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,14 +58,43 @@ target_include_directories(${PROJECT_NAME} $ $) +ament_target_dependencies(${PROJECT_NAME} + ament_index_cpp) + install( DIRECTORY include/ DESTINATION include) +install( + TARGETS ${PROJECT_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) + ament_export_include_directories(include) ament_export_libraries(${PROJECT_NAME}) if(BUILD_TESTING) + find_package(ament_cmake_gmock REQUIRED) + + if(UNIX) + ament_add_gmock(${PROJECT_NAME}-test + tests/unix_serial_tests.cc) + + 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() diff --git a/package.xml b/package.xml index 4e1946c0..07e5acea 100644 --- a/package.xml +++ b/package.xml @@ -21,8 +21,7 @@ ament_cmake - ament_lint_auto - ament_lint_common + ament_cmake_gmock boost From 2fc44b687187aee24af149a3fc1a07ba23d3a166 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 18 Nov 2019 09:11:02 -0800 Subject: [PATCH 6/9] Remove unused CMakeLists (tests now defined in root) Signed-off-by: Zachary Michaels --- tests/CMakeLists.txt | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 tests/CMakeLists.txt diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index e52a4d31..00000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -if(UNIX) - catkin_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc) - target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES}) - if(NOT APPLE) - target_link_libraries(${PROJECT_NAME}-test util) - endif() - - if(NOT APPLE) # these tests are unreliable on macOS - catkin_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) - target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME}) - endif() -endif() From 013f9cf8d1e3333836d18e0ac5b8e4bb1c199203 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 18 Nov 2019 09:43:36 -0800 Subject: [PATCH 7/9] Remove dependency on ament_index_cpp unused dependency Signed-off-by: Zachary Michaels --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6de602d..67adfc5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,9 +58,6 @@ target_include_directories(${PROJECT_NAME} $ $) -ament_target_dependencies(${PROJECT_NAME} - ament_index_cpp) - install( DIRECTORY include/ DESTINATION include) From 22a104a70c11953a5b57439a94c60e56fce15440 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 20 Nov 2019 15:23:19 -0800 Subject: [PATCH 8/9] Set package.xml format to 3 Signed-off-by: Zachary Michaels --- package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.xml b/package.xml index 07e5acea..a8d3b091 100644 --- a/package.xml +++ b/package.xml @@ -1,5 +1,5 @@ - + serial 1.2.1 From ad3897cc8f648c00edebfaefde8f76320be91112 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Thu, 21 Nov 2019 09:35:26 -0800 Subject: [PATCH 9/9] Remove dependency on Boost (unused) Signed-off-by: Zachary Michaels --- package.xml | 1 - tests/unix_serial_tests.cc | 2 -- 2 files changed, 3 deletions(-) diff --git a/package.xml b/package.xml index a8d3b091..2019a7cc 100644 --- a/package.xml +++ b/package.xml @@ -22,7 +22,6 @@ ament_cmake ament_cmake_gmock - boost ament_cmake diff --git a/tests/unix_serial_tests.cc b/tests/unix_serial_tests.cc index 26ffde2d..c34868a2 100644 --- a/tests/unix_serial_tests.cc +++ b/tests/unix_serial_tests.cc @@ -20,8 +20,6 @@ void loop() #include #include "gtest/gtest.h" -#include - // Use FRIEND_TEST... its not as nasty, thats what friends are for // // OMG this is so nasty... // #define private public