Skip to content

Commit

Permalink
Use ament_export_targets
Browse files Browse the repository at this point in the history
* Link to exported namespace targets when possible

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed Feb 12, 2024
1 parent ef8a31b commit c0c7ef1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
48 changes: 35 additions & 13 deletions grid_map_costmap_2d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.13)
project(grid_map_costmap_2d)

## Find ament_cmake macros and libraries
Expand All @@ -7,23 +7,14 @@ find_package(grid_map_cmake_helpers REQUIRED)
find_package(grid_map_core REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav2_costmap_2d REQUIRED)

find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)

find_package(Eigen3 REQUIRED)

grid_map_package()

## Specify additional locations of header files
include_directories(
include
SYSTEM
${EIGEN3_INCLUDE_DIR}
${grid_map_core_INCLUDE_DIRS}
${nav2_costmap_2d_INCLUDE_DIRS}
${geometry_msgs_INCLUDE_DIRS}
)

set(dependencies
grid_map_core
geometry_msgs
Expand All @@ -32,13 +23,44 @@ set(dependencies
tf2_geometry_msgs
)

add_library(${PROJECT_NAME}
include/grid_map_costmap_2d/costmap_2d_converter.hpp
include/grid_map_costmap_2d/grid_map_costmap_2d.hpp
)

add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_link_libraries(${PROJECT_NAME}
PUBLIC
grid_map_core::grid_map_core
${geometry_msgs_TARGETS}
${tf2_geometry_msgs_TARGETS}
nav2_costmap_2d::nav2_costmap_2d_core
tf2_ros::tf2_ros
)

target_include_directories(${PROJECT_NAME}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)

#############
## Install ##
#############

# Mark library for installation
install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

# Mark cpp header files for installation
install(
DIRECTORY include/${PROJECT_NAME}/
DIRECTORY include/
DESTINATION include/${PROJECT_NAME}
FILES_MATCHING PATTERN "*.hpp"
)
Expand Down Expand Up @@ -77,6 +99,6 @@ if(BUILD_TESTING)
add_subdirectory(test)
endif()

ament_export_include_directories(include)
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(${dependencies})
ament_package()
10 changes: 6 additions & 4 deletions grid_map_costmap_2d/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ ament_add_gtest(${PROJECT_NAME}-test
test_costmap_2d_converter.cpp
)

ament_target_dependencies(${PROJECT_NAME}-test
${dependencies}
target_link_libraries(${PROJECT_NAME}-test
${PROJECT_NAME}::${PROJECT_NAME}
)

ament_add_gtest(costmap-2d-ros-test
test_costmap_2d_ros.cpp
)

ament_target_dependencies(costmap-2d-ros-test
${dependencies}
target_link_libraries(costmap-2d-ros-test
${PROJECT_NAME}::${PROJECT_NAME}
)


0 comments on commit c0c7ef1

Please sign in to comment.