We would like to learn how to generate documentation for targets

Hello,
We would like to document selected targets in our cmake file.
For example, the envisioned usage might look something like this:

mkdir build
cd build
cmake ..
make doc

This will then print out nicely formatted documentation, for example:

all       Make everything
clean  Clean up
foo      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
bar      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
blah    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
etc etc

Is there a way to do this, or something similar?
There are numerous targets, and we would like to make it easier for the user, without having to maintain a separate document describing all the targets.
We understand that make help lists all of the targets, but this is not what we are looking for.
Thank you for your time.

Not really, no. The best possible is to have a target that outputs the content you want. It may need to adapt for different generator behavior too. I would recommend just writing docs in README.md or other build documentation.

1 Like

Thanks for the response Ben.

FWIW, my development workflow is usually to use CMake as the build system, and I like to also create a makefile to use just as a task manager (it will invoke CMake configure & build). I usually create a help goal that lists all the Make goals (and there’s usually one per major CMake target), and the output looks a lot like what you posted in your example.

Here is an example of such a Makefile.

1 Like