CMake - customize 'make help' output

Viewed 96

I introduced CMake to my project it replaced Make's makefiles. Anyhow I'm not able to find how to customize 'make help' output. This target is created automagically anyhow I would like to add some descriptions for particular targets. It is anyhow possible?

1 Answers

Overwriting help with add_custom_target results in:

See also "/tmp/20/CMakeFiles/CMakeOutput.log".
CMake Error at CMakeLists.txt:5 (add_custom_target):
  The target name "help" is reserved or not valid for certain CMake features,
  such as generator expressions, and may result in undefined behavior.

Instead of overwriting what cmake generates, write your own make wrapper one directory above the cmake one. Like so:

$ cd /your/project
$ ls
_build    CMakeLists.txt    source_file.c    Makefile
$ cmake -S. -B./_build
... configure the project in ./_build builddir ...
$ make
cmake --build _build --target all
<builds the project>
$ make help
This is your help

With Makefile:

all:
    cmake --build _build --target all
configure_for_some_configuration:
    cmake -S. -B_build -DSOME_OPTION=true
help:
    @echo 'This is your help'
.PHONY: help configure_for_some_configuration all

Remember that make is one of several of supported generators. I recommend Ninja for faster builds. Use cmake --build <the build dir> to abstractly build the project independently of the used generator.

Related