CMake has the ability to produce a Graphviz dot file for a project that displays the dependencies of each target in the project. Unfortunately the generated output file cannot be customized in any way. For bigger projects this normally results in a really huge graph that doesn’t help very much because of the many links. Especially the fact that external libraries are displayed in the graph can be very annoying.
To solve this problem I wrote a simple post-processor script in Python that takes the dot fileĀ generated by CMake and filters it by simple text matching on the nodes.
Usage
First you must tell CMake to generate a dot file with the project dependencies. This is done with the –graphviz=[file] option. The cleaner script then works on this dot file as described in the program help:
|
1 2 3 4 5 6 7 8 |
Usage: graphviz-cleaner.py [options] <input dot source> Options: -h, --help show this help message and exit -f FILE, --file=FILE write processed dot graph source to FILE (default = cleaned.dot) -u, --removeusrlib remove targets located in /usr/lib -p PATTERNS, --pattern=PATTERNS adds an additional pattern to remove nodes with |
Example
Here is a short example of what can be done with this simple tool: The original dependency graph for digiKam looks like this:
As you can easily see, this is pretty useless.
This graph can be cleaned to:
This is much more useful to analyze the dependencies of the various project parts. This graph was generated with:
|
1 2 |
$ ./graphviz-cleaner.py -u -p KDE -p pthread -p imageplugin -f digiKam_cleaned.dot dependencies.dot $ dot digiKam_cleaned.dot -Tpng -o digiKam_cleaned.png |
Getting the Code
The source code is available in my svn:
https://ssl.semipol.de/svn/projects/cmake-graphviz-cleaner/
Log in with user name anonymous and password anonymous.
License
The source code is released under the terms of the GNU General Public License (GPL), version 2.


