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

ROS top level CMakelists.txt is not used, how to give cmake defaults for all sub projects?

asked 2021-05-25 20:23:11 -0500

FantasticMrFox gravatar image

updated 2022-01-22 16:16:15 -0500

Evgeny gravatar image

I have a workspace set out as in the ROS REP 128 aka:

catkin_ws
   src
      CMakeLists.txt // < 1.
      project_1
          CMakeLists.txt
      project_2
          CMakeLists.txt
      ...

In fact you can reproduce this using just the catkin tutorials here. The top level CMakeLists.txt (1. in the example above) appears to not be sourced. I can tell this because i added the line, weifnbwefn to the end of it expecting a cmake error (on a clean build) but got none. So this leads to 2 questions:

  1. Why is this file not used?
  2. How can i add default cmake items for all of my sub projects? for eg. if i wanted to add set(CMAKE_CXX_STANDARD 17) for every sub-project?

For 2. , i know that i can add additional cmake args to my build profile in .catkin_tools but for anything more complex then a couple of arguments, this would not be scaleable.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-05-26 03:35:31 -0500

gvdhoorn gravatar image

updated 2021-05-26 05:27:10 -0500

i know that i can add additional cmake args to my build profile in .catkin_tools

you don't explicitly mention which tool you are using to build your workspace, and I believe that's important here.

The "catkin tutorials" you mention (should that link point to wiki/ROS/Tutorials/CreatingPackage instead?) specifically use catkin_make.

You appear to use catkin_tools (or at least, you mention its support for profiles).

Those don't work exactly the same, and one difference is the fact that "top-level CMakeLists.txt" is not used by catkin_tools, as it builds every package in your workspace on its own (terminology used is "in isolation"), just as you would when you mkdir build && cmake .. && ... && make install DESTDIR=... each project in the correct order.

How can i add default cmake items for all of my sub projects? for eg. if i wanted to add set(CMAKE_CXX_STANDARD 17) for every sub-project? [..] i know that i can add additional cmake args to my build profile in .catkin_tools but for anything more complex then a couple of arguments, this would not be scaleable.

I'm a bit confused as to how adding those flags to a .yaml file used by your build tool is less scalable than editing a CMakeLists.txt (which would contain the same information). And for the specific example you show, the most efficient would be passing -DCMAKE_CXX_STANDARD=17 to the --cmake-args option of catkin_tools, which seems like something well suited for using catkin_tools' configuration profiles.

But to answer your question: catkin_tools doesn't have any convenience built-in for setting build arguments per-package right now. Per-workspace is supported, exactly through the use of the configurations. Passing --cmake-args -DCMAKE_... and/or adding those to your profile would be what is supported.

Colcon however does support this: see Colcon: Configuration. Specifically the colcon.pkg and .meta files sections. Using a .pkg file you can configure build flags to always pass to whichever tool is used to build the package automatically (ie: CMake or something else). Example file (from here):

{
    "name": "microxrcedds_client",
    "type": "cmake",
    "dependencies":[
        "microcdr"
    ],
    "cmake-args":[
        "-DUCLIENT_ISOLATED_INSTALL=OFF",
        "-DUCLIENT_SUPERBUILD=OFF"
    ]
}

Note the cmake-args key there.

Colcon will automatically discover these files and apply the settings it finds in them, per-package.

This comes with a trade-off again, as for your copy of a package, you may want to change some flags, but not necessarily commit those.

That's where .meta files come in (see again the Colcon: Configuration page I linked above): they essentially perform a similar function to the configurations supported by catkin_tools (so per-workspace configuration), but they also support the same content as the .pkg files, so it's possible to specify configuration for a subset of the packages in your workspace, including CMake flags, without having to touch any files in the package's directory.

Colcon can be used to build ROS 1 packages as well, but officially it's not completely supported (last time I checked).

edit flag offensive delete link more

Comments

Very good answer, so ues i mean catkin_tools, but i am often confused by which tutorial applies to each. For the yaml configuration, can you import to the yaml files for all of the different build types?

FantasticMrFox gravatar image FantasticMrFox  ( 2021-06-07 01:25:48 -0500 )edit

i am often confused by which tutorial applies to each.

if the tutorial asks you to execute catkin_make, it's not catkin_tools. If the tutorial asks you to execute catkin build, it's not catkin_make.

For the yaml configuration, can you import to the yaml files for all of the different build types?

I'm not sure I understand what you mean by this.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-07 03:30:31 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-05-25 20:23:11 -0500

Seen: 558 times

Last updated: May 26 '21