Skip to content

Commit

Permalink
Switch nav2_lifecycle_manager to modern CMake idioms. (#4588)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Aug 1, 2024
1 parent 495fe89 commit a366ca2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 73 deletions.
74 changes: 35 additions & 39 deletions nav2_lifecycle_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)

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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)

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
Expand All @@ -76,20 +68,24 @@ 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)
ament_lint_auto_find_test_dependencies()

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()
34 changes: 11 additions & 23 deletions nav2_lifecycle_manager/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,24 @@
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>geometry_msgs</build_depend>
<build_depend>lifecycle_msgs</build_depend>
<build_depend>nav2_msgs</build_depend>
<build_depend>nav2_util</build_depend>
<build_depend>rclcpp_action</build_depend>
<build_depend>rclcpp_lifecycle</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>std_srvs</build_depend>
<build_depend>tf2_geometry_msgs</build_depend>
<build_depend>bondcpp</build_depend>
<build_depend>nav2_common</build_depend>
<build_depend>diagnostic_updater</build_depend>

<exec_depend>geometry_msgs</exec_depend>
<exec_depend>lifecycle_msgs</exec_depend>
<exec_depend>nav2_msgs</exec_depend>
<exec_depend>nav2_util</exec_depend>
<exec_depend>rclcpp_action</exec_depend>
<exec_depend>rclcpp_lifecycle</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>std_srvs</exec_depend>
<exec_depend>bondcpp</exec_depend>
<exec_depend>tf2_geometry_msgs</exec_depend>
<exec_depend>diagnostic_updater</exec_depend>
<depend>bondcpp</depend>
<depend>diagnostic_updater</depend>
<depend>geometry_msgs</depend>
<depend>lifecycle_msgs</depend>
<depend>nav2_msgs</depend>
<depend>nav2_util</depend>
<depend>rclcpp</depend>
<depend>rclcpp_action</depend>
<depend>rclcpp_components</depend>
<depend>std_srvs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
<test_depend>rclcpp_lifecycle</test_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
1 change: 0 additions & 1 deletion nav2_lifecycle_manager/src/lifecycle_manager_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <string>
#include <utility>

#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
#include "nav2_util/geometry_utils.hpp"

namespace nav2_lifecycle_manager
Expand Down
15 changes: 5 additions & 10 deletions nav2_lifecycle_manager/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit a366ca2

Please sign in to comment.