ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to override DEFAULT_RMW_IMPLEMENTATION ?

asked 2022-10-14 09:55:35 -0500

realtime-neil gravatar image

updated 2022-10-14 09:56:28 -0500

When I build things with colcon I see compiler invocations like this:

g++ -DDEFAULT_RMW_IMPLEMENTATION=rmw_fastrtps_cpp ...

I would like to override that preprocessor definition. How do I do that? Something like this has no effect:

export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp

On a Ubuntu 20.04 host with foxy installed, this is the only file that mentions DEFAULT_RMW_IMPLEMENTATION:

$ grep -rl 'DEFAULT_RMW_IMPLEMENTATION' /opt/ros/foxy
/opt/ros/foxy/share/rmw_implementation/cmake/rmw_implementationExport.cmake

Within that file, here is the section that sets the CPPFLAGS:

$ grep -nC2 'DEFAULT_RMW_IMPLEMENTATION' /opt/ros/foxy/share/rmw_implementation/cmake/rmw_implementationExport.cmake
55-
56-set_target_properties(rmw_implementation::rmw_implementation PROPERTIES
57:  INTERFACE_COMPILE_DEFINITIONS "DEFAULT_RMW_IMPLEMENTATION=rmw_fastrtps_cpp"
58-  INTERFACE_LINK_LIBRARIES "rcpputils::rcpputils;rcutils::rcutils;rmw::rmw"
59-)

Here is the package that provides that file:

$ dpkg -S /opt/ros/foxy/share/rmw_implementation/cmake/rmw_implementationExport.cmake
ros-foxy-rmw-implementation: /opt/ros/foxy/share/rmw_implementation/cmake/rmw_implementationExport.cmake

Here is the version of that package at the time of this writing:

$ apt-cache policy ros-foxy-rmw-implementation
ros-foxy-rmw-implementation:
  Installed: 1.0.3-1focal.20220922.205522
  Candidate: 1.0.3-1focal.20220922.205522
  Version table:
 *** 1.0.3-1focal.20220922.205522 500
        500 http://packages.ros.org/ros2/ubuntu focal/main amd64 Packages
        100 /var/lib/dpkg/status

Short of changing the content of this *.cmake file for this package, how do I change the default rmw implementation definition used by the preprocessor?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-10-15 08:53:42 -0500

gvdhoorn gravatar image

AFAIK, you cannot change the default used by ros-foxy-rmw-implementation, as it's hard-coded into the .cmake file you already found.

The way this was implemented (not by me) is that at build time of rmw_implementation, the RMW_IMPLEMENTATION environment variable is checked, and if set, it gets used (here) to populate a target_compile_definitions(... DEFAULT_RMW_IMPLEMENTATION=...) for the rmw_implementation target (which then gets install(... export ...)-ed later on, resulting in the rmw_implementationExport.cmake file you found).

That file is used/loaded by rmw_implementation_cmake (here fi) to determine which value it should return in case the RMW_IMPLEMENTATION environment variable isn't set.

While you probably have your reasons, I must point out the intended way for this to be used is to set the RMW_IMPLEMENTATION environment variable before starting any nodes. Regardless of what the value of DEFAULT_RMW_IMPLEMENTATION is, the RMW corresponding to RMW_IMPLEMENTATION will be loaded (unless the RMW_IMPLEMENTATION_DISABLE_RUNTIME_SELECTION CMake option of rmw_implementation was set when it was built).

Note also that AFAIK, setting RMW_IMPLEMENTATION at build time will not affect anything other than the value returned by CMake functions like get_default_rmw_implementation(..) and the value passed to the compiler. There don't appear to be any other code paths taken or code excluded or included based on that value anywhere in the core packages (in other words: the core ROS 2 packages will behave exactly the same, whether or not you set that variable, as all RMWs are loaded at runtime anyway, including any default, if configured).

Having written that: the direct answer to your question would seem to be: you can change the value which ends up in DEFAULT_RMW_IMPLEMENTATION by setting the RMW_IMPLEMENTATION environment variable during the build of the rmw_implementation package. You might also be able to pass the value to CMake as a --cmake-arg using -DRMW_IMPLEMENTATION=... (this seems to suggest that). This would make it somewhat more manageable, as CMake args can be more easily stored in files.

edit flag offensive delete link more

Comments

1

This was also discussed in Change the default DDS implementation on ROS Discourse, which seems like it answers your question as well. I took the time to add some more detail and link to some of the files involved.

gvdhoorn gravatar image gvdhoorn  ( 2022-10-15 08:54:54 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-10-14 09:55:35 -0500

Seen: 89 times

Last updated: Oct 15 '22