Skip to content

Commit

Permalink
Switch nav2_velocity_smoother to modern CMake idioms. (#4606)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Aug 8, 2024
1 parent 46c40cb commit 3a4219d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
66 changes: 31 additions & 35 deletions nav2_velocity_smoother/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,42 @@ cmake_minimum_required(VERSION 3.5)
project(nav2_velocity_smoother)

find_package(ament_cmake REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav2_common REQUIRED)
find_package(nav2_util REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav2_util REQUIRED)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
find_package(rclcpp_lifecycle REQUIRED)

nav2_package()

include_directories(
include
)

set(executable_name velocity_smoother)
set(library_name ${executable_name}_core)

set(dependencies
rclcpp
rclcpp_components
geometry_msgs
nav2_util
)

# Main library
add_library(${library_name} SHARED
src/velocity_smoother.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_util::nav2_util_core
rclcpp::rclcpp
rclcpp_lifecycle::rclcpp_lifecycle
)
target_link_libraries(${library_name} PRIVATE
rclcpp_components::component
)

# Main executable
add_executable(${executable_name}
src/main.cpp
)
ament_target_dependencies(${executable_name}
${dependencies}
)
target_link_libraries(${executable_name} ${library_name})

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
set(ament_cmake_copyright_FOUND TRUE)
ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_gtest REQUIRED)
endif()
target_link_libraries(${executable_name} PRIVATE ${library_name} rclcpp::rclcpp)

rclcpp_components_register_nodes(${library_name} "nav2_velocity_smoother::VelocitySmoother")

Expand All @@ -68,17 +53,28 @@ install(TARGETS ${executable_name}
)

install(DIRECTORY include/
DESTINATION include/
DESTINATION include/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
set(ament_cmake_copyright_FOUND TRUE)
ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_gtest REQUIRED)
find_package(nav_msgs 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(
geometry_msgs
nav2_util
rclcpp
rclcpp_lifecycle
)
ament_package()
9 changes: 6 additions & 3 deletions nav2_velocity_smoother/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@

<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>nav2_common</build_depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>

<depend>geometry_msgs</depend>
<depend>nav2_util</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>rclcpp_lifecycle</depend>

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

<export>
<build_type>ament_cmake</build_type>
Expand Down
8 changes: 5 additions & 3 deletions nav2_velocity_smoother/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
ament_add_gtest(velocity_smoother_tests
test_velocity_smoother.cpp
)
ament_target_dependencies(velocity_smoother_tests
${dependencies}
)
target_link_libraries(velocity_smoother_tests
${library_name}
${geometry_msgs_TARGETS}
nav2_util::nav2_util_core
${nav_msgs_TARGETS}
rclcpp::rclcpp
rclcpp_lifecycle::rclcpp_lifecycle
)

0 comments on commit 3a4219d

Please sign in to comment.