From 34cc452d294f6f65ec5b9a04d34d362a79b80784 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Wed, 31 Jul 2024 11:40:20 +0000 Subject: [PATCH] Switch nav2_collision_monitor to modern CMake idioms. Signed-off-by: Chris Lalancette --- nav2_collision_monitor/CMakeLists.txt | 141 ++++++++++-------- nav2_collision_monitor/package.xml | 16 +- nav2_collision_monitor/test/CMakeLists.txt | 46 +++--- .../test/velocity_polygons_test.cpp | 6 +- 4 files changed, 119 insertions(+), 90 deletions(-) diff --git a/nav2_collision_monitor/CMakeLists.txt b/nav2_collision_monitor/CMakeLists.txt index 5dfaf1576a..b56fde855c 100644 --- a/nav2_collision_monitor/CMakeLists.txt +++ b/nav2_collision_monitor/CMakeLists.txt @@ -1,48 +1,23 @@ cmake_minimum_required(VERSION 3.5) project(nav2_collision_monitor) -### Dependencies ### - find_package(ament_cmake REQUIRED) +find_package(geometry_msgs REQUIRED) +find_package(nav2_common REQUIRED) +find_package(nav2_costmap_2d REQUIRED) +find_package(nav2_msgs REQUIRED) +find_package(nav2_util REQUIRED) find_package(rclcpp REQUIRED) find_package(rclcpp_components REQUIRED) +find_package(rclcpp_lifecycle REQUIRED) find_package(sensor_msgs REQUIRED) -find_package(geometry_msgs REQUIRED) find_package(std_msgs REQUIRED) find_package(tf2 REQUIRED) find_package(tf2_ros REQUIRED) -find_package(tf2_geometry_msgs REQUIRED) -find_package(nav2_common REQUIRED) -find_package(nav2_util REQUIRED) -find_package(nav2_costmap_2d REQUIRED) -find_package(nav2_msgs REQUIRED) find_package(visualization_msgs REQUIRED) -### Header ### - nav2_package() -### Libraries and executables ### - -include_directories( - include -) - -set(dependencies - rclcpp - rclcpp_components - sensor_msgs - geometry_msgs - std_msgs - tf2 - tf2_ros - tf2_geometry_msgs - nav2_util - nav2_costmap_2d - nav2_msgs - visualization_msgs -) - set(monitor_executable_name collision_monitor) set(detector_executable_name collision_detector) set(monitor_library_name ${monitor_executable_name}_core) @@ -60,6 +35,27 @@ add_library(${monitor_library_name} SHARED src/range.cpp src/kinematics.cpp ) +target_include_directories(${monitor_library_name} + PUBLIC + "$" + "$") +target_link_libraries(${monitor_library_name} PUBLIC + ${geometry_msgs_TARGETS} + nav2_costmap_2d::nav2_costmap_2d_client + nav2_costmap_2d::nav2_costmap_2d_core + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle + ${sensor_msgs_TARGETS} + tf2::tf2 + tf2_ros::tf2_ros + ${visualization_msgs_TARGETS} +) +target_link_libraries(${monitor_library_name} PRIVATE + rclcpp_components::component +) + add_library(${detector_library_name} SHARED src/collision_detector_node.cpp src/polygon.cpp @@ -72,43 +68,57 @@ add_library(${detector_library_name} SHARED src/range.cpp src/kinematics.cpp ) - -add_executable(${monitor_executable_name} - src/collision_monitor_main.cpp +target_include_directories(${detector_library_name} + PUBLIC + "$" + "$") +target_link_libraries(${detector_library_name} PUBLIC + ${geometry_msgs_TARGETS} + nav2_costmap_2d::nav2_costmap_2d_client + nav2_costmap_2d::nav2_costmap_2d_core + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle + ${sensor_msgs_TARGETS} + tf2_ros::tf2_ros + tf2::tf2 + ${visualization_msgs_TARGETS} ) -add_executable(${detector_executable_name} - src/collision_detector_main.cpp +target_link_libraries(${detector_library_name} PRIVATE + rclcpp_components::component ) -ament_target_dependencies(${monitor_library_name} - ${dependencies} -) -ament_target_dependencies(${detector_library_name} - ${dependencies} +add_executable(${monitor_executable_name} + src/collision_monitor_main.cpp ) - -target_link_libraries(${monitor_executable_name} +target_include_directories(${monitor_executable_name} + PRIVATE + "$" + "$") +target_link_libraries(${monitor_executable_name} PRIVATE + rclcpp::rclcpp ${monitor_library_name} ) -target_link_libraries(${detector_executable_name} - ${detector_library_name} -) -ament_target_dependencies(${monitor_executable_name} - ${dependencies} +add_executable(${detector_executable_name} + src/collision_detector_main.cpp ) - -ament_target_dependencies(${detector_executable_name} - ${dependencies} +target_include_directories(${detector_executable_name} + PRIVATE + "$" + "$") +target_link_libraries(${detector_executable_name} PRIVATE + rclcpp::rclcpp + ${detector_library_name} ) rclcpp_components_register_nodes(${monitor_library_name} "nav2_collision_monitor::CollisionMonitor") rclcpp_components_register_nodes(${detector_library_name} "nav2_collision_monitor::CollisionDetector") -### Install ### - install(TARGETS ${monitor_library_name} ${detector_library_name} + EXPORT export_${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin @@ -119,14 +129,12 @@ install(TARGETS ${monitor_executable_name} ${detector_executable_name} ) install(DIRECTORY include/ - DESTINATION include/ + DESTINATION include/${PROJECT_NAME} ) install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}) install(DIRECTORY params DESTINATION share/${PROJECT_NAME}) -### Testing ### - if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights @@ -135,13 +143,26 @@ if(BUILD_TESTING) ament_lint_auto_find_test_dependencies() find_package(ament_cmake_gtest REQUIRED) + + ament_find_gtest() + add_subdirectory(test) endif() -### Ament stuff ### - -ament_export_include_directories(include) +ament_export_include_directories(include/${PROJECT_NAME}) ament_export_libraries(${monitor_library_name} ${detector_library_name}) -ament_export_dependencies(${dependencies}) +ament_export_dependencies( + geometry_msgs + nav2_costmap_2d + nav2_msgs + nav2_util + rclcpp + rclcpp_lifecycle + sensor_msgs + tf2 + tf2_ros + visualization_msgs +) +ament_export_targets(export_${PROJECT_NAME}) ament_package() diff --git a/nav2_collision_monitor/package.xml b/nav2_collision_monitor/package.xml index 1301b22e6d..22871152b7 100644 --- a/nav2_collision_monitor/package.xml +++ b/nav2_collision_monitor/package.xml @@ -9,19 +9,19 @@ Apache-2.0 ament_cmake + nav2_common - rclcpp - rclcpp_components - tf2 - tf2_ros - tf2_geometry_msgs - sensor_msgs geometry_msgs - std_msgs - nav2_common nav2_util nav2_costmap_2d nav2_msgs + rclcpp + rclcpp_components + rclcpp_lifecycle + sensor_msgs + std_msgs + tf2 + tf2_ros visualization_msgs ament_cmake_gtest diff --git a/nav2_collision_monitor/test/CMakeLists.txt b/nav2_collision_monitor/test/CMakeLists.txt index 2f879e1d39..e2b668b517 100644 --- a/nav2_collision_monitor/test/CMakeLists.txt +++ b/nav2_collision_monitor/test/CMakeLists.txt @@ -1,52 +1,60 @@ # Kinematics test ament_add_gtest(kinematics_test kinematics_test.cpp) -ament_target_dependencies(kinematics_test - ${dependencies} -) target_link_libraries(kinematics_test ${monitor_library_name} + rclcpp::rclcpp ) # Data sources test ament_add_gtest(sources_test sources_test.cpp) -ament_target_dependencies(sources_test - ${dependencies} -) target_link_libraries(sources_test ${monitor_library_name} + rclcpp::rclcpp + nav2_util::nav2_util_core + ${sensor_msgs_TARGETS} + tf2_ros::tf2_ros ) # Polygon shapes test ament_add_gtest(polygons_test polygons_test.cpp) -ament_target_dependencies(polygons_test - ${dependencies} -) target_link_libraries(polygons_test ${monitor_library_name} + ${geometry_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + tf2_ros::tf2_ros ) # Velocity Polygon test ament_add_gtest(velocity_polygons_test velocity_polygons_test.cpp) -ament_target_dependencies(velocity_polygons_test - ${dependencies} -) target_link_libraries(velocity_polygons_test ${monitor_library_name} + ${geometry_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + tf2_ros::tf2_ros ) # Collision Monitor node test ament_add_gtest(collision_monitor_node_test collision_monitor_node_test.cpp) -ament_target_dependencies(collision_monitor_node_test - ${dependencies} -) target_link_libraries(collision_monitor_node_test ${monitor_library_name} + ${geometry_msgs_TARGETS} + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + ${sensor_msgs_TARGETS} + tf2_ros::tf2_ros + ${visualization_msgs_TARGETS} ) # Collision Detector node test ament_add_gtest(collision_detector_node_test collision_detector_node_test.cpp) -ament_target_dependencies(collision_detector_node_test - ${dependencies} -) target_link_libraries(collision_detector_node_test ${detector_library_name} -) \ No newline at end of file + ${geometry_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + ${sensor_msgs_TARGETS} + tf2_ros::tf2_ros + ${visualization_msgs_TARGETS} +) diff --git a/nav2_collision_monitor/test/velocity_polygons_test.cpp b/nav2_collision_monitor/test/velocity_polygons_test.cpp index 4fd4f8bc0b..216a85b514 100644 --- a/nav2_collision_monitor/test/velocity_polygons_test.cpp +++ b/nav2_collision_monitor/test/velocity_polygons_test.cpp @@ -14,13 +14,13 @@ #include -#include #include +#include +#include #include +#include #include #include -#include -#include #include "rclcpp/rclcpp.hpp" #include "nav2_util/lifecycle_node.hpp"