From f1ea2940940c2d0dc05bb9532ce0eeb62b546da5 Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Sun, 11 Feb 2024 23:32:04 -0700 Subject: [PATCH 1/3] Use ament_export_targets * Link to exported namespace targets when possible Signed-off-by: Ryan Friedman (cherry picked from commit c0c7ef1e4da0bbe84a5ab4003e6429d0ecba66bf) --- grid_map_costmap_2d/CMakeLists.txt | 48 ++++++++++++++++++------- grid_map_costmap_2d/test/CMakeLists.txt | 10 +++--- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/grid_map_costmap_2d/CMakeLists.txt b/grid_map_costmap_2d/CMakeLists.txt index 544ded124..0a0716e1b 100644 --- a/grid_map_costmap_2d/CMakeLists.txt +++ b/grid_map_costmap_2d/CMakeLists.txt @@ -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 @@ -7,6 +7,7 @@ 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) @@ -14,16 +15,6 @@ 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 @@ -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 + "$" + "$" +) + ############# ## 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" ) @@ -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() diff --git a/grid_map_costmap_2d/test/CMakeLists.txt b/grid_map_costmap_2d/test/CMakeLists.txt index 31d13e3bf..9ca4e5003 100644 --- a/grid_map_costmap_2d/test/CMakeLists.txt +++ b/grid_map_costmap_2d/test/CMakeLists.txt @@ -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} ) + + From 1cc2625df2f892f8df189c1b95fc0d840c5162c4 Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Sat, 17 Feb 2024 12:12:41 -0700 Subject: [PATCH 2/3] Fix whitespace, make INTERFACE type Signed-off-by: Ryan Friedman (cherry picked from commit fb020294f4496bdc7b861a8847cfaeaf828add90) --- grid_map_costmap_2d/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/grid_map_costmap_2d/CMakeLists.txt b/grid_map_costmap_2d/CMakeLists.txt index 0a0716e1b..201c87601 100644 --- a/grid_map_costmap_2d/CMakeLists.txt +++ b/grid_map_costmap_2d/CMakeLists.txt @@ -7,7 +7,6 @@ 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) @@ -23,7 +22,7 @@ set(dependencies tf2_geometry_msgs ) -add_library(${PROJECT_NAME} +add_library(${PROJECT_NAME} INTERFACE include/grid_map_costmap_2d/costmap_2d_converter.hpp include/grid_map_costmap_2d/grid_map_costmap_2d.hpp ) @@ -31,7 +30,7 @@ add_library(${PROJECT_NAME} add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME} - PUBLIC + INTERFACE grid_map_core::grid_map_core ${geometry_msgs_TARGETS} ${tf2_geometry_msgs_TARGETS} @@ -40,7 +39,7 @@ target_link_libraries(${PROJECT_NAME} ) target_include_directories(${PROJECT_NAME} - PUBLIC + INTERFACE "$" "$" ) From d4dec3ce3728afe8806d17f518fc77c2ef542c9c Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Mon, 19 Feb 2024 22:29:52 -0700 Subject: [PATCH 3/3] Remove extra whitespace Signed-off-by: Ryan Friedman (cherry picked from commit 8c3abed54d95bdd6217c35fadadf5e7b28bc1f0b) --- grid_map_costmap_2d/test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/grid_map_costmap_2d/test/CMakeLists.txt b/grid_map_costmap_2d/test/CMakeLists.txt index 9ca4e5003..999537413 100644 --- a/grid_map_costmap_2d/test/CMakeLists.txt +++ b/grid_map_costmap_2d/test/CMakeLists.txt @@ -15,4 +15,3 @@ target_link_libraries(costmap-2d-ros-test ${PROJECT_NAME}::${PROJECT_NAME} ) -