From e722563bcad7bc2b9d86380b794055306d102dd2 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 20 Aug 2024 14:50:28 -0400 Subject: [PATCH] Switch opennav_docking_bt to modern CMake idioms. (#4631) Signed-off-by: Chris Lalancette --- .../opennav_docking_bt/CMakeLists.txt | 82 ++++++++++--------- nav2_docking/opennav_docking_bt/package.xml | 11 +-- .../opennav_docking_bt/test/CMakeLists.txt | 20 ++++- 3 files changed, 66 insertions(+), 47 deletions(-) diff --git a/nav2_docking/opennav_docking_bt/CMakeLists.txt b/nav2_docking/opennav_docking_bt/CMakeLists.txt index c89330ee38..a852c4124b 100644 --- a/nav2_docking/opennav_docking_bt/CMakeLists.txt +++ b/nav2_docking/opennav_docking_bt/CMakeLists.txt @@ -2,56 +2,56 @@ cmake_minimum_required(VERSION 3.5) project(opennav_docking_bt) find_package(ament_cmake REQUIRED) -find_package(rclcpp REQUIRED) -find_package(rclcpp_action REQUIRED) -find_package(std_msgs REQUIRED) -find_package(nav2_util REQUIRED) -find_package(nav2_msgs REQUIRED) -find_package(nav2_core REQUIRED) +find_package(behaviortree_cpp REQUIRED) +find_package(geometry_msgs REQUIRED) find_package(nav2_behavior_tree REQUIRED) +find_package(nav2_common REQUIRED) +find_package(nav2_core REQUIRED) +find_package(nav2_msgs REQUIRED) +find_package(nav2_util REQUIRED) find_package(nav_msgs REQUIRED) -find_package(geometry_msgs REQUIRED) -find_package(behaviortree_cpp REQUIRED) +find_package(rclcpp REQUIRED) +find_package(rclcpp_action REQUIRED) -# potentially replace with nav2_common, nav2_package() -set(CMAKE_CXX_STANDARD 17) -add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wdeprecated -fPIC -Wshadow -Wnull-dereference) +nav2_package() -include_directories( - include +add_library(opennav_dock_action_bt_node SHARED src/dock_robot.cpp) +target_include_directories(opennav_dock_action_bt_node + PUBLIC + "$" + "$" ) - -set(dependencies - rclcpp - rclcpp_action - std_msgs - nav2_util - nav2_msgs - nav2_core - nav2_behavior_tree - nav_msgs - geometry_msgs - behaviortree_cpp +target_compile_definitions(opennav_dock_action_bt_node PRIVATE BT_PLUGIN_EXPORT) +target_link_libraries(opennav_dock_action_bt_node PUBLIC + behaviortree_cpp::behaviortree_cpp + ${geometry_msgs_TARGETS} + nav2_behavior_tree::nav2_behavior_tree + ${nav2_msgs_TARGETS} ) -add_library(opennav_dock_action_bt_node SHARED src/dock_robot.cpp) -list(APPEND plugin_libs opennav_dock_action_bt_node) add_library(opennav_undock_action_bt_node SHARED src/undock_robot.cpp) -list(APPEND plugin_libs opennav_undock_action_bt_node) - -foreach(bt_plugin ${plugin_libs}) - ament_target_dependencies(${bt_plugin} ${dependencies}) - target_compile_definitions(${bt_plugin} PRIVATE BT_PLUGIN_EXPORT) -endforeach() +target_include_directories(opennav_undock_action_bt_node + PUBLIC + "$" + "$" +) +target_compile_definitions(opennav_undock_action_bt_node PRIVATE BT_PLUGIN_EXPORT) +target_link_libraries(opennav_undock_action_bt_node PUBLIC + behaviortree_cpp::behaviortree_cpp + ${geometry_msgs_TARGETS} + nav2_behavior_tree::nav2_behavior_tree + ${nav2_msgs_TARGETS} +) -install(TARGETS ${plugin_libs} +install(TARGETS opennav_dock_action_bt_node opennav_undock_action_bt_node + EXPORT ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) install(DIRECTORY include/ - DESTINATION include/ + DESTINATION include/${PROJECT_NAME} ) install(DIRECTORY behavior_trees DESTINATION share/${PROJECT_NAME}) @@ -63,7 +63,13 @@ if(BUILD_TESTING) add_subdirectory(test) endif() -ament_export_include_directories(include) -ament_export_libraries(${plugin_libs}) -ament_export_dependencies(${dependencies}) +ament_export_include_directories(include/${PROJECT_NAME}) +ament_export_libraries(opennav_dock_action_bt_node opennav_undock_action_bt_node) +ament_export_dependencies( + behaviortree_cpp + geometry_msgs + nav2_behavior_tree + nav2_msgs +) +ament_export_targets(${PROJECT_NAME}) ament_package() diff --git a/nav2_docking/opennav_docking_bt/package.xml b/nav2_docking/opennav_docking_bt/package.xml index 85b90b1207..3778555116 100644 --- a/nav2_docking/opennav_docking_bt/package.xml +++ b/nav2_docking/opennav_docking_bt/package.xml @@ -8,16 +8,17 @@ Apache-2.0 ament_cmake + nav2_common - rclcpp - rclcpp_action + behaviortree_cpp + geometry_msgs nav2_behavior_tree - nav2_util nav2_core nav2_msgs + nav2_util nav_msgs - geometry_msgs - behaviortree_cpp + rclcpp + rclcpp_action ament_lint_common ament_lint_auto diff --git a/nav2_docking/opennav_docking_bt/test/CMakeLists.txt b/nav2_docking/opennav_docking_bt/test/CMakeLists.txt index ba0c374f8b..077e3a8581 100644 --- a/nav2_docking/opennav_docking_bt/test/CMakeLists.txt +++ b/nav2_docking/opennav_docking_bt/test/CMakeLists.txt @@ -1,9 +1,21 @@ # Cancel test ament_add_gtest(test_dock_robot test_dock_robot.cpp) -target_link_libraries(test_dock_robot opennav_dock_action_bt_node) -ament_target_dependencies(test_dock_robot ${dependencies}) +target_link_libraries(test_dock_robot + behaviortree_cpp::behaviortree_cpp + ${geometry_msgs_TARGETS} + ${nav2_msgs_TARGETS} + opennav_dock_action_bt_node + rclcpp::rclcpp + rclcpp_action::rclcpp_action +) # Make command test ament_add_gtest(test_undock_robot test_undock_robot.cpp) -target_link_libraries(test_undock_robot opennav_undock_action_bt_node) -ament_target_dependencies(test_undock_robot ${dependencies}) +target_link_libraries(test_undock_robot + behaviortree_cpp::behaviortree_cpp + ${geometry_msgs_TARGETS} + ${nav2_msgs_TARGETS} + opennav_undock_action_bt_node + rclcpp::rclcpp + rclcpp_action::rclcpp_action +)