Creating dependency graphs of CMake targets
In the previous sections, we have been covering the documentation and graphing of the software code, but in a large project, we may also need to document and visualize the CMake code as well. The relations between CMake targets may be complex, and this may render keeping track of all the dependencies hard. Fortunately, CMake can again help with this by providing a graph showing all dependencies between targets. By calling cmake --graphviz=my-project.dot /path/to/build/dir
, CMake will create files in the DOT language that contain how targets depend on each other.
The DOT language is a description language for graphs and can be interpreted by a multitude of programs, the most famous one being the freely available Graphviz. DOT files can be converted to images or even Portable Document Format (PDF) files using the dot
command-line utility from Graphviz, like this: dot -Tpng filename.dot -o out.png
.
Running these commands for the example...