Skip to content

Commit 6056680

Browse files
committed
Use ament_export_targets for all targets
* Matches new internal ALIAS targets * Use ALIAS targets for all internal linkage * Remove unnecessary calls to ament_target_dependencies in test code * Export includes in proper folders for overlays in colcon Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com>
1 parent 70dc1f9 commit 6056680

File tree

4 files changed

+63
-85
lines changed

4 files changed

+63
-85
lines changed

nav2_costmap_2d/CMakeLists.txt

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,10 @@ find_package(visualization_msgs REQUIRED)
2626
find_package(angles REQUIRED)
2727

2828
remove_definitions(-DDISABLE_LIBUSB-1.0)
29-
find_package(Eigen3 REQUIRED)
29+
find_package(Eigen3 3.3 REQUIRED)
3030

3131
nav2_package()
3232

33-
include_directories(
34-
include
35-
${EIGEN3_INCLUDE_DIRS}
36-
)
37-
38-
add_definitions(${EIGEN3_DEFINITIONS})
39-
4033
add_library(nav2_costmap_2d_core SHARED
4134
src/costmap_2d.cpp
4235
src/layer.cpp
@@ -51,6 +44,13 @@ add_library(nav2_costmap_2d_core SHARED
5144
src/footprint_collision_checker.cpp
5245
plugins/costmap_filters/costmap_filter.cpp
5346
)
47+
add_library(${PROJECT_NAME}::nav2_costmap_2d_core ALIAS nav2_costmap_2d_core)
48+
49+
target_include_directories(nav2_costmap_2d_core
50+
PUBLIC
51+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
52+
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
53+
)
5454

5555
set(dependencies
5656
geometry_msgs
@@ -78,6 +78,7 @@ set(dependencies
7878
ament_target_dependencies(nav2_costmap_2d_core
7979
${dependencies}
8080
)
81+
target_link_libraries(nav2_costmap_2d_core Eigen3::Eigen)
8182

8283
add_library(layers SHARED
8384
plugins/inflation_layer.cpp
@@ -88,42 +89,47 @@ add_library(layers SHARED
8889
plugins/range_sensor_layer.cpp
8990
plugins/denoise_layer.cpp
9091
)
92+
add_library(${PROJECT_NAME}::layers ALIAS layers)
9193
ament_target_dependencies(layers
9294
${dependencies}
9395
)
9496
target_link_libraries(layers
95-
nav2_costmap_2d_core
97+
${PROJECT_NAME}::nav2_costmap_2d_core
9698
)
9799

98100
add_library(filters SHARED
99101
plugins/costmap_filters/keepout_filter.cpp
100102
plugins/costmap_filters/speed_filter.cpp
101103
plugins/costmap_filters/binary_filter.cpp
102104
)
105+
add_library(${PROJECT_NAME}::filters ALIAS filters)
106+
107+
103108
ament_target_dependencies(filters
104109
${dependencies}
105110
)
106111
target_link_libraries(filters
107-
nav2_costmap_2d_core
112+
${PROJECT_NAME}::nav2_costmap_2d_core
108113
)
109114

110115
add_library(nav2_costmap_2d_client SHARED
111116
src/footprint_subscriber.cpp
112117
src/costmap_subscriber.cpp
113118
src/costmap_topic_collision_checker.cpp
114119
)
120+
add_library(${PROJECT_NAME}::nav2_costmap_2d_client ALIAS nav2_costmap_2d_client)
115121

116122
ament_target_dependencies(nav2_costmap_2d_client
117123
${dependencies}
118124
)
119125

120126
target_link_libraries(nav2_costmap_2d_client
121-
nav2_costmap_2d_core
127+
${PROJECT_NAME}::nav2_costmap_2d_core
122128
)
123129

124130
add_executable(nav2_costmap_2d_markers src/costmap_2d_markers.cpp)
125131
target_link_libraries(nav2_costmap_2d_markers
126-
nav2_costmap_2d_core
132+
${PROJECT_NAME}::nav2_costmap_2d_core
127133
)
128134

129135
ament_target_dependencies(nav2_costmap_2d_markers
@@ -132,7 +138,7 @@ ament_target_dependencies(nav2_costmap_2d_markers
132138

133139
add_executable(nav2_costmap_2d_cloud src/costmap_2d_cloud.cpp)
134140
target_link_libraries(nav2_costmap_2d_cloud
135-
nav2_costmap_2d_core
141+
${PROJECT_NAME}::nav2_costmap_2d_core
136142
)
137143

138144
add_executable(nav2_costmap_2d src/costmap_2d_node.cpp)
@@ -141,34 +147,30 @@ ament_target_dependencies(nav2_costmap_2d
141147
)
142148

143149
target_link_libraries(nav2_costmap_2d
144-
nav2_costmap_2d_core
150+
${PROJECT_NAME}::nav2_costmap_2d_core
145151
layers
146-
filters
152+
${PROJECT_NAME}::filters
147153
)
148154

149155
install(TARGETS
150-
nav2_costmap_2d_core
151156
layers
152157
filters
158+
nav2_costmap_2d_core
153159
nav2_costmap_2d_client
160+
nav2_costmap_2d_markers
161+
nav2_costmap_2d_cloud
162+
EXPORT export_${PROJECT_NAME}
154163
ARCHIVE DESTINATION lib
155164
LIBRARY DESTINATION lib
156165
RUNTIME DESTINATION bin
157166
)
158167

159-
install(TARGETS
160-
nav2_costmap_2d
161-
nav2_costmap_2d_markers
162-
nav2_costmap_2d_cloud
163-
RUNTIME DESTINATION lib/${PROJECT_NAME}
164-
)
165-
166168
install(FILES costmap_plugins.xml
167169
DESTINATION share/${PROJECT_NAME}
168170
)
169171

170172
install(DIRECTORY include/
171-
DESTINATION include/
173+
DESTINATION include/${PROJECT_NAME}
172174
)
173175

174176
if(BUILD_TESTING)
@@ -183,8 +185,7 @@ if(BUILD_TESTING)
183185
pluginlib_export_plugin_description_file(nav2_costmap_2d test/regression/order_layer.xml)
184186
endif()
185187

186-
ament_export_include_directories(include)
187-
ament_export_libraries(layers filters nav2_costmap_2d_core nav2_costmap_2d_client)
188+
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
188189
ament_export_dependencies(${dependencies})
189190
pluginlib_export_plugin_description_file(nav2_costmap_2d costmap_plugins.xml)
190191
ament_package()

nav2_costmap_2d/test/integration/CMakeLists.txt

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,66 @@
11
ament_add_gtest_executable(footprint_tests_exec
22
footprint_tests.cpp
33
)
4-
ament_target_dependencies(footprint_tests_exec
5-
${dependencies}
6-
)
74
target_link_libraries(footprint_tests_exec
8-
nav2_costmap_2d_core
9-
layers
5+
${PROJECT_NAME}::nav2_costmap_2d_core
6+
${PROJECT_NAME}::layers
107
)
118

129
ament_add_gtest_executable(test_collision_checker_exec
1310
test_costmap_topic_collision_checker.cpp
1411
)
15-
ament_target_dependencies(test_collision_checker_exec
16-
${dependencies}
17-
)
1812
target_link_libraries(test_collision_checker_exec
19-
nav2_costmap_2d_core
20-
nav2_costmap_2d_client
21-
layers
13+
${PROJECT_NAME}::nav2_costmap_2d_core
14+
${PROJECT_NAME}::nav2_costmap_2d_client
15+
${PROJECT_NAME}::layers
2216
)
2317

2418
ament_add_gtest_executable(inflation_tests_exec
2519
inflation_tests.cpp
2620
)
27-
ament_target_dependencies(inflation_tests_exec
28-
${dependencies}
29-
)
3021
target_link_libraries(inflation_tests_exec
31-
nav2_costmap_2d_core
32-
layers
22+
${PROJECT_NAME}::nav2_costmap_2d_core
23+
${PROJECT_NAME}::layers
3324
)
3425

3526
ament_add_gtest_executable(obstacle_tests_exec
3627
obstacle_tests.cpp
3728
)
38-
ament_target_dependencies(obstacle_tests_exec
39-
${dependencies}
40-
)
4129
target_link_libraries(obstacle_tests_exec
42-
nav2_costmap_2d_core
43-
layers
30+
${PROJECT_NAME}::nav2_costmap_2d_core
31+
${PROJECT_NAME}::layers
4432
)
4533

4634
ament_add_gtest_executable(range_tests_exec
4735
range_tests.cpp
4836
)
49-
ament_target_dependencies(range_tests_exec
50-
${dependencies}
51-
)
5237
target_link_libraries(range_tests_exec
53-
nav2_costmap_2d_core
54-
layers
38+
${PROJECT_NAME}::nav2_costmap_2d_core
39+
${PROJECT_NAME}::layers
5540
)
5641

5742
ament_add_gtest(dyn_params_tests
5843
dyn_params_tests.cpp
5944
)
60-
ament_target_dependencies(dyn_params_tests
61-
${dependencies}
62-
)
6345
target_link_libraries(dyn_params_tests
64-
nav2_costmap_2d_core
46+
${PROJECT_NAME}::nav2_costmap_2d_core
6547
)
6648

6749
ament_add_gtest_executable(test_costmap_publisher_exec
6850
test_costmap_2d_publisher.cpp
6951
)
70-
ament_target_dependencies(test_costmap_publisher_exec
71-
${dependencies}
72-
)
7352
target_link_libraries(test_costmap_publisher_exec
74-
nav2_costmap_2d_core
75-
nav2_costmap_2d_client
76-
layers
53+
${PROJECT_NAME}::nav2_costmap_2d_core
54+
${PROJECT_NAME}::nav2_costmap_2d_client
55+
${PROJECT_NAME}::layers
7756
)
7857

7958
ament_add_gtest_executable(test_costmap_subscriber_exec
8059
test_costmap_subscriber.cpp
8160
)
82-
ament_target_dependencies(test_costmap_subscriber_exec
83-
${dependencies}
84-
)
8561
target_link_libraries(test_costmap_subscriber_exec
86-
nav2_costmap_2d_core
87-
nav2_costmap_2d_client
62+
${PROJECT_NAME}::nav2_costmap_2d_core
63+
${PROJECT_NAME}::nav2_costmap_2d_client
8864
)
8965

9066
ament_add_test(test_collision_checker
@@ -166,6 +142,6 @@ ament_add_test(test_costmap_subscriber_exec
166142
# ${dependencies}
167143
# )
168144
# target_link_libraries(costmap_tester
169-
# nav2_costmap_2d_core
145+
# ${PROJECT_NAME}::nav2_costmap_2d_core
170146
# layers
171147
# )

nav2_costmap_2d/test/regression/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Bresenham2D corner cases test
22
ament_add_gtest(costmap_bresenham_2d costmap_bresenham_2d.cpp)
33
target_link_libraries(costmap_bresenham_2d
4-
nav2_costmap_2d_core
4+
${PROJECT_NAME}::nav2_costmap_2d_core
55
)
66

77
# OrderLayer for checking Costmap2D plugins API calling order
@@ -11,7 +11,7 @@ ament_target_dependencies(order_layer
1111
${dependencies}
1212
)
1313
target_link_libraries(order_layer
14-
nav2_costmap_2d_core
14+
${PROJECT_NAME}::nav2_costmap_2d_core
1515
)
1616
install(TARGETS
1717
order_layer
@@ -23,5 +23,5 @@ install(TARGETS
2323
# Costmap2D plugins API calling order test
2424
ament_add_gtest(plugin_api_order plugin_api_order.cpp)
2525
target_link_libraries(plugin_api_order
26-
nav2_costmap_2d_core
26+
${PROJECT_NAME}::nav2_costmap_2d_core
2727
)
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
11
ament_add_gtest(collision_footprint_test footprint_collision_checker_test.cpp)
22
target_link_libraries(collision_footprint_test
3-
nav2_costmap_2d_core
3+
${PROJECT_NAME}::nav2_costmap_2d_core
44
)
55

66
ament_add_gtest(costmap_convesion_test costmap_conversion_test.cpp)
77
target_link_libraries(costmap_convesion_test
8-
nav2_costmap_2d_core
8+
${PROJECT_NAME}::nav2_costmap_2d_core
99
)
1010

1111
ament_add_gtest(declare_parameter_test declare_parameter_test.cpp)
1212
target_link_libraries(declare_parameter_test
13-
nav2_costmap_2d_core
13+
${PROJECT_NAME}::nav2_costmap_2d_core
1414
)
1515

1616
ament_add_gtest(costmap_filter_test costmap_filter_test.cpp)
1717
target_link_libraries(costmap_filter_test
18-
nav2_costmap_2d_core
18+
${PROJECT_NAME}::nav2_costmap_2d_core
1919
)
2020

2121
ament_add_gtest(keepout_filter_test keepout_filter_test.cpp)
2222
target_link_libraries(keepout_filter_test
23-
nav2_costmap_2d_core
24-
filters
23+
${PROJECT_NAME}::nav2_costmap_2d_core
24+
${PROJECT_NAME}::filters
2525
)
2626

2727
ament_add_gtest(speed_filter_test speed_filter_test.cpp)
2828
target_link_libraries(speed_filter_test
29-
nav2_costmap_2d_core
30-
filters
29+
${PROJECT_NAME}::nav2_costmap_2d_core
30+
${PROJECT_NAME}::filters
3131
)
3232

3333
ament_add_gtest(binary_filter_test binary_filter_test.cpp)
3434
target_link_libraries(binary_filter_test
35-
nav2_costmap_2d_core
36-
filters
35+
${PROJECT_NAME}::nav2_costmap_2d_core
36+
${PROJECT_NAME}::filters
3737
)
3838

3939
ament_add_gtest(copy_window_test copy_window_test.cpp)
4040
target_link_libraries(copy_window_test
41-
nav2_costmap_2d_core
41+
${PROJECT_NAME}::nav2_costmap_2d_core
4242
)
4343

4444
ament_add_gtest(costmap_filter_service_test costmap_filter_service_test.cpp)
4545
target_link_libraries(costmap_filter_service_test
46-
nav2_costmap_2d_core
46+
${PROJECT_NAME}::nav2_costmap_2d_core
4747
)
4848

4949
ament_add_gtest(denoise_layer_test denoise_layer_test.cpp image_test.cpp image_processing_test.cpp)
5050
target_link_libraries(denoise_layer_test
51-
nav2_costmap_2d_core layers
51+
${PROJECT_NAME}::nav2_costmap_2d_core
52+
${PROJECT_NAME}::layers
5253
)
5354

5455
ament_add_gtest(lifecycle_test lifecycle_test.cpp)
5556
target_link_libraries(lifecycle_test
56-
nav2_costmap_2d_core
57+
${PROJECT_NAME}::nav2_costmap_2d_core
5758
)

0 commit comments

Comments
 (0)