CMake codemodel graphs

When getting up to speed with a CMake project, you want to get some decent overview of the build targets without perusing the source code. It should show which source files are built into the targets, the compilation definitions, how the targets depend on each other, etc. This project is a prototype of such a tool. It is a Python project with a couple modules and cmake_graph CLI. The source code on github.

CMake does comes with a graphing option:

cmake -S . --graphviz=targets.dot

But it is not intended for serious use. To get more info, CMake team advises to use their file API.

My original goal was to add Graphviz tooltips with the info on the source files that go into the target, where the target is defined in CMakeLists.txt, etc. The cmake_graph tool makes .dot and .svg files with that information. And it also handles clusters of dense dependensies in the project.

For example, the structure of the CMake project (zoom in for tooltips):

Browser doesn't support object tag for SVG

The large circle represents a cluster of dense dependencies, where 16 targets are used by 17 other targets in the project.

The SVG was made like this:

git clone \
  git@gitlab.kitware.com:cmake/cmake.git \
  cmake_src
cd cmake_src
cmake_graph setup -B build/
cmake -S . -B build/
...
cmake_graph graph -B build/ --skip-types UTILITY
ls targetgraph-.svg
Related posts:

Clustering CMake graphs