Skip to content

Instantly share code, notes, and snippets.

@robosina
Last active January 5, 2023 14:18
Show Gist options
  • Save robosina/d4dc3acd901f197f8e4f659826387054 to your computer and use it in GitHub Desktop.
Save robosina/d4dc3acd901f197f8e4f659826387054 to your computer and use it in GitHub Desktop.
CMake dependency generator

When you add --graphviz=graph/X.dot to the cmake command, it will generate some .dot files based on the dependencies you have. For unix based systems, you can use the following python code to generate svg for each dot file:

import os


# read all .dot files in a path

def get_dot_files(path):
    dot_files = []
    for file in os.listdir(path):
        if 'dot' in file:
            dot_files.append(file)
    return dot_files


path_2_dot_files = '/cmake-build-debug/graph'

dot_files = get_dot_files(path_2_dot_files)

# generate svg files from dot files
os.chdir(path_2_dot_files)
for dot_file in dot_files:
    os.system('dot -Tsvg ' + dot_file + ' -o ' + dot_file + '.svg')

For more info refer to this link

When running CMake with the --graphviz=foo.dot option, it produces:

  • a foo.dot file, showing all dependencies in the project
  • a foo.dot. file for each target, showing on which other targets it depends
  • a foo.dot..dependers file for each target, showing which other targets depend on it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment