Skip to content

Commit 26f6efa

Browse files
authored
Switch to target_link_libraries. (ros2#2374)
That way we can hide more of the implementation by using the PRIVATE keyword. Signed-off-by: Chris Lalancette <[email protected]>
1 parent d08d9cf commit 26f6efa

File tree

9 files changed

+170
-460
lines changed

9 files changed

+170
-460
lines changed

rclcpp/CMakeLists.txt

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ find_package(rcpputils REQUIRED)
1616
find_package(rcutils REQUIRED)
1717
find_package(rmw REQUIRED)
1818
find_package(rosgraph_msgs REQUIRED)
19+
find_package(rosidl_dynamic_typesupport REQUIRED)
20+
find_package(rosidl_runtime_c REQUIRED)
1921
find_package(rosidl_runtime_cpp REQUIRED)
2022
find_package(rosidl_typesupport_c REQUIRED)
2123
find_package(rosidl_typesupport_cpp REQUIRED)
@@ -202,23 +204,28 @@ target_include_directories(${PROJECT_NAME} PUBLIC
202204
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
203205
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
204206
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
205-
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
206-
# specific order: dependents before dependencies
207-
ament_target_dependencies(${PROJECT_NAME}
208-
"ament_index_cpp"
209-
"libstatistics_collector"
210-
"rcl"
211-
"rcl_interfaces"
212-
"rcl_logging_interface"
213-
"rcl_yaml_param_parser"
214-
"rcpputils"
215-
"rcutils"
216-
"builtin_interfaces"
217-
"rosgraph_msgs"
218-
"rosidl_typesupport_cpp"
219-
"rosidl_runtime_cpp"
220-
"statistics_msgs"
221-
"tracetools"
207+
target_link_libraries(${PROJECT_NAME} PUBLIC
208+
${builtin_interfaces_TARGETS}
209+
libstatistics_collector::libstatistics_collector
210+
rcl::rcl
211+
${rcl_interfaces_TARGETS}
212+
rcl_yaml_param_parser::rcl_yaml_param_parser
213+
rcpputils::rcpputils
214+
rcutils::rcutils
215+
rmw::rmw
216+
${rosgraph_msgs_TARGETS}
217+
rosidl_dynamic_typesupport::rosidl_dynamic_typesupport
218+
rosidl_runtime_c::rosidl_runtime_c
219+
rosidl_runtime_cpp::rosidl_runtime_cpp
220+
rosidl_typesupport_cpp::rosidl_typesupport_cpp
221+
${statistics_msgs_TARGETS}
222+
tracetools::tracetools
223+
${CMAKE_THREAD_LIBS_INIT}
224+
)
225+
226+
target_link_libraries(${PROJECT_NAME} PRIVATE
227+
ament_index_cpp::ament_index_cpp
228+
rcl_logging_interface::rcl_logging_interface
222229
)
223230

224231
# Causes the visibility macros to use dllexport rather than dllimport,
@@ -240,20 +247,23 @@ ament_export_libraries(${PROJECT_NAME})
240247
# Export modern CMake targets
241248
ament_export_targets(${PROJECT_NAME})
242249

243-
# specific order: dependents before dependencies
244-
ament_export_dependencies(ament_index_cpp)
245-
ament_export_dependencies(libstatistics_collector)
246-
ament_export_dependencies(rcl)
247-
ament_export_dependencies(rcpputils)
248-
ament_export_dependencies(rcutils)
249-
ament_export_dependencies(builtin_interfaces)
250-
ament_export_dependencies(rosgraph_msgs)
251-
ament_export_dependencies(rosidl_typesupport_cpp)
252-
ament_export_dependencies(rosidl_typesupport_c)
253-
ament_export_dependencies(rosidl_runtime_cpp)
254-
ament_export_dependencies(rcl_yaml_param_parser)
255-
ament_export_dependencies(statistics_msgs)
256-
ament_export_dependencies(tracetools)
250+
ament_export_dependencies(
251+
builtin_interfaces
252+
libstatistics_collector
253+
rcl
254+
rcl_interfaces
255+
rcl_yaml_param_parser
256+
rcpputils
257+
rcutils
258+
rmw
259+
rosgraph_msgs
260+
rosidl_dynamic_typesupport
261+
rosidl_runtime_c
262+
rosidl_runtime_cpp
263+
rosidl_typesupport_cpp
264+
statistics_msgs
265+
tracetools
266+
)
257267

258268
if(BUILD_TESTING)
259269
find_package(ament_lint_auto REQUIRED)

rclcpp/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
<build_depend>builtin_interfaces</build_depend>
2323
<build_depend>rcl_interfaces</build_depend>
2424
<build_depend>rosgraph_msgs</build_depend>
25+
<build_depend>rosidl_runtime_c</build_depend>
2526
<build_depend>rosidl_runtime_cpp</build_depend>
2627
<build_depend>rosidl_typesupport_c</build_depend>
2728
<build_depend>rosidl_typesupport_cpp</build_depend>
2829
<build_export_depend>ament_index_cpp</build_export_depend>
2930
<build_export_depend>builtin_interfaces</build_export_depend>
3031
<build_export_depend>rcl_interfaces</build_export_depend>
3132
<build_export_depend>rosgraph_msgs</build_export_depend>
33+
<build_export_depend>rosidl_runtime_c</build_export_depend>
3234
<build_export_depend>rosidl_runtime_cpp</build_export_depend>
3335
<build_export_depend>rosidl_typesupport_c</build_export_depend>
3436
<build_export_depend>rosidl_typesupport_cpp</build_export_depend>

rclcpp/test/benchmark/CMakeLists.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ find_package(performance_test_fixture REQUIRED)
77

88
add_performance_test(benchmark_client benchmark_client.cpp)
99
if(TARGET benchmark_client)
10-
target_link_libraries(benchmark_client ${PROJECT_NAME})
11-
ament_target_dependencies(benchmark_client test_msgs rcl_interfaces)
10+
target_link_libraries(benchmark_client ${PROJECT_NAME} ${rcl_interfaces_TARGETS} ${test_msgs_TARGETS})
1211
endif()
1312

1413
add_performance_test(benchmark_executor benchmark_executor.cpp)
1514
if(TARGET benchmark_executor)
16-
target_link_libraries(benchmark_executor ${PROJECT_NAME})
17-
ament_target_dependencies(benchmark_executor test_msgs)
15+
target_link_libraries(benchmark_executor ${PROJECT_NAME} ${test_msgs_TARGETS})
1816
endif()
1917

2018
add_performance_test(benchmark_init_shutdown benchmark_init_shutdown.cpp)
@@ -39,6 +37,5 @@ endif()
3937

4038
add_performance_test(benchmark_service benchmark_service.cpp)
4139
if(TARGET benchmark_service)
42-
target_link_libraries(benchmark_service ${PROJECT_NAME})
43-
ament_target_dependencies(benchmark_service test_msgs rcl_interfaces)
40+
target_link_libraries(benchmark_service ${PROJECT_NAME} ${rcl_interfaces_TARGETS} ${test_msgs_TARGETS})
4441
endif()

0 commit comments

Comments
 (0)