Skip to content

Commit

Permalink
Switch nav2_planner to modern CMake idioms. (ros-navigation#4592)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lalancette <[email protected]>
Signed-off-by: Joseph Duchesne <[email protected]>
  • Loading branch information
clalancette authored and josephduchesne committed Dec 10, 2024
1 parent b2b74cf commit 7d369e0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 64 deletions.
97 changes: 51 additions & 46 deletions nav2_planner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)
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
Expand All @@ -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()
1 change: 0 additions & 1 deletion nav2_planner/include/nav2_planner/planner_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 12 additions & 11 deletions nav2_planner/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>nav2_common</build_depend>

<depend>rclcpp</depend>
<depend>rclcpp_action</depend>
<depend>rclcpp_lifecycle</depend>
<depend>visualization_msgs</depend>
<depend>nav2_util</depend>
<depend>nav2_msgs</depend>
<depend>nav_msgs</depend>
<depend>geometry_msgs</depend>
<depend>builtin_interfaces</depend>
<depend>nav2_common</depend>
<depend>tf2_ros</depend>
<depend>lifecycle_msgs</depend>
<depend>nav2_core</depend>
<depend>nav2_costmap_2d</depend>
<depend>nav2_msgs</depend>
<depend>nav2_util</depend>
<depend>nav_msgs</depend>
<depend>pluginlib</depend>
<depend>nav2_core</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>rclcpp_lifecycle</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>ament_lint_auto</test_depend>

Expand Down
1 change: 0 additions & 1 deletion nav2_planner/src/planner_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <vector>
#include <utility>

#include "builtin_interfaces/msg/duration.hpp"
#include "lifecycle_msgs/msg/state.hpp"
#include "nav2_util/costmap.hpp"
#include "nav2_util/node_utils.hpp"
Expand Down
6 changes: 3 additions & 3 deletions nav2_planner/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
4 changes: 2 additions & 2 deletions nav2_planner/test/test_dynamic_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License. Reserved.

#include <math.h>

#include <cmath>
#include <memory>
#include <string>
#include <vector>
Expand All @@ -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
{
Expand Down

0 comments on commit 7d369e0

Please sign in to comment.