Skip to content

fix(cmake): register package via ament_package() in ROS 2 builds#19

Merged
Georacer merged 1 commit into
ArduPilot:mainfrom
dakejahl:fix/ament-package-registration
May 22, 2026
Merged

fix(cmake): register package via ament_package() in ROS 2 builds#19
Georacer merged 1 commit into
ArduPilot:mainfrom
dakejahl:fix/ament-package-registration

Conversation

@dakejahl
Copy link
Copy Markdown
Contributor

@dakejahl dakejahl commented May 22, 2026

Summary

Call ament_package() at the end of the ament-cmake branch so the package registers itself on AMENT_PREFIX_PATH when sourcing the colcon workspace's install/setup.bash.

Problem

The ament branch sets COMPILING_WITH_AMENT, finds ament_cmake/plotjuggler, and installs the .so, but never calls ament_package(). Without it, colcon doesn't emit local_setup.bash and the package never lands on AMENT_PREFIX_PATH. Downstream tools that walk AMENT_PREFIX_PATH to discover plugins (e.g. PlotJuggler #1374) can't find the .so even though it's installed. The catkin branch already calls catkin_package() on line 52; this restores parity.

Solution

Add ament_package() after the install rule, gated on COMPILING_WITH_AMENT so it's a no-op for catkin and bare-cmake builds.

Sponsored by ARK Electronics

The ament branch sets COMPILING_WITH_AMENT, finds ament_cmake/plotjuggler,
and installs the .so, but never calls ament_package(). Without it, colcon
doesn't emit local_setup.bash and the package never lands on
AMENT_PREFIX_PATH after sourcing install/setup.bash. The catkin branch
already calls catkin_package() on line 52; this restores parity.
@Georacer
Copy link
Copy Markdown
Contributor

The pattern looks familiar, although I don't know the ament workings by heart.
Have you tested this yourself?

@dakejahl
Copy link
Copy Markdown
Contributor Author

Yes — built and sourced locally on a colcon workspace. Before the patch, colcon build installs the .so but doesn't emit local_setup.bash or the share/ament_index/resource_index/packages/plotjuggler_apbin_plugins marker, so the prefix never lands on AMENT_PREFIX_PATH. After adding ament_package() the install tree looks like:

install/plotjuggler_apbin_plugins/
├── lib/plotjuggler_apbin_plugins/libDataAPBin.so
└── share/
    ├── ament_index/resource_index/packages/plotjuggler_apbin_plugins
    ├── plotjuggler_apbin_plugins/local_setup.bash
    └── plotjuggler_apbin_plugins/environment/ament_prefix_path.sh

Sourcing install/setup.bash then prepends the prefix to AMENT_PREFIX_PATH, and PlotJuggler (with PlotJuggler/PlotJuggler#1374) walks it and loads the plugin. Catkin and bare-cmake builds are unaffected since the call is gated on COMPILING_WITH_AMENT.

Copy link
Copy Markdown
Contributor

@Georacer Georacer left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@Georacer Georacer merged commit 10e9694 into ArduPilot:main May 22, 2026
1 check passed
@Georacer
Copy link
Copy Markdown
Contributor

Yes — built and sourced locally on a colcon workspace. Before the patch, colcon build installs the .so but doesn't emit local_setup.bash or the share/ament_index/resource_index/packages/plotjuggler_apbin_plugins marker, so the prefix never lands on AMENT_PREFIX_PATH. After adding ament_package() the install tree looks like:

install/plotjuggler_apbin_plugins/
├── lib/plotjuggler_apbin_plugins/libDataAPBin.so
└── share/
    ├── ament_index/resource_index/packages/plotjuggler_apbin_plugins
    ├── plotjuggler_apbin_plugins/local_setup.bash
    └── plotjuggler_apbin_plugins/environment/ament_prefix_path.sh

Sourcing install/setup.bash then prepends the prefix to AMENT_PREFIX_PATH, and PlotJuggler (with PlotJuggler/PlotJuggler#1374) walks it and loads the plugin. Catkin and bare-cmake builds are unaffected since the call is gated on COMPILING_WITH_AMENT.

I do wonder though: You need to compile PlotJuggler first, in order to compile this AP plugin. What you're describing is fixing a dependency that goes the other way, no?

If I read your linked PJ PR, what you're trying to do is to auto-discover plugins, so this is a runtime dependency, correct?

@dakejahl
Copy link
Copy Markdown
Contributor Author

Right on both counts:

  • Build-time: this plugin depends on PlotJuggler (unchanged — still find_package(plotjuggler)).
  • Runtime: PlotJuggler walks AMENT_PREFIX_PATH to discover plugins. That's the edge #1374 adds, and what this PR enables.

It's really packaging hygiene that's independent of #1374 though — without ament_package() the install isn't a valid ament package at all (no local_setup.bash, no ament_index entry), so e.g. ros2 pkg list doesn't see it. The catkin branch already calls catkin_package() on line 52; this restores parity for the ament branch.

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.

2 participants