
But as a special case, you can use add_custom_target(ALL) to create a new target attached to the “all” target: add_custom_target( How about using add_dependencies()? No, you can’t use that with any of the built in targets. So we need to add a dependency between docs/doxygen.stamp and the “all” target. Nothing depends on the documentation, so it isn’t built.

But actually, here’s what to expect: nothing! If you build this, you get no output. We have to create a ‘stamp’ file because Doxygen generates lots of different files, and we can’t really tell CMake what to expect. "Generating API documentation with Doxygen" You may live to regret ever letting it in. This is where add_custom_command() enters your life. If your project is a good one then maybe you use a documentation tool like GTK-Doc or Doxygen to generate documentation from the code. There are also “install” and “test” targets built in ( but no “clean” target). What is “all”, in the dependency graph to the left? It’s a built in target, and it’s the default target. When you run CMake, both of them get built. You have a library, and a program that depends on it. This is CMake at its simplest (and best). Here is a hopefully complete list of things you might want to do in CMake that involve custom commands and custom targets depending on each other, and some explainations as to why things don’t work the way that you might expect. What makes it so hard is that there’s not one limitation, but several. But files aren’t targets and have all sorts of exciting limitations to make you forget everything you ever new about dependency management.

If you want to generate some kind of file at build time, in some manner other than compiling C or C++ code, then you need to use a custom command to generate the file. If you’ve tried do anything non-trivial in CMake using the add_custom_command() command, you may have got stuck in this horrible swamp of confusion.

Unfortunately, not everything is a target though! As I said in my last post about CMake, targets are everything in CMake.
