Fortran dependency graph with CMake

CMake can generate GraphViz dependency graphs for languages including Fortran. Fortran submodule are not shown in the graph, but executables and modules are shown in the directed dependency graph.


  • the “dot” GraphViz program converts the .dot files to PNG, SVG, etc. This is typically available on Linux, Homebrew, Windows MSYS2, Cygwin, WSL, etc.
  • Since CMake needs to configure and generate, the compiler and generator needed by the CMake project must be working. However the project does not need to be compiled before generating the dependency graph.


h5fortran HDF5 object-oriented Fortran dependency graph is below. SVG can be a useful format since it’s vector and can be zoomed arbitrarily large in a web browser, while PNG is viewable by almost anything.

cmake -B build

dot -Tpng -o foo.png

dot -Tsvg -o foo.svg

h5fortran dependency graph

The “dependers” files show only the nodes depending on a node.