From 7f7d8ad07655f4195213bdf03cd57600421ac5b5 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 30 Jul 2024 20:04:35 +0000 Subject: [PATCH] Make nav2_bt_navigator use modern CMake idioms. Signed-off-by: Chris Lalancette --- nav2_bt_navigator/CMakeLists.txt | 130 +++++++++++++++++++------------ nav2_bt_navigator/package.xml | 40 ++++------ 2 files changed, 94 insertions(+), 76 deletions(-) diff --git a/nav2_bt_navigator/CMakeLists.txt b/nav2_bt_navigator/CMakeLists.txt index 7de1592106..5ced439631 100644 --- a/nav2_bt_navigator/CMakeLists.txt +++ b/nav2_bt_navigator/CMakeLists.txt @@ -2,79 +2,110 @@ cmake_minimum_required(VERSION 3.5) project(nav2_bt_navigator) find_package(ament_cmake 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(ament_index_cpp REQUIRED) find_package(geometry_msgs REQUIRED) find_package(nav2_behavior_tree REQUIRED) -find_package(nav_msgs REQUIRED) +find_package(nav2_common REQUIRED) +find_package(nav2_core REQUIRED) find_package(nav2_msgs REQUIRED) -find_package(behaviortree_cpp REQUIRED) -find_package(std_srvs REQUIRED) find_package(nav2_util REQUIRED) -find_package(nav2_core REQUIRED) -find_package(tf2_ros REQUIRED) +find_package(nav_msgs REQUIRED) find_package(pluginlib REQUIRED) +find_package(rclcpp REQUIRED) +find_package(rclcpp_action REQUIRED) +find_package(rclcpp_components REQUIRED) +find_package(rclcpp_lifecycle REQUIRED) +find_package(tf2_ros REQUIRED) nav2_package() -include_directories( - include -) - set(executable_name bt_navigator) -add_executable(${executable_name} - src/main.cpp -) - set(library_name ${executable_name}_core) -set(dependencies - rclcpp - rclcpp_action - rclcpp_lifecycle - rclcpp_components - std_msgs - geometry_msgs - nav2_behavior_tree - nav_msgs - nav2_msgs - behaviortree_cpp - std_srvs - nav2_util - nav2_core - tf2_ros - pluginlib -) - add_library(${library_name} SHARED src/bt_navigator.cpp ) - -ament_target_dependencies(${executable_name} - ${dependencies} +target_include_directories(${library_name} + PUBLIC + "$" + "$" +) +target_link_libraries(${library_name} PUBLIC + nav2_core::nav2_core + nav2_util::nav2_util_core + pluginlib::pluginlib + rclcpp::rclcpp + rclcpp_action::rclcpp_action + tf2_ros::tf2_ros +) +target_link_libraries(${library_name} PRIVATE + nav2_behavior_tree::nav2_behavior_tree + rclcpp_components::component + rclcpp_lifecycle::rclcpp_lifecycle ) -target_link_libraries(${executable_name} ${library_name}) - -ament_target_dependencies(${library_name} - ${dependencies} +add_executable(${executable_name} + src/main.cpp +) +target_include_directories(${executable_name} + PRIVATE + "$" + "$" +) +target_link_libraries(${executable_name} PRIVATE + ${library_name} + rclcpp::rclcpp ) add_library(nav2_navigate_to_pose_navigator SHARED src/navigators/navigate_to_pose.cpp) -ament_target_dependencies(nav2_navigate_to_pose_navigator ${dependencies}) +target_include_directories(nav2_navigate_to_pose_navigator + PUBLIC + "$" + "$" +) +target_link_libraries(nav2_navigate_to_pose_navigator PUBLIC + ${geometry_msgs_TARGETS} + nav2_core::nav2_core + ${nav2_msgs_TARGETS} + nav2_util::nav2_util_core + ${nav_msgs_TARGETS} + rclcpp::rclcpp + rclcpp_action::rclcpp_action +) +target_link_libraries(nav2_navigate_to_pose_navigator PRIVATE + ament_index_cpp::ament_index_cpp + nav2_behavior_tree::nav2_behavior_tree + pluginlib::pluginlib + rclcpp_lifecycle::rclcpp_lifecycle +) add_library(nav2_navigate_through_poses SHARED src/navigators/navigate_through_poses.cpp) -ament_target_dependencies(nav2_navigate_through_poses ${dependencies}) +target_include_directories(nav2_navigate_through_poses + PUBLIC + "$" + "$" +) +target_link_libraries(nav2_navigate_through_poses PUBLIC + ${geometry_msgs_TARGETS} + nav2_core::nav2_core + ${nav2_msgs_TARGETS} + ${nav_msgs_TARGETS} + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_action::rclcpp_action +) +target_link_libraries(nav2_navigate_through_poses PRIVATE + ament_index_cpp::ament_index_cpp + pluginlib::pluginlib + rclcpp_lifecycle::rclcpp_lifecycle +) pluginlib_export_plugin_description_file(nav2_core navigator_plugins.xml) rclcpp_components_register_nodes(${library_name} "nav2_bt_navigator::BtNavigator") install(TARGETS ${library_name} nav2_navigate_to_pose_navigator nav2_navigate_through_poses + EXPORT export_${library_name} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin @@ -85,7 +116,7 @@ install(TARGETS ${executable_name} ) install(DIRECTORY include/ - DESTINATION include/ + DESTINATION include/${PROJECT_NAME} ) install(DIRECTORY behavior_trees DESTINATION share/${PROJECT_NAME}) @@ -95,7 +126,8 @@ if(BUILD_TESTING) ament_lint_auto_find_test_dependencies() endif() -ament_export_include_directories(include) +ament_export_include_directories(include/${PROJECT_NAME}) ament_export_libraries(${library_name} nav2_navigate_to_pose_navigator nav2_navigate_through_poses) -ament_export_dependencies(${dependencies}) +ament_export_dependencies(geometry_msgs nav2_core nav2_msgs nav2_util nav_msgs pluginlib rclcpp rclcpp_action tf2_ros) +ament_export_targets(export_${library_name}) ament_package() diff --git a/nav2_bt_navigator/package.xml b/nav2_bt_navigator/package.xml index 9df2e88e1e..fdc5a87bbe 100644 --- a/nav2_bt_navigator/package.xml +++ b/nav2_bt_navigator/package.xml @@ -7,36 +7,22 @@ Michael Jeronimo Apache-2.0 - tf2_ros - ament_cmake nav2_common - rclcpp - rclcpp_action - rclcpp_lifecycle - nav2_behavior_tree - nav_msgs - nav2_msgs - behaviortree_cpp - std_msgs - geometry_msgs - std_srvs - nav2_util - pluginlib - nav2_core - behaviortree_cpp - rclcpp - rclcpp_action - rclcpp_lifecycle - nav2_behavior_tree - nav_msgs - nav2_msgs - std_msgs - nav2_util - geometry_msgs - pluginlib - nav2_core + ament_index_cpp + geometry_msgs + nav2_behavior_tree + nav2_core + nav2_msgs + nav2_util + nav_msgs + pluginlib + rclcpp + rclcpp_action + rclcpp_components + rclcpp_lifecycle + tf2_ros ament_lint_common ament_lint_auto