Skip to content

Deprecate ament_target_dependencies()#572

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

Deprecate ament_target_dependencies()#572
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 added 2 commits March 14, 2025 23:58
Signed-off-by: Shane Loretz <sloretz@intrinsic.ai>
Signed-off-by: Shane Loretz <sloretz@intrinsic.ai>
@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.
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