CMake dependency graph
CMake
--graphviz
and
graphviz configure preset
can generate GraphViz
dependency graphs
for CMake-supported project code languages including C, C++, and Fortran.
Fortran executables and modules are shown in the directed dependency graph.
Fortran submodule are not shown in the graph.
The
“dot” GraphViz program
converts the .dot files to PNG, SVG, etc.
dot
program is available by installing the “graphviz” program via the package manager.
Generating the dependency graph requires CMake configure and generate. Thus, the compiler and generator needed by the CMake project must be working. The project does not need to be compiled before generating the dependency graph. However, the user should select the same CMake configure options as they would for compiling the project.
Example: h5fortran HDF5 object-oriented Fortran dependency graph is below. SVG vector graphics can be zoomed arbitrarily large in a web browser. The “gfx/” directory is to avoid making files in the source directory.
cmake -B build --graphviz=gfx/block.dot
cd gfx
dot -Tpng -o block.png block.dot
dot -Tsvg -o block.svg block.dot
The “dependers” files show only the nodes depending on a node.
Scripts and Viewing output
CMakeUtils graph.py converts a directory of CMake dot diagrams to SVG or PNG and collects them in an HTML document for easy viewing:
python cmakeutils/graph.py ~/myprog/gfx
To open a web browser from the Terminal:
python -m webbrowser -t file:///$HOME/myprog/gfx/index.html
Note that “file:///” has three slashes and the file path must be absolute.
Related: Dependency graphs are also easily created in Python and Matlab.