From a366ca2e784ba5091511a7d9c14be5c131b8f2eb Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Thu, 1 Aug 2024 16:39:30 -0400 Subject: [PATCH] Switch nav2_lifecycle_manager to modern CMake idioms. (#4588) Signed-off-by: Chris Lalancette --- nav2_lifecycle_manager/CMakeLists.txt | 74 +++++++++---------- nav2_lifecycle_manager/package.xml | 34 +++------ .../src/lifecycle_manager_client.cpp | 1 - nav2_lifecycle_manager/test/CMakeLists.txt | 15 ++-- 4 files changed, 51 insertions(+), 73 deletions(-) diff --git a/nav2_lifecycle_manager/CMakeLists.txt b/nav2_lifecycle_manager/CMakeLists.txt index 5f4b3f3c23..85179764ee 100644 --- a/nav2_lifecycle_manager/CMakeLists.txt +++ b/nav2_lifecycle_manager/CMakeLists.txt @@ -2,70 +2,62 @@ cmake_minimum_required(VERSION 3.5) project(nav2_lifecycle_manager) find_package(ament_cmake REQUIRED) +find_package(bondcpp REQUIRED) +find_package(diagnostic_updater REQUIRED) find_package(geometry_msgs REQUIRED) find_package(lifecycle_msgs REQUIRED) find_package(nav2_common REQUIRED) find_package(nav2_msgs REQUIRED) find_package(nav2_util REQUIRED) +find_package(rclcpp REQUIRED) find_package(rclcpp_action REQUIRED) -find_package(rclcpp_lifecycle REQUIRED) find_package(rclcpp_components REQUIRED) -find_package(rclcpp REQUIRED) -find_package(std_msgs REQUIRED) find_package(std_srvs REQUIRED) -find_package(tf2_geometry_msgs REQUIRED) -find_package(bondcpp REQUIRED) -find_package(diagnostic_updater REQUIRED) nav2_package() -include_directories( - include -) - set(library_name ${PROJECT_NAME}_core) add_library(${library_name} SHARED src/lifecycle_manager.cpp src/lifecycle_manager_client.cpp ) - -set(dependencies - geometry_msgs - lifecycle_msgs - nav2_msgs - nav2_util - rclcpp - rclcpp_action - rclcpp_lifecycle - rclcpp_components - std_msgs - std_srvs - tf2_geometry_msgs - bondcpp - diagnostic_updater +target_include_directories(${library_name} + PUBLIC + "$" + "$" ) - -ament_target_dependencies(${library_name} - ${dependencies} +target_link_libraries(${library_name} PUBLIC + bondcpp::bondcpp + diagnostic_updater::diagnostic_updater + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_action::rclcpp_action + ${std_srvs_TARGETS} +) +target_link_libraries(${library_name} PRIVATE + ${diagnostic_msgs_TARGETS} + ${lifecycle_msgs_TARGETS} + rclcpp_components::component ) add_executable(lifecycle_manager src/main.cpp ) - -target_link_libraries(lifecycle_manager - ${library_name} +target_include_directories(lifecycle_manager + PUBLIC + "$" + "$" ) - -ament_target_dependencies(lifecycle_manager - ${dependencies} +target_link_libraries(lifecycle_manager PRIVATE + ${library_name} + rclcpp::rclcpp ) rclcpp_components_register_nodes(${library_name} "nav2_lifecycle_manager::LifecycleManager") -install(TARGETS - ${library_name} +install(TARGETS ${library_name} + EXPORT ${library_name} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin @@ -76,7 +68,7 @@ install(TARGETS RUNTIME DESTINATION lib/${PROJECT_NAME} ) -install(DIRECTORY include/ DESTINATION include/) +install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME}) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) @@ -84,12 +76,16 @@ if(BUILD_TESTING) find_package(ament_cmake_gtest REQUIRED) find_package(ament_cmake_pytest REQUIRED) + find_package(rclcpp_lifecycle REQUIRED) + + 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(bondcpp diagnostic_updater nav2_util rclcpp rclcpp_action std_srvs) +ament_export_targets(${library_name}) ament_package() diff --git a/nav2_lifecycle_manager/package.xml b/nav2_lifecycle_manager/package.xml index 85dae758aa..f5c010075f 100644 --- a/nav2_lifecycle_manager/package.xml +++ b/nav2_lifecycle_manager/package.xml @@ -8,36 +8,24 @@ Apache-2.0 ament_cmake - - geometry_msgs - lifecycle_msgs - nav2_msgs - nav2_util - rclcpp_action - rclcpp_lifecycle - std_msgs - std_srvs - tf2_geometry_msgs - bondcpp nav2_common - diagnostic_updater - geometry_msgs - lifecycle_msgs - nav2_msgs - nav2_util - rclcpp_action - rclcpp_lifecycle - std_msgs - std_srvs - bondcpp - tf2_geometry_msgs - diagnostic_updater + bondcpp + diagnostic_updater + geometry_msgs + lifecycle_msgs + nav2_msgs + nav2_util + rclcpp + rclcpp_action + rclcpp_components + std_srvs ament_lint_auto ament_lint_common ament_cmake_gtest ament_cmake_pytest + rclcpp_lifecycle ament_cmake diff --git a/nav2_lifecycle_manager/src/lifecycle_manager_client.cpp b/nav2_lifecycle_manager/src/lifecycle_manager_client.cpp index 123c69b58e..4f2f14ed54 100644 --- a/nav2_lifecycle_manager/src/lifecycle_manager_client.cpp +++ b/nav2_lifecycle_manager/src/lifecycle_manager_client.cpp @@ -19,7 +19,6 @@ #include #include -#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp" #include "nav2_util/geometry_utils.hpp" namespace nav2_lifecycle_manager diff --git a/nav2_lifecycle_manager/test/CMakeLists.txt b/nav2_lifecycle_manager/test/CMakeLists.txt index 96cbaa5f7a..43692d9bf0 100644 --- a/nav2_lifecycle_manager/test/CMakeLists.txt +++ b/nav2_lifecycle_manager/test/CMakeLists.txt @@ -1,13 +1,11 @@ ament_add_gtest_executable(test_lifecycle_gtest test_lifecycle_manager.cpp ) - target_link_libraries(test_lifecycle_gtest ${library_name} -) - -ament_target_dependencies(test_lifecycle_gtest - ${dependencies} + nav2_util::nav2_util_core + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle ) ament_add_test(test_lifecycle @@ -22,13 +20,10 @@ ament_add_test(test_lifecycle ament_add_gtest_executable(test_bond_gtest test_bond.cpp ) - target_link_libraries(test_bond_gtest ${library_name} -) - -ament_target_dependencies(test_bond_gtest - ${dependencies} + nav2_util::nav2_util_core + rclcpp::rclcpp ) ament_add_test(test_bond