Helping colleagues familiar with make come over to cmake

I’ve converted a large production codebase from make to cmake. It is structured as a top level CMakeLists.txt that does add_subdirectory() for the numerous subprojects.

Individual projects can be built like this per normal cmake with presets:

~/project$ cmake --build --preset linux-debug --target subproject

Colleagues familiar with make would like to be able to build things like they did with make:

~/project$ cd subproject
~/project/subproject$ make

AFAIK there is not a way for cmake CLI to support this style of invocation. But asking here in case anyone has some ideas.

Bonus question! Also in the spirit of helping my colleagues come over to cmake – is there a more minimal cmake CLI to do the configure and build steps:

~/project$ cmake --preset linux-debug
~/project$ cmake --build --preset linux-debug

Question 1: Aside from doing exactly what you’re doing, I don’t personally know another way. Perhaps specific generators like Unix Makefiles might give you some extra options, but you lose the performance and portability improvements of being able to use other generators like Ninja, which is pretty fast. There’s always, I suppose, the possiblility of creating a CMake project for each subproject and then using the ExternalProject method, although having never used it personally I can’t give any specifics on how to use it for your use-case.

Question 2: If you have a small closed set of standard build workflows (e.g. configure-release/build/install vs configure-debug/build/test/install or whatever), you could add workflows into your CMakePresets file and then invoke cmake like cmake --workflow <workflow>. That does mean that re-running e.g. the install step will require re-running all the steps, so tests will be unskippable unless you make another workflow that specifically skips tests. Also, workflows seem to be meant for stuff like CI/CD and are therefore highly restrictive, so you can’t mix-and-match: you can’t have the release-build preset in a workflow whose configure is the debug-configure, and you also can’t have a single build preset that works for both the release-workflow and debug-workflow, or whatever you want to call them.

1 Like