Visualizing CMake Dependencies with Graphviz in VS Code

CMake Graphviz Dependency Graph:

1. Generate the dependency graph

Run this inside our build directory:

cmake --graphviz=dependency.dot 

This creates:

  • dependency.dot: the actual graph
  • dep.* files: internal fragments (safe to delete anytime)

2. Install Graphviz (the rendering engine)

We need this in WSL:

sudo apt install graphviz

This provides the dot command that VS Code uses to render the graph.

3. Install Graphviz Preview extension (the viewer)

In VS Code:

  1. Press Ctrl+Shift+X
  2. Search: Graphviz Preview
  3. Click Install in WSL: Ubuntu

This registers the preview command inside WSL.

4. Open the .dot file in VS Code

Just open:

dependency.dot

5. Render the graph

Press:

Ctrl+Shift+P

Type:

Graphviz: Show Preview

Select it -> our.dot file renders as a graph.

That’s the entire working pipeline

  • Generate DOT
  • Install Graphviz
  • Install Graphviz Preview
  • Open DOT
  • Run Graphviz Preview

Leave a Reply

Your email address will not be published. Required fields are marked *