Skip to content

Conversation

@cottsay
Copy link
Contributor

@cottsay cottsay commented Oct 9, 2025

There is a CMake mode which can be used to extract basic compile and linker flags as would be produced by a call to find_package(). Existing ament_cmake code always assumes that we're being invoked under a PROJECT role. This change skips certain project-specific parts of ament_cmake_core and ament_cmake_test which shouldn't be run unless we're actually configuring a CMakeLists.txt project.

The smoke tests added by this change validate that the "extra" CMake functionality provided by these packages continues to be loadable outside of a project context. It does not validate that the defined functions can actually be used, but will serve as a validation that features like CMake --find-package should work.

Docs: https://cmake.org/cmake/help/latest/manual/cmake.1.html#find-package-tool-mode

Expected:

$ cmake --find-package -DNAME=rmw -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=COMPILE
-I/opt/ros/rolling/include/rcutils -I/opt/ros/rolling/include/rosidl_dynamic_typesupport -I/opt/ros/rolling/include/rosidl_runtime_c -I/opt/ros/rolling/include/rmw

Actual:

$ cmake --find-package -DNAME=rmw -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=COMPILE
CMake Error: Generator implementation error, all generators must specify this->FindMakeProgramFile
CMake Error at /opt/ros/rolling/share/ament_cmake_core/cmake/ament_cmake_package_templates-extras.cmake:17 (message):
  ament_cmake_package_templates: target 'Python3::Interpreter' must exist
Call Stack (most recent call first):
  /opt/ros/rolling/share/ament_cmake_core/cmake/ament_cmake_coreConfig.cmake:41 (include)
  /opt/ros/rolling/share/rmw/cmake/ament_cmake_export_dependencies-extras.cmake:15 (find_package)
  /opt/ros/rolling/share/rmw/cmake/rmwConfig.cmake:41 (include)
  /usr/share/cmake/Modules/CMakeFindPackageMode.cmake:182 (find_package)


rmw not found.
CMake Error: Run 'cmake --help' for all supported options.

Note

This PR changes a bunch of indentation, so it's best to view the changes with whitespace ignored.

@cottsay cottsay requested a review from sloretz October 9, 2025 20:36
@cottsay cottsay self-assigned this Oct 9, 2025
@cottsay cottsay added the bug Something isn't working label Oct 9, 2025
@cottsay cottsay force-pushed the cottsay/cmake-find-package-mode branch from 15b4895 to e39caf7 Compare October 9, 2025 21:01
There is a CMake mode which can be used to extract basic compile and
linker flags as would be produced by a call to find_package(). Existing
ament_cmake code always assumes that we're being invoked under a
"PROJECT" role. This change skips certain project-specific parts of
ament_cmake_core and ament_cmake_test which shouldn't be run unless
we're actually configuring a CMakeLists.txt project.

The smoke tests added by this change validate that the "extra" CMake
functionality provided by these packages continues to be loadable
outside of a project context. It does not validate that the defined
functions can actually be used, but will serve as a validation that
features like CMake --find-package should work.

Signed-off-by: Scott K Logan <[email protected]>
@cottsay cottsay force-pushed the cottsay/cmake-find-package-mode branch from e39caf7 to 58d4e94 Compare October 10, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant