Skip to content

Export CMake targets from Autoware packages and replace ament_target_dependencies #7412

Open

Description

@xmfcx

This issue tracks the work that the design discussion below agreed on. Autoware library packages export CMake targets, and every package links its dependencies with target_link_libraries() and those targets. This replaces ament_target_dependencies(), which ROS 2 Lyrical removed.

Mitsudome-san and I discussed the design decisions, and we agreed on the options below.

Decisions

Decision Agreed option
D1 Where the targets get exported In autoware_ament_auto_package() in autoware_cmake
D2 Default behavior of the wrapper Opt-in with the flag EXPORT_LIBRARY_TARGETS, the same name as in the upstream change
D3 The classic variables during the transition Export both the targets and the classic variables until phase 4
D4 How a consumer names a dependency ${<pkg>_TARGETS}. Explicit target names are permitted where a package exports several libraries and the code needs only one
D5 The scope keyword The plain form, without PUBLIC or PRIVATE, as the old calls had
D6 Lyrical before the migration finishes No bridge. Autoware does not bring back ament_target_dependencies(). Lyrical builds after phases 1 to 3 land in each repository
D7 Upstream Help to finish the upstream change for Rolling, and keep the wrapper equal to it

The upstream change for D2 and D7:

Because of D6, the Lyrical CI checks of a repository can become required only after phase 3 lands in that repository. The one-to-one replacement with variables is not used:

Phase 1: export targets in autoware_cmake

  • Add EXPORT_LIBRARY_TARGETS to autoware_ament_auto_package(). It installs each library of the package with EXPORT, calls ament_export_targets(), and keeps ament_export_libraries().
  • Wrap the public include folders in $<BUILD_INTERFACE:...> and add the install include folder, so that install(EXPORT) accepts them.
  • Handle libraries that link a local target, for example the <pkg>_param target of generate_parameter_library or a CUDA library. The package adds such a target to the export with list(APPEND ${PROJECT_NAME}_TARGETS <target>) before the macro call.
  • Measure a clean build before the change, on Jazzy and Humble (see Measurement).
  • Release autoware_cmake 1.5.0 with the flag. The release issue tracks the rosdistro pull requests and the autoware.repos bump.

The change and the release:

Phase 2: producers

105 workspace packages build a library with ament_auto_add_library() that another package uses. 100 of them are in Autoware repositories. Each of these opts in with EXPORT_LIBRARY_TARGETS, and a package on ament_auto_package() moves to autoware_ament_auto_package() in the same change. On Humble and Jazzy both macros install headers to include. The wrapper also passed header-only (INTERFACE) libraries to ament_export_libraries(), which breaks their consumers. A separate fix makes the wrapper skip them, as ament_auto_package() does on Jazzy and later. After that fix, the move changes nothing else.

Some producers live in repositories that do not use autoware_cmake: muSSP and pointcloud_to_laserscan (tier4), eagleye and llh_converter (MapIV), and boost_io_context in transport_drivers. They get a target export in their own repository. Until then, their consumers keep the variables.

A package whose exported library links a target of another package must pass that package on, or its consumers fail with "target was not found". See the third case in the Q&A.

Phase 3: consumers

Each ament_target_dependencies() call becomes target_link_libraries() with ${<pkg>_TARGETS}. Calls that only repeat what ament_auto already links get deleted. One PR per repository.

  • autoware_core: 43 calls in 22 files
  • autoware_universe: 86 calls in 50 files
  • autoware_tools: 13 calls in 10 files
  • autoware_rviz_plugins: 2 calls in 2 files
  • autoware_utils: 1 call
  • autoware_simple_planning_simulator: 1 call

Outside Autoware, these repositories do not use autoware_cmake, so their calls need PRs in their own repositories:

  • agnocast: 54 calls in 7 files
  • transport_drivers: 7 calls in 4 files

pcl_conversions on Humble and Jazzy and grid_map_ros export file lists. Their 5 call sites in autoware_universe keep the variables. A target export for grid_map_ros can join the grid_map maintenance work:

Phase 4: cleanup

  • When nothing reads <pkg>_LIBRARIES of Autoware packages anymore, the wrapper stops calling ament_export_libraries().
  • Make the target export the default of the wrapper and remove the flag.
  • Measure the clean build again.

Phase 5: upstream

  • Share Autoware's measurements on the upstream change, and help to finish it for Rolling.

Measurement

A clean colcon build of core and universe, on one machine, with ccache off and -DBUILD_TESTING=OFF, before phase 1, after phase 1, and after phase 4:

  • The total wall time and CPU time, on Jazzy and on Humble.
  • The CMake configure time of the deepest packages, for example autoware_behavior_path_planner and autoware_route_handler.

Q&A

What does a package give to other packages today?

When a package such as autoware_route_handler is built and installed, it leaves three things for other packages:

  • Its library file, for example libautoware_route_handler.so.
  • Its header folder.
  • A plain list of file paths in autoware_route_handler_LIBRARIES. The list holds its own library file, every library that it needs, and every library that those need, written out one by one.

A package that uses it gives this list to the linker as it is. Nobody checks the list.

What does EXPORT_LIBRARY_TARGETS add?

The package still leaves those three things. It also leaves a CMake file in share/<pkg>/cmake/ that describes each library as a target, for example autoware_route_handler::autoware_route_handler. The description holds the library file, the installed header folder, and the libraries that it needs, by name, for example rclcpp::rclcpp. A package that uses it links that one name, and CMake follows the dependencies by itself. CMake writes each library only once on the link line.

Is this only an extra file?

No. The extra file is harmless by itself, but two other things change with it:

  1. The wrapper installs the libraries with install(TARGETS ... EXPORT ...) instead of install(TARGETS ...). With EXPORT, CMake checks the settings of each library before it writes the file, and stops the build of the package when a setting is not valid after install. Without EXPORT, CMake never checks these settings. The wrapper also rewrites the include path of each library so that it passes this check. The package's own compile gets the same path as before.
  2. Packages that depend on it switch to the new file without any edit. ament_target_dependencies() uses only the targets of a package when the package has them, and ignores its file list. Every ament_auto_add_library() and ament_auto_add_executable() call goes through this function. This switch is the goal, because it gives the short link lines and the faster builds.

What stays the same?

The package keeps its own <pkg>_LIBRARIES and <pkg>_INCLUDE_DIRS until phase 4. But the classic variables of a package one level downstream change. When package B depends on package A, and A exports targets, B_LIBRARIES still holds the library file of A, and it also holds the targets of the dependencies of A. B_INCLUDE_DIRS and B_RECURSIVE_DEPENDENCIES no longer hold the entries of the dependencies of A. A probe on Jazzy still built and ran with these variables.

What can fail, and how do we fix it?

Case Where it fails Fix
A library has a header folder inside the source or build folder, which does not exist after install. The wrapper fixes the standard include folder, but not the extra folders that a package adds with target_include_directories(... PUBLIC ...). The build of the package that turns on the flag Wrap the folder in $<BUILD_INTERFACE:...>
A library links a helper library of the same package that does not get installed with it, for example a plain or CUDA add_library() target, or the _param target of generate_parameter_library. The build of the package that turns on the flag Install the helper library in the same export, or link it in a way that does not need it after install
The library links a target of package X, but a package that uses the library never loads X, so it does not know the name of the target. This happens in two ways. package.xml lists X only as <build_depend>, because the wrapper passes on a dependency only when package.xml also lists it as <depend>, <build_export_depend> or <exec_depend>. The macro finds this case and stops. Or the CMake package name is not the package.xml key: eigen gives Eigen3::Eigen, libpcl-all-dev gives PCL, and the vendor packages pybind11_vendor and yaml_cpp_vendor do not define the pybind11 and yaml-cpp targets. For a <build_depend>, the build of the package itself. Otherwise the build of a package that depends on it, with "target was not found" For a <build_depend>, list X as <depend>. For a different CMake name, add ament_export_dependencies(<CMake name>) before the macro call, for example ament_export_dependencies(Eigen3)

A scan on Jazzy turned on the export in all 92 library packages that another package uses. 0 hit the first case, 9 hit the second case, and 7 hit the third case. Only 1 of the 16 needs a package.xml tag change. The other 6 of the third case need ament_export_dependencies().

Why is the flag opt-in?

Because of the check and the switch above. With the flag, each package turns on the export in its own PR, and its own CI shows the failures of that package only. If the export were the default, one autoware_cmake release would turn it on in every package at once. That includes the packages that the ROS build farm builds from the released autoware_cmake, and packages outside Autoware that use it. Phase 4 makes the export the default and removes the flag, after every package has it.

What else changes for the packages that use the library?

  • The installed headers reach them as system headers, as before. The macro sets this itself, because mrt_cmake_modules turns off the CMake default for imported targets in the Lanelet2 packages. Without it, a warning in an exported header becomes an error there.
  • The PUBLIC compile options and definitions of the library now reach them. The classic export never passed these on. For example, autoware_test_utils sets PUBLIC -Wno-deprecated-declarations. Make such options PRIVATE before the package turns on the flag.
  • With colcon build --symlink-install, the exported libraries are copied to the install folder, not linked. Upstream ROS packages behave the same.

Is there anything else?

The new file stores absolute paths for the few outside packages that still give file lists, for example pcl_conversions on Humble and Jazzy. This works in a colcon workspace and in Debian packages. It can break if an install folder moves after the build. That case is not tested yet.

Related

I wrote this issue with Claude Code, from the discussion and my direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions