Skip to content

Create an aggregate target for rosidl generated interfaces targets#947

Merged
ahcorde merged 1 commit intorollingfrom
emerson/rosidl_interfaces_group_target
Mar 20, 2026
Merged

Create an aggregate target for rosidl generated interfaces targets#947
ahcorde merged 1 commit intorollingfrom
emerson/rosidl_interfaces_group_target

Conversation

@emersonknapp
Copy link
Collaborator

Description

Fixes #746

Adds a new aggregate target via CMake INTERFACE target type to bundle together the ${package_TARGETS} that are currently needed to use rosidl interfaces.

target_link_libraries(my_lib ${sensor_msgs_TARGETS}

can now use the following to get the same result.

target_link_libraries(my_lib sensor_msgs::sensor_msgs

Is this user-facing behavior change?

This is a new feature that users can opt in to using.

Did you use Generative AI?

This was assisted by Claude Code using Sonnet 4.6 model, all lines manually reviewed.

Additional Information

N/A

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
@ahcorde
Copy link
Contributor

ahcorde commented Mar 20, 2026

Pulls: #947, ros2/rcl#1302
Gist: https://gist.githubusercontent.com/ahcorde/acd58b8fa6eeb16e16181898c3d7e692/raw/849eedfb0d3b3a25c7f8edb8b7048ffff8a64d7d/ros2.repos
BUILD args: --packages-above-and-dependencies rosidl_cmake rcl
TEST args: --packages-above rosidl_cmake rcl
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18571

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit e61e46d into rolling Mar 20, 2026
3 checks passed
@ahcorde ahcorde deleted the emerson/rosidl_interfaces_group_target branch March 20, 2026 16:44
@emersonknapp
Copy link
Collaborator Author

@Mergifyio backport kilted jazzy humble

@mergify
Copy link
Contributor

mergify bot commented Mar 20, 2026

backport kilted jazzy humble

✅ Backports have been created

Details

mergify bot pushed a commit that referenced this pull request Mar 20, 2026
)

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
(cherry picked from commit e61e46d)
mergify bot pushed a commit that referenced this pull request Mar 20, 2026
)

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
(cherry picked from commit e61e46d)
mergify bot pushed a commit that referenced this pull request Mar 20, 2026
)

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
(cherry picked from commit e61e46d)
@peci1
Copy link

peci1 commented Mar 20, 2026

This is great, thanks! I guess now it is also possible to adjust the deprecation warning for ament_target_dependencies in distros that still have it, right?

ahcorde pushed a commit that referenced this pull request Mar 23, 2026
) (#950)

(cherry picked from commit e61e46d)

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Co-authored-by: Emerson Knapp <537409+emersonknapp@users.noreply.github.com>
ahcorde pushed a commit that referenced this pull request Mar 23, 2026
) (#949)

(cherry picked from commit e61e46d)

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Co-authored-by: Emerson Knapp <537409+emersonknapp@users.noreply.github.com>
# Create a convenience aggregate target @PROJECT_NAME@::@PROJECT_NAME@
# that links all generated interface targets, so downstream packages can use
# a single modern CMake target name instead of ${@PROJECT_NAME@_TARGETS}.
if(@PROJECT_NAME@_TARGETS AND NOT TARGET @PROJECT_NAME@::@PROJECT_NAME@)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I'm late to the conversation (sorry), but given this potential (and I think real in the wild) collision, did you consider something like this:

target_link_libraries(my_lib sensor_msgs::rosidl_targets)

Or something more meaningful that repeating the project name? Perhaps this could be a "yes, and ..." idea. We could have both targets defined (e.g. sensor_msgs::rosidl_targets, or whatever we call it, and sensor_msgs::sensor_msgs unless that target already exists)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term, this target could also be an aggregate for more granularity, e.g. sensor_msgs::rosidl_targets_cpp, sensor_msgs::rosidl_targets_python, sensor_msgs::rosidl_generate_protobuf_targets, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, makes sense to me

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a more human-freindly ::interfaces ?

Copy link

@Zyrin Zyrin Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collisions is indeed a problem. And I would suggest changing the name before the next release.
Regarding the name for this interface target: I would suggest to NOT includ "target(s)" in the name as this is an interface target and not a list of targets.
Maybe something like "rosidl_interfaces" as "interfaces" could be another candidate for collisions.


find_package(ament_cmake_export_dependencies QUIET REQUIRED)

_rosidl_cmake_aggregate_target_register_package_hook()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there should probably be a documented way to opt-out of this behavior. Currently you could set _ROSIDL_CMAKE_AGGREGATE_TARGET_PACKAGE_HOOK_REGISTERED manually, but that doesn't seem very dog-foody.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you want to opt out of that? Targets are the way to go.
Instead "${PROJECT_NAME}_TARGETS" should be removed at some point.

ahcorde pushed a commit that referenced this pull request Mar 26, 2026
) (#948)

(cherry picked from commit e61e46d)

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Co-authored-by: Emerson Knapp <537409+emersonknapp@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide documented CMake exported namespace targets for consuming generated packages without ament_target_dependencies

6 participants