From 7430d521e080e864d61ddd046256d7a674b28f95 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 5 Apr 2019 20:07:32 -0500 Subject: [PATCH 1/7] Migrated to ROS2 Followed migration instructions in https://index.ros.org/doc/ros2/Contributing/Migration-Guide/ --- CMakeLists.txt | 30 ++++++++++++------------------ package.xml | 6 +++++- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1474ad1..cb0367ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,20 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.5) project(serial) -# Find catkin -find_package(catkin REQUIRED) +find_package(ament_cmake REQUIRED) if(APPLE) find_library(IOKIT_LIBRARY IOKit) find_library(FOUNDATION_LIBRARY Foundation) endif() +ament_export_include_directories(include) +ament_export_libraries(${PROJECT_NAME}) 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 - ) + ament_export_dependencies(rt pthread) endif() ## Sources @@ -66,15 +57,18 @@ include_directories(include) ## Install executable install(TARGETS ${PROJECT_NAME} - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + 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) +if(BUILD_TESTING) add_subdirectory(tests) endif() + +ament_package() diff --git a/package.xml b/package.xml index 27781e14..f1ac9d3a 100644 --- a/package.xml +++ b/package.xml @@ -19,8 +19,12 @@ William Woodall John Harrison - catkin + ament_cmake boost + + ament_cmake + + From 8900d469e524d1c19ee83a662d1d28e47b8d22b8 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Wed, 10 Apr 2019 15:41:11 -0500 Subject: [PATCH 2/7] Add setupapi to ament_export_libraries This prevents dependent libraries from failing with something like: serial.lib(list_ports_win.obj) : error LNK2019: unresolved external symbol __imp_SetupDiEnumDeviceInfo referenced in --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb0367ef..a135e87a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ elseif(UNIX) target_link_libraries(${PROJECT_NAME} rt pthread) else() target_link_libraries(${PROJECT_NAME} setupapi) + ament_export_libraries(setupapi) endif() ## Uncomment for example From 51741829c024d14a90950d9d77422338a09ddd9e Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Mon, 22 Apr 2019 20:09:09 -0500 Subject: [PATCH 3/7] Fix the build and cleanup CMakeLists --- CMakeLists.txt | 75 ++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a135e87a..1dc6c660 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,58 +3,49 @@ project(serial) find_package(ament_cmake REQUIRED) -if(APPLE) - find_library(IOKIT_LIBRARY IOKit) - find_library(FOUNDATION_LIBRARY Foundation) -endif() - ament_export_include_directories(include) ament_export_libraries(${PROJECT_NAME}) -if(UNIX AND NOT APPLE) - # If Linux, add rt and pthread - set(rt_LIBRARIES rt) - set(pthread_LIBRARIES pthread) - ament_export_dependencies(rt pthread) -endif() ## Sources -set(serial_SRCS +## Add serial library +add_library(${PROJECT_NAME} 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) -elseif(UNIX) - # 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) -endif() -## Add serial library -add_library(${PROJECT_NAME} ${serial_SRCS}) -if(APPLE) - target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) -elseif(UNIX) - target_link_libraries(${PROJECT_NAME} rt pthread) -else() - target_link_libraries(${PROJECT_NAME} setupapi) +if(APPLE) # macOS + find_library(IOKIT_LIBRARY IOKit) + find_library(FOUNDATION_LIBRARY Foundation) + target_sources(${PROJECT_NAME} PRIVATE + src/impl/unix.cc + src/impl/list_ports/list_ports_osx.cc + ) + target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) +elseif(UNIX) # .*nix + target_sources(${PROJECT_NAME} PRIVATE + src/impl/unix.cc + src/impl/list_ports/list_ports_linux.cc + ) + target_link_libraries(${PROJECT_NAME} rt pthread) +elseif(WIN32) # Windows + target_sources(${PROJECT_NAME} PRIVATE + src/impl/win.cc + src/impl/list_ports/list_ports_win.cc + ) + target_link_libraries(${PROJECT_NAME} setupapi) ament_export_libraries(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}) ## Include headers -include_directories(include) +target_include_directories(${PROJECT_NAME} PRIVATE include) + +## Uncomment for example +# add_executable(serial_example examples/serial_example.cc) +# add_dependencies(serial_example ${PROJECT_NAME}) +# target_link_libraries(serial_example ${PROJECT_NAME}) + ## Install executable install(TARGETS ${PROJECT_NAME} @@ -64,12 +55,12 @@ install(TARGETS ${PROJECT_NAME} ## Install headers install(FILES include/serial/serial.h include/serial/v8stdint.h - DESTINATION include/serial + DESTINATION include/serial ) ## Tests -if(BUILD_TESTING) - add_subdirectory(tests) -endif() +#if(BUILD_TESTING) +# add_subdirectory(tests) +#endif() ament_package() From f6bd881babeae71f49485f445bfe75d848c450be Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 3 Jul 2019 14:09:10 -0700 Subject: [PATCH 4/7] Convert package to ament_cmake --- CMakeLists.txt | 36 ++++++++++++------------------------ package.xml | 6 +++++- tests/CMakeLists.txt | 7 +++++-- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1474ad1..e861baf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,14 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.5) project(serial) -# Find catkin -find_package(catkin REQUIRED) +# Find ament_cmake +find_package(ament_cmake REQUIRED) if(APPLE) 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 - ) -endif() - ## Sources set(serial_SRCS src/serial.cc @@ -66,15 +49,20 @@ include_directories(include) ## Install executable install(TARGETS ${PROJECT_NAME} - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + 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) +if(BUILD_TESTING) add_subdirectory(tests) endif() + +ament_export_include_directories(include) +ament_export_libraries(${PROJECT_NAME}) + +ament_package() diff --git a/package.xml b/package.xml index 27781e14..7fb772da 100644 --- a/package.xml +++ b/package.xml @@ -19,8 +19,12 @@ William Woodall John Harrison - catkin + ament_cmake + ament_cmake_gtest boost + + ament_cmake + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e52a4d31..964f27cf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,15 @@ if(UNIX) - catkin_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc) + find_package(ament_cmake_gtest REQUIRED) + find_package(Boost REQUIRED) + + ament_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) + ament_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME}) endif() endif() From 7fe3be8d5f24db9837fff7e5b2fc45dcb464eef0 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Tue, 8 Sep 2020 11:09:06 -0500 Subject: [PATCH 5/7] Remove test that breaks the build --- tests/CMakeLists.txt | 5 --- tests/unit/unix_timer_tests.cc | 63 ---------------------------------- 2 files changed, 68 deletions(-) delete mode 100644 tests/unit/unix_timer_tests.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 964f27cf..c9352529 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,9 +7,4 @@ if(UNIX) if(NOT APPLE) target_link_libraries(${PROJECT_NAME}-test util) endif() - - if(NOT APPLE) # these tests are unreliable on macOS - ament_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) - target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME}) - endif() endif() diff --git a/tests/unit/unix_timer_tests.cc b/tests/unit/unix_timer_tests.cc deleted file mode 100644 index 5bbd1edc..00000000 --- a/tests/unit/unix_timer_tests.cc +++ /dev/null @@ -1,63 +0,0 @@ -#include "gtest/gtest.h" -#include "serial/impl/unix.h" - -#include -#include - -using serial::MillisecondTimer; - -namespace { - -/** - * Do 100 trials of timing gaps between 0 and 19 milliseconds. - * Expect accuracy within one millisecond. - */ -TEST(timer_tests, short_intervals) { - for (int trial = 0; trial < 100; trial++) - { - uint32_t ms = rand() % 20; - MillisecondTimer mt(ms); - usleep(1000 * ms); - int32_t r = mt.remaining(); - - // 1ms slush, for the cost of calling usleep. - EXPECT_NEAR(r+1, 0, 1); - } -} - -TEST(timer_tests, overlapping_long_intervals) { - MillisecondTimer* timers[10]; - - // Experimentally determined. Corresponds to the extra time taken by the loops, - // the big usleep, and the test infrastructure itself. - const int slush_factor = 14; - - // Set up the timers to each time one second, 1ms apart. - for (int t = 0; t < 10; t++) - { - timers[t] = new MillisecondTimer(1000); - usleep(1000); - } - - // Check in on them after 500ms. - usleep(500000); - for (int t = 0; t < 10; t++) - { - EXPECT_NEAR(timers[t]->remaining(), 500 - slush_factor + t, 5); - } - - // Check in on them again after another 500ms and free them. - usleep(500000); - for (int t = 0; t < 10; t++) - { - EXPECT_NEAR(timers[t]->remaining(), -slush_factor + t, 5); - delete timers[t]; - } -} - -} // namespace - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} From 2df800d0fc5928d2b5d3bf1b5e3a3923e0574166 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Tue, 8 Sep 2020 11:09:06 -0500 Subject: [PATCH 6/7] Revert "Remove test that breaks the build" This reverts commit 7fe3be8d5f24db9837fff7e5b2fc45dcb464eef0. --- tests/CMakeLists.txt | 5 +++ tests/unit/unix_timer_tests.cc | 63 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/unit/unix_timer_tests.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c9352529..964f27cf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,4 +7,9 @@ if(UNIX) if(NOT APPLE) target_link_libraries(${PROJECT_NAME}-test util) endif() + + if(NOT APPLE) # these tests are unreliable on macOS + ament_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) + target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME}) + endif() endif() diff --git a/tests/unit/unix_timer_tests.cc b/tests/unit/unix_timer_tests.cc new file mode 100644 index 00000000..5bbd1edc --- /dev/null +++ b/tests/unit/unix_timer_tests.cc @@ -0,0 +1,63 @@ +#include "gtest/gtest.h" +#include "serial/impl/unix.h" + +#include +#include + +using serial::MillisecondTimer; + +namespace { + +/** + * Do 100 trials of timing gaps between 0 and 19 milliseconds. + * Expect accuracy within one millisecond. + */ +TEST(timer_tests, short_intervals) { + for (int trial = 0; trial < 100; trial++) + { + uint32_t ms = rand() % 20; + MillisecondTimer mt(ms); + usleep(1000 * ms); + int32_t r = mt.remaining(); + + // 1ms slush, for the cost of calling usleep. + EXPECT_NEAR(r+1, 0, 1); + } +} + +TEST(timer_tests, overlapping_long_intervals) { + MillisecondTimer* timers[10]; + + // Experimentally determined. Corresponds to the extra time taken by the loops, + // the big usleep, and the test infrastructure itself. + const int slush_factor = 14; + + // Set up the timers to each time one second, 1ms apart. + for (int t = 0; t < 10; t++) + { + timers[t] = new MillisecondTimer(1000); + usleep(1000); + } + + // Check in on them after 500ms. + usleep(500000); + for (int t = 0; t < 10; t++) + { + EXPECT_NEAR(timers[t]->remaining(), 500 - slush_factor + t, 5); + } + + // Check in on them again after another 500ms and free them. + usleep(500000); + for (int t = 0; t < 10; t++) + { + EXPECT_NEAR(timers[t]->remaining(), -slush_factor + t, 5); + delete timers[t]; + } +} + +} // namespace + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} From ae46504ae7d4a199ea9bba0e73a6f083bf172f80 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Thu, 3 Sep 2020 19:45:41 -0500 Subject: [PATCH 7/7] Revert "Merge branch 'ament_cmake'" This reverts commit 8e0effcd36b855701d9327aecff949d7f2b20e31. --- CMakeLists.txt | 16 ++++++---------- package.xml | 4 ++-- tests/CMakeLists.txt | 7 ++----- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a4bb58b..1dc6c660 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ elseif(WIN32) # Windows src/impl/win.cc src/impl/list_ports/list_ports_win.cc ) - target_link_libraries(${PROJECT_NAME} setupapi) + target_link_libraries(${PROJECT_NAME} setupapi) ament_export_libraries(setupapi) endif() @@ -54,17 +54,13 @@ install(TARGETS ${PROJECT_NAME} ) ## Install headers -install( - FILES include/serial/serial.h include/serial/v8stdint.h - DESTINATION include/serial +install(FILES include/serial/serial.h include/serial/v8stdint.h + DESTINATION include/serial ) ## Tests -if(BUILD_TESTING) - add_subdirectory(tests) -endif() - -ament_export_include_directories(include) -ament_export_libraries(${PROJECT_NAME}) +#if(BUILD_TESTING) +# add_subdirectory(tests) +#endif() ament_package() diff --git a/package.xml b/package.xml index 7fb772da..f1ac9d3a 100644 --- a/package.xml +++ b/package.xml @@ -21,10 +21,10 @@ ament_cmake - ament_cmake_gtest boost - ament_cmake + ament_cmake + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 964f27cf..e52a4d31 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,15 +1,12 @@ if(UNIX) - find_package(ament_cmake_gtest REQUIRED) - find_package(Boost REQUIRED) - - ament_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc) + 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 - ament_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) + catkin_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME}) endif() endif()