Use ament_cmake_ros_core::ament_ros_defaults instead of setting CMAKE_C_STANDARD or CMAKE_CXX_STANDARD

Open
#432 1 comment 0 reactions 1 assignee View on GitHub

@EkenoSamson is already working on this.

Since Sep 25, 2026.

  • #433 by @EkenoSamson — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
74/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
c, cmake
Domain
build-system

Research direction

Start with rmw/CMakeLists.txt and rmw_security_common/CMakeLists.txt, then check each package.xml for the required ament_cmake_ros_core dependency. Remove manual C and C++ standard settings, add the required find_package call, and link every listed target to ament_cmake_ros_core::ament_ros_defaults. Done means both packages use the shared defaults and exported libraries declare the dependency when required.

Written by the indexing model from the issue text.

Description

good first issue

These packages manually set the C or C++ standard using CMAKE_C_STANDARD or CMAKE_CXX_STANDARD. Instead, we should use ament_cmake_ros_core::ament_ros_defaults. This target automatically sets the C and C++ standard versions to the right version for a given ROS distribution.

To make this change for each package listed below:

  1. Add <buildtool_depend>ament_cmake_ros_core</buildtool_depend> (and <buildtool_export_depend>ament_cmake_ros_core</buildtool_export_depend> if exporting a library target) to the package's package.xml if it is not already present.
  2. Delete the lines in CMakeLists.txt that set CMAKE_C_STANDARD, CMAKE_CXX_STANDARD, or CMAKE_CXX_STANDARD_REQUIRED.
  3. Make sure CMakeLists.txt calls find_package(ament_cmake_ros_core REQUIRED).
  4. Link every target (libraries, executables, and tests) in CMakeLists.txt against ament_cmake_ros_core::ament_ros_defaults using target_link_libraries(). You can use PUBLIC or PRIVATE visibility (prefer PUBLIC by default for libraries because headers likely use the latest standard, PRIVATE for executables/tests, or INTERFACE for INTERFACE libraries). If a library target is exported and uses PUBLIC or INTERFACE, also pass ament_cmake_ros_core to ament_export_dependencies().
Example

In package.xml:

<buildtool_depend>ament_cmake_ros_core</buildtool_depend>
<buildtool_export_depend>ament_cmake_ros_core</buildtool_export_depend>

Before (CMakeLists.txt):

# Default to C++20
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 20)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

find_package(ament_cmake_ros REQUIRED)

add_library(my_library src/my_library.cpp)
target_link_libraries(my_library PUBLIC
  rcutils::rcutils
)

After (CMakeLists.txt):

find_package(ament_cmake_ros REQUIRED)
find_package(ament_cmake_ros_core REQUIRED)

add_library(my_library src/my_library.cpp)
target_link_libraries(my_library PUBLIC
  ament_cmake_ros_core::ament_ros_defaults
  rcutils::rcutils
)
Files to modify
  • rmw/CMakeLists.txt
  • rmw_security_common/CMakeLists.txt
Dominant language
C
Stars
121
Forks
89
Avg merge
17h 40m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ros2/rmw

All issues in ros2/rmw

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.