Skip to content

Deprecate ament_target_dependencies() - #572

Merged
sloretz merged 2 commits into
rollingfrom
sloretz__deprecate_ament_target_dependencies
Apr 6, 2025
Merged

sloretz merged 2 commits into
rollingfrom
sloretz__deprecate_ament_target_dependencies

Conversation

@sloretz

@sloretz sloretz commented Mar 15, 2025 •

Copy link
Copy Markdown
Contributor

There are no more uses of ament_target_dependencies() in the core 🎉

Requires #571
Requires ros2/system_tests#566


This PR deprecates ament_target_dependencies() in favor of target_link_libraries(). This PR also adds a deprecation warning that suggests a target_link_libraries() call to be used instead.

For example, I inserted a call to ament_target_dependencies into my local copy of tf2_ros:

ament_target_dependencies(${PROJECT_NAME} PUBLIC
  builtin_interfaces
  geometry_msgs
  message_filters
  rclcpp
  rclcpp_action
  tf2
  tf2_msgs
)

I got the following deprecation warning when I built it.

CMake Deprecation Warning at /workspaces/ros2/install/ament_cmake_target_dependencies/share/ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake:89 (message):
  ament_target_dependencies() is deprecated.  Use target_link_libraries()
  with modern CMake targets instead.  Try replacing this call with:

    target_link_libraries(tf2_ros PUBLIC
      ${builtin_interfaces_TARGETS}
      ${geometry_msgs_TARGETS}
      ${tf2_msgs_TARGETS}
      message_filters::message_filters
      rclcpp::rclcpp
      rclcpp_action::rclcpp_action
      tf2::tf2
    )

Call Stack (most recent call first):
  CMakeLists.txt:45 (ament_target_dependencies)

The suggested target_link_libraries() call matches the real call (minus a difference in sorting)
https://github.com/ros2/geometry2/blob/d60e39d663e21d2e426a2a7ff3e3d266df6f8c9a/tf2_ros/CMakeLists.txt#L37-L44

#292

@sloretz
sloretz marked this pull request as ready for review March 26, 2025 20:31

@christophebedard christophebedard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's probably the most helpful deprecation warning I've seen 👏

@sloretz

sloretz commented Apr 5, 2025

Copy link
Copy Markdown
Contributor Author

Pulls: #572
Gist: https://gist.githubusercontent.com/sloretz/b8090a5bd5c961cd144e6601088e87d3/raw/a4b93d93596b28675a7280e08b13b9697dc99bea/ros2.repos
BUILD args: --packages-above-and-dependencies ament_cmake_target_dependencies
TEST args: --packages-above ament_cmake_target_dependencies
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15601

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

@sloretz
sloretz merged commit b9a046b into rolling Apr 6, 2025
@sloretz
sloretz deleted the sloretz__deprecate_ament_target_dependencies branch April 6, 2025 00:29
Rayman added a commit to ros-perception/perception_pcl that referenced this pull request May 22, 2025
`ament_target_dependencies` is deprecated rolling, so we should convert
all usages to `target_link_libraries`. See also the following
discussion:

ament/ament_cmake#572
SteveMacenski pushed a commit to ros-perception/perception_pcl that referenced this pull request May 22, 2025
`ament_target_dependencies` is deprecated rolling, so we should convert
all usages to `target_link_libraries`. See also the following
discussion:

ament/ament_cmake#572
AntoBrandi pushed a commit to AntoBrandi/perception_pcl that referenced this pull request Aug 26, 2025
`ament_target_dependencies` is deprecated rolling, so we should convert
all usages to `target_link_libraries`. See also the following
discussion:

ament/ament_cmake#572
jcfurey pushed a commit to jcfurey/ouster-ros that referenced this pull request May 17, 2026
`ament_target_dependencies()` is being deprecated in newer ROS 2 distros
(ament/ament_cmake#572, merged Apr 2025). In rolling/lyrical, the
ament_cmake metapackage no longer hard-depends on
ament_cmake_target_dependencies — it's now only a build_export_depend.
Consumers that still call `ament_target_dependencies()` need to opt in
by find_package'ing the dedicated package and declaring it as a
buildtool_depend so rosdep installs it.

This unblocks the lyrical Docker build:
  CMake Error at CMakeLists.txt:103 (ament_target_dependencies):
    Unknown CMake command \"ament_target_dependencies\".

Migration to direct \`target_link_libraries(target pkg::pkg)\` /
\`\${pkg_TARGETS}\` is the longer-term fix but out of scope here.
wentasah added a commit to wentasah/ros2_console_tools that referenced this pull request Aug 17, 2026
ament_target_dependencies is deprecated [1] and was removed in ROS
Lyrical [2]. This commit replaces calls to ament_target_dependencies
with plain CMake command target_link_libraries as suggested in [1].
While [1] suggested to replace interface packages with ${xxx_TARGETS},
this is not necessary since [3]. Therefore, this commit replaces every
"xxx" package with "xxx::xxx" target.

Compilation was tested under ROS Jazzy and Lyrical.

[1]: ament/ament_cmake#572
[2]: ament/ament_cmake#583
[3]: ros2/rosidl#947
robwoolley added a commit to robwoolley/meta-ros that referenced this pull request Sep 2, 2026
…pendencies)

Root-caused via web search after a validation rebuild showed the earlier
ament-cmake-target-dependencies DEPENDS fix (260c780) wasn't enough on
its own: aruco-ros still hit "Unknown CMake command
\"ament_target_dependencies\"" even though the package's cmake config was
now correctly staged into its sysroot (confirmed on disk).

Turns out staging the files was necessary but not sufficient. In
lyrical/rolling, the ament_cmake metapackage no longer hard-depends on
ament_cmake_target_dependencies -- it's only a build_export_depend now
(see ament/ament_cmake#572) -- so plain
find_package(ament_cmake REQUIRED) no longer transitively find_package()'s
(and thus include()'s) ament_cmake_target_dependencies-extras.cmake the
way it did in older distros, which is what actually defines the
ament_target_dependencies() macro. Upstream's own fix is for each
consuming package's CMakeLists.txt to find_package() it directly, but
most of the ROS ecosystem hasn't been updated for that breaking change
yet.

Rather than patch 25+ individual upstream CMakeLists.txt files, inject it
globally via CMake's CMAKE_PROJECT_INCLUDE mechanism (runs right after
each project() call, in full script context) pointing at a new
ament_target_dependencies_compat.cmake next to this bbclass, which just
does find_package(ament_cmake_target_dependencies QUIET) -- a safe no-op
for packages that don't need it.

Referencing that file's path correctly needed a second fix: a bbclass's
own d.getVar('FILE') reflects whichever recipe is currently being parsed,
not the class's own file location, so a first attempt using
os.path.dirname(d.getVar('FILE')) resolved to (and appended)
"<consuming-recipe's-own-dir>/ament_target_dependencies_compat.cmake" for
every recipe -- verified wrong via bitbake-getvar before it was ever
built. Fixed by capturing LAYERDIR in this layer's own layer.conf (as
ROS2_LYRICAL_LAYER_DIR, immediate-expanded so it's frozen at the one
point where LAYERDIR is actually this layer's root) instead of trying to
derive it from inside the class. Re-verified via bitbake-getvar that
EXTRA_OECMAKE now carries the correct absolute path.

Also force-cleaned sstate (bitbake -c cleansstate) for ament-cmake(-native),
rosidl-cmake(-native), generate-parameter-library(-native), and
phidgets-api: the validation rebuild revealed that recipes which had
*always* succeeded earlier in the session (unlike the always-failing
consumers) were silently reusing stale pre-fix sstate artifacts -- e.g.
rosidl-cmake-native's do_configure log was dated Aug 22, six days before
the rosidl-adapter-native DEPENDS fix -- masking that fix's effect
entirely. Confirmed real: autoware-planning-msgs still had zero
rosidl_adapter files staged anywhere in its sysroot despite the fix being
correctly present in rosidl-cmake's own DEPENDS.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
yishinli added a commit to yishinli/abb_ros2 that referenced this pull request Oct 26, 2026
ament_target_dependencies() was deprecated in Kilted
(ament/ament_cmake#572) and removed in Rolling / Lyrical
(ament/ament_cmake#614), so abb_hardware_interface, abb_rws_client and
the abb_bringup tests fail to configure with "Unknown CMake command".

Link the exported CMake targets directly instead. abb_hardware_interface
only exports old-style variables, so abb_rws_client uses
abb_hardware_interface_LIBRARIES / _INCLUDE_DIRS for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants