Skip to content

Commit e61e46d

Browse files
authored
Create an aggregate target for rosidl generated interfaces targets (#947)
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
1 parent bab30b0 commit e61e46d

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# generated from rosidl_cmake/cmake/rosidl_cmake_aggregate_target-extras.cmake.in
2+
3+
# Create a convenience aggregate target @PROJECT_NAME@::@PROJECT_NAME@
4+
# that links all generated interface targets, so downstream packages can use
5+
# a single modern CMake target name instead of ${@PROJECT_NAME@_TARGETS}.
6+
if(@PROJECT_NAME@_TARGETS AND NOT TARGET @PROJECT_NAME@::@PROJECT_NAME@)
7+
add_library(@PROJECT_NAME@::@PROJECT_NAME@ INTERFACE IMPORTED)
8+
set_target_properties(@PROJECT_NAME@::@PROJECT_NAME@ PROPERTIES
9+
INTERFACE_LINK_LIBRARIES "${@PROJECT_NAME@_TARGETS}")
10+
endif()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2026 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Generate and register a post-extra file that creates the aggregate
16+
# interface target ${PROJECT_NAME}::${PROJECT_NAME} for downstream packages.
17+
# This uses CONFIG_EXTRAS_POST so it runs after ament_cmake_export_targets
18+
# has populated ${PROJECT_NAME}_TARGETS.
19+
set(_generated_extra_file
20+
"${CMAKE_CURRENT_BINARY_DIR}/rosidl_cmake/rosidl_cmake_aggregate_target-extras.cmake")
21+
configure_file(
22+
"${rosidl_cmake_DIR}/rosidl_cmake_aggregate_target-extras.cmake.in"
23+
"${_generated_extra_file}"
24+
@ONLY
25+
)
26+
list(APPEND ${PROJECT_NAME}_CONFIG_EXTRAS_POST "${_generated_extra_file}")

rosidl_cmake/rosidl_cmake-extras.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ macro(_rosidl_cmake_register_package_hook)
2424
"rosidl_cmake_package_hook.cmake")
2525

2626
find_package(ament_cmake_export_dependencies QUIET REQUIRED)
27+
28+
_rosidl_cmake_aggregate_target_register_package_hook()
29+
endif()
30+
endmacro()
31+
32+
# register ament_package() hook for the aggregate interface target once
33+
macro(_rosidl_cmake_aggregate_target_register_package_hook)
34+
if(NOT DEFINED _ROSIDL_CMAKE_AGGREGATE_TARGET_PACKAGE_HOOK_REGISTERED)
35+
set(_ROSIDL_CMAKE_AGGREGATE_TARGET_PACKAGE_HOOK_REGISTERED TRUE)
36+
37+
find_package(ament_cmake_core QUIET REQUIRED)
38+
ament_register_extension("ament_package" "rosidl_cmake"
39+
"rosidl_cmake_aggregate_target_package_hook.cmake")
2740
endif()
2841
endmacro()
2942

0 commit comments

Comments
 (0)