From ccddc45691befd19c2dcb0d6c06d1995da56c3f9 Mon Sep 17 00:00:00 2001 From: Tyler Weaver Date: Thu, 26 Jan 2023 07:23:52 -0700 Subject: [PATCH 1/2] Fix overriding of install --- CMakeLists.txt | 97 +++++++++++++++++++++++++++++++------------------- package.xml | 1 - 2 files changed, 61 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9695a73e..6c7d6b09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ -cmake_minimum_required(VERSION 3.5) -project(realtime_tools) +cmake_minimum_required(VERSION 3.16) +project(realtime_tools LANGUAGES CXX) -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) +if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") + add_compile_options(-Wall -Wextra) endif() # Load catkin and all dependencies required for this package @@ -11,15 +11,33 @@ find_package(rclcpp REQUIRED) find_package(rclcpp_action REQUIRED) find_package(Threads REQUIRED) -add_library(${PROJECT_NAME} src/realtime_clock.cpp) -ament_target_dependencies(${PROJECT_NAME} "rclcpp" "rclcpp_action") -target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}) -target_include_directories(${PROJECT_NAME} PUBLIC include) +add_library(realtime_tools SHARED + src/realtime_clock.cpp +) +target_compile_features(realtime_tools PUBLIC cxx_std_17) +target_include_directories(realtime_tools PUBLIC + $ + $ +) +target_link_libraries(realtime_tools PUBLIC + rclcpp::rclcpp + rclcpp_action::rclcpp_action + Threads::Threads +) # A library to detect a realtime kernel and set thread priority, if one is found -add_library(thread_priority SHARED src/thread_priority.cpp) -target_include_directories(thread_priority PUBLIC include) -ament_target_dependencies(thread_priority "rclcpp" "rclcpp_action") +add_library(thread_priority SHARED + src/thread_priority.cpp +) +target_compile_features(thread_priority PUBLIC cxx_std_17) +target_include_directories(thread_priority PUBLIC + $ + $ +) +target_link_libraries(thread_priority PUBLIC + rclcpp::rclcpp + rclcpp_action::rclcpp_action +) # Unit Tests if(BUILD_TESTING) @@ -27,42 +45,49 @@ if(BUILD_TESTING) find_package(test_msgs REQUIRED) ament_add_gmock(realtime_box_tests test/realtime_box_tests.cpp) - target_link_libraries(realtime_box_tests ${PROJECT_NAME} ${GMOCK_MAIN_LIBRARIES}) + target_link_libraries(realtime_box_tests realtime_tools) ament_add_gmock(realtime_buffer_tests test/realtime_buffer_tests.cpp) - target_link_libraries(realtime_buffer_tests ${PROJECT_NAME} ${GMOCK_MAIN_LIBRARIES}) + target_link_libraries(realtime_buffer_tests realtime_tools) ament_add_gmock(realtime_clock_tests test/realtime_clock_tests.cpp) - target_link_libraries(realtime_clock_tests ${PROJECT_NAME} ${GMOCK_MAIN_LIBRARIES}) + target_link_libraries(realtime_clock_tests realtime_tools) ament_add_gmock(realtime_publisher_tests_non_polling - test/realtime_publisher_non_polling.test test/realtime_publisher_tests_non_polling.cpp) - target_link_libraries(realtime_publisher_tests_non_polling ${PROJECT_NAME} ${test_msgs_LIBRARIES} ${GMOCK_MAIN_LIBRARIES}) - target_include_directories(realtime_publisher_tests_non_polling PRIVATE ${test_msgs_INCLUDE_DIRS}) - - ament_add_gmock(realtime_publisher_tests test/realtime_publisher.test test/realtime_publisher_tests.cpp) - target_link_libraries(realtime_publisher_tests ${PROJECT_NAME} ${test_msgs_LIBRARIES} ${GMOCK_MAIN_LIBRARIES}) - target_include_directories(realtime_publisher_tests PRIVATE ${test_msgs_INCLUDE_DIRS}) - - ament_add_gmock(realtime_server_goal_handle_tests test/realtime_server_goal_handle.test test/realtime_server_goal_handle_tests.cpp) - target_link_libraries(realtime_server_goal_handle_tests ${PROJECT_NAME} ${test_msgs_LIBRARIES} ${GMOCK_MAIN_LIBRARIES}) - target_include_directories(realtime_server_goal_handle_tests PRIVATE ${test_msgs_INCLUDE_DIRS}) + test/realtime_publisher_non_polling.test + test/realtime_publisher_tests_non_polling.cpp) + target_link_libraries(realtime_publisher_tests_non_polling realtime_tools) + ament_target_dependencies(realtime_publisher_tests_non_polling test_msgs) + + ament_add_gmock(realtime_publisher_tests + test/realtime_publisher.test + test/realtime_publisher_tests.cpp) + target_link_libraries(realtime_publisher_tests realtime_tools) + ament_target_dependencies(realtime_publisher_tests test_msgs) + + ament_add_gmock(realtime_server_goal_handle_tests + test/realtime_server_goal_handle.test + test/realtime_server_goal_handle_tests.cpp) + target_link_libraries(realtime_server_goal_handle_tests realtime_tools) + ament_target_dependencies(realtime_server_goal_handle_tests test_msgs) endif() # Install install( DIRECTORY include/ - DESTINATION include) - -install(TARGETS ${PROJECT_NAME} thread_priority + DESTINATION include/realtime_tools +) +install(TARGETS realtime_tools thread_priority + EXPORT export_realtime_tools ARCHIVE DESTINATION lib LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) - -ament_export_include_directories(include) -ament_export_libraries(${PROJECT_NAME} thread_priority) - -ament_export_dependencies(rclcpp) -ament_export_dependencies(rclcpp_action) - + RUNTIME DESTINATION bin +) + +ament_export_targets(export_realtime_tools HAS_LIBRARY_TARGET) +ament_export_dependencies( + rclcpp + rclcpp_action + Threads +) ament_package() diff --git a/package.xml b/package.xml index d3b4422d..11e313f8 100644 --- a/package.xml +++ b/package.xml @@ -23,7 +23,6 @@ rclcpp_action ament_cmake_gmock - rclcpp_action test_msgs From 2c3a3383a25e1ba0866daef523606547b3db4a63 Mon Sep 17 00:00:00 2001 From: Tyler Weaver Date: Thu, 26 Jan 2023 12:06:00 -0700 Subject: [PATCH 2/2] Use THIS_PACKAGE_INCLUDE_DEPENDS list --- CMakeLists.txt | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c7d6b09..4743d984 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,11 +5,16 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") add_compile_options(-Wall -Wextra) endif() -# Load catkin and all dependencies required for this package +set(THIS_PACKAGE_INCLUDE_DEPENDS + rclcpp + rclcpp_action + Threads +) + find_package(ament_cmake REQUIRED) -find_package(rclcpp REQUIRED) -find_package(rclcpp_action REQUIRED) -find_package(Threads REQUIRED) +foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS}) + find_package(${Dependency} REQUIRED) +endforeach() add_library(realtime_tools SHARED src/realtime_clock.cpp @@ -19,11 +24,7 @@ target_include_directories(realtime_tools PUBLIC $ $ ) -target_link_libraries(realtime_tools PUBLIC - rclcpp::rclcpp - rclcpp_action::rclcpp_action - Threads::Threads -) +ament_target_dependencies(realtime_tools PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS}) # A library to detect a realtime kernel and set thread priority, if one is found add_library(thread_priority SHARED @@ -34,10 +35,7 @@ target_include_directories(thread_priority PUBLIC $ $ ) -target_link_libraries(thread_priority PUBLIC - rclcpp::rclcpp - rclcpp_action::rclcpp_action -) +ament_target_dependencies(thread_priority PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS}) # Unit Tests if(BUILD_TESTING) @@ -85,9 +83,5 @@ install(TARGETS realtime_tools thread_priority ) ament_export_targets(export_realtime_tools HAS_LIBRARY_TARGET) -ament_export_dependencies( - rclcpp - rclcpp_action - Threads -) +ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS}) ament_package()