From eec5367d40edde8e12e97fa5cbb428e7778195e0 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Mon, 20 May 2024 20:47:41 +0000 Subject: [PATCH] Switch nav2_planner to modern CMake idioms. Signed-off-by: Chris Lalancette --- nav2_planner/CMakeLists.txt | 97 ++++++++++--------- .../include/nav2_planner/planner_server.hpp | 1 - nav2_planner/package.xml | 23 ++--- nav2_planner/src/planner_server.cpp | 1 - nav2_planner/test/CMakeLists.txt | 6 +- nav2_planner/test/test_dynamic_parameters.cpp | 4 +- 6 files changed, 68 insertions(+), 64 deletions(-) diff --git a/nav2_planner/CMakeLists.txt b/nav2_planner/CMakeLists.txt index 197150837c..a5bce30e77 100644 --- a/nav2_planner/CMakeLists.txt +++ b/nav2_planner/CMakeLists.txt @@ -2,71 +2,62 @@ cmake_minimum_required(VERSION 3.5) project(nav2_planner) find_package(ament_cmake REQUIRED) +find_package(geometry_msgs REQUIRED) +find_package(lifecycle_msgs REQUIRED) find_package(nav2_common REQUIRED) -find_package(rclcpp REQUIRED) -find_package(rclcpp_action REQUIRED) -find_package(rclcpp_lifecycle REQUIRED) -find_package(rclcpp_components REQUIRED) -find_package(std_msgs REQUIRED) -find_package(visualization_msgs REQUIRED) -find_package(nav2_util REQUIRED) +find_package(nav2_core REQUIRED) +find_package(nav2_costmap_2d REQUIRED) find_package(nav2_msgs REQUIRED) +find_package(nav2_util REQUIRED) find_package(nav_msgs REQUIRED) -find_package(geometry_msgs REQUIRED) -find_package(builtin_interfaces REQUIRED) -find_package(tf2_ros REQUIRED) -find_package(nav2_costmap_2d REQUIRED) find_package(pluginlib REQUIRED) -find_package(nav2_core REQUIRED) +find_package(rclcpp REQUIRED) +find_package(rclcpp_components REQUIRED) +find_package(rclcpp_lifecycle REQUIRED) +find_package(tf2 REQUIRED) +find_package(tf2_ros REQUIRED) nav2_package() -include_directories( - include -) - set(executable_name planner_server) set(library_name ${executable_name}_core) -set(dependencies - rclcpp - rclcpp_action - rclcpp_lifecycle - rclcpp_components - std_msgs - visualization_msgs - nav2_util - nav2_msgs - nav_msgs - geometry_msgs - builtin_interfaces - tf2_ros - nav2_costmap_2d - pluginlib - nav2_core -) - add_library(${library_name} SHARED src/planner_server.cpp ) - -ament_target_dependencies(${library_name} - ${dependencies} +target_include_directories(${library_name} + PUBLIC + "$" + "$" +) +target_link_libraries(${library_name} PUBLIC + ${geometry_msgs_TARGETS} + nav2_core::nav2_core + nav2_costmap_2d::nav2_costmap_2d_core + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + ${nav_msgs_TARGETS} + pluginlib::pluginlib + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle + ${rcl_interfaces_TARGETS} + tf2_ros::tf2_ros +) +target_link_libraries(${library_name} PRIVATE + ${lifecycle_msgs_TARGETS} + rclcpp_components::component + tf2::tf2 ) add_executable(${executable_name} src/main.cpp ) - -target_link_libraries(${executable_name} ${library_name}) - -ament_target_dependencies(${executable_name} - ${dependencies} -) +target_link_libraries(${executable_name} PRIVATE ${library_name} rclcpp::rclcpp) rclcpp_components_register_nodes(${library_name} "nav2_planner::PlannerServer") install(TARGETS ${library_name} + EXPORT ${library_name} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin @@ -77,17 +68,31 @@ install(TARGETS ${executable_name} ) install(DIRECTORY include/ - DESTINATION include/ + DESTINATION include/${PROJECT_NAME} ) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) find_package(ament_cmake_gtest REQUIRED) ament_lint_auto_find_test_dependencies() + + ament_find_gtest() add_subdirectory(test) endif() -ament_export_include_directories(include) +ament_export_include_directories(include/${PROJECT_NAME}) ament_export_libraries(${library_name}) -ament_export_dependencies(${dependencies}) +ament_export_dependencies( + geometry_msgs + nav2_core + nav2_costmap_2d + nav2_msgs + nav2_util + nav_msgs + pluginlib + rclcpp + rclcpp_lifecycle + tf2_ros +) +ament_export_targets(${library_name}) ament_package() diff --git a/nav2_planner/include/nav2_planner/planner_server.hpp b/nav2_planner/include/nav2_planner/planner_server.hpp index bdffda281a..12e364c710 100644 --- a/nav2_planner/include/nav2_planner/planner_server.hpp +++ b/nav2_planner/include/nav2_planner/planner_server.hpp @@ -31,7 +31,6 @@ #include "nav2_msgs/msg/costmap.hpp" #include "nav2_util/robot_utils.hpp" #include "nav2_util/simple_action_server.hpp" -#include "visualization_msgs/msg/marker.hpp" #include "tf2_ros/transform_listener.h" #include "tf2_ros/create_timer_ros.h" #include "nav2_costmap_2d/costmap_2d_ros.hpp" diff --git a/nav2_planner/package.xml b/nav2_planner/package.xml index 397dd8ae1d..26de6cfa13 100644 --- a/nav2_planner/package.xml +++ b/nav2_planner/package.xml @@ -8,22 +8,23 @@ Apache-2.0 ament_cmake + nav2_common - rclcpp - rclcpp_action - rclcpp_lifecycle - visualization_msgs - nav2_util - nav2_msgs - nav_msgs geometry_msgs - builtin_interfaces - nav2_common - tf2_ros + lifecycle_msgs + nav2_core nav2_costmap_2d + nav2_msgs + nav2_util + nav_msgs pluginlib - nav2_core + rclcpp + rclcpp_components + rclcpp_lifecycle + tf2 + tf2_ros + ament_cmake_gtest ament_lint_common ament_lint_auto diff --git a/nav2_planner/src/planner_server.cpp b/nav2_planner/src/planner_server.cpp index 6abeddd29b..d572360fc9 100644 --- a/nav2_planner/src/planner_server.cpp +++ b/nav2_planner/src/planner_server.cpp @@ -24,7 +24,6 @@ #include #include -#include "builtin_interfaces/msg/duration.hpp" #include "lifecycle_msgs/msg/state.hpp" #include "nav2_util/costmap.hpp" #include "nav2_util/node_utils.hpp" diff --git a/nav2_planner/test/CMakeLists.txt b/nav2_planner/test/CMakeLists.txt index d415d906ef..a551d1208f 100644 --- a/nav2_planner/test/CMakeLists.txt +++ b/nav2_planner/test/CMakeLists.txt @@ -2,9 +2,9 @@ ament_add_gtest(test_dynamic_parameters test_dynamic_parameters.cpp ) -ament_target_dependencies(test_dynamic_parameters - ${dependencies} -) target_link_libraries(test_dynamic_parameters ${library_name} + nav2_util::nav2_util_core + rclcpp::rclcpp + ${rcl_interfaces_TARGETS} ) diff --git a/nav2_planner/test/test_dynamic_parameters.cpp b/nav2_planner/test/test_dynamic_parameters.cpp index 8215e80e43..3dc3ab2b55 100644 --- a/nav2_planner/test/test_dynamic_parameters.cpp +++ b/nav2_planner/test/test_dynamic_parameters.cpp @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. Reserved. -#include - +#include #include #include #include @@ -22,6 +21,7 @@ #include "nav2_util/lifecycle_node.hpp" #include "nav2_planner/planner_server.hpp" #include "rclcpp/rclcpp.hpp" +#include "rcl_interfaces/msg/set_parameters_result.hpp" class PlannerShim : public nav2_planner::PlannerServer {