1

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.

To reproduce this:

  1. Clone the above repo.
  2. Navigate to the catkin_tutorials/create_package_pubsub/catkin_ws
  3. Modify the src/CMakeLists.txt with something that won't build.
  4. Build with catkin build

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.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
  • Cannot reproduce this issue. Could you add the parameters you used to run cmake with to do the initial configuration (as well as the working directory in case you use relative paths)? – fabian May 26 '21 at 07:11
  • BTW: Assuming by "subprojects" you mean directories containing `CMakeLists.txt` files other than the toplevel one that are added via `add_subdirectory`: `set(CMAKE_CXX_STANDARD 17)` should do the trick as long as it's done before `add_subdirectory`; every directory has it's own variable scope but a read access falls back to the scope of the "parent directory" (refering to the relationship established by `add_subdirectory` here), if the variable is not present in the scope of the current dir. Target properties have higher priority though and subdirectories can overwrite the value. – fabian May 26 '21 at 07:18
  • @fabian I added some reproduction steps. – Fantastic Mr Fox May 26 '21 at 07:25

1 Answers1

0

My understanding from the docs is that the src/CMakeLists.txt is intended to be a symlink to catkin/cmake/toplevel.cmake in the ROS installation and not be edited. It is only used if CMake is driving the legacy build workflow.

The new workflow, which catkin build implements, ignores this file specifically to isolate the builds and prevent cross-talk from one package setting CMake cache variables another reads.

So that answers part (1), but regrettably I am not experienced enough with catkin to know what the best practice is to store common configuration. I do know that there is a --cmake-args flag to catkin build that you could use in tandem with the CMAKE_PROJECT_INCLUDE variable to inject a CMake file containing your settings.

For C++17 specifically, this would look like:

$ catkin build --cmake-args -DCMAKE_CXX_STANDARD=17

See the docs for this here: https://catkin-tools.readthedocs.io/en/latest/verbs/catkin_build.html#temporarily-changing-build-flags

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86