Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake graphviz auto generated

I know the common way to generate a CMake project dependencies graph by the CLI:

cmake --graphviz=[file]

But is there a way for it to be autogenerated by just setting a flag or command within a CMakeList? The idea is for the CMakeLists.txt itself to trigger the graph generation, and not the user through command line.

like image 701
Javier Calzado Avatar asked Mar 03 '17 11:03

Javier Calzado


2 Answers

You could call CMake inside your script again, e.g. like:

add_custom_target(graphviz ALL
                  "${CMAKE_COMMAND}" "--graphviz=foo" .
                  WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
like image 68
languitar Avatar answered Sep 27 '22 21:09

languitar


Not only can you create a CMake custom target for running Graphviz, but you can take it a step further, and have it also generate the image files for you using Dot:

add_custom_target(graphviz ALL
    COMMAND ${CMAKE_COMMAND} "--graphviz=foo.dot" .
    COMMAND dot -Tpng foo.dot -o foo.png
    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)

This way, the custom target runs the second command dot -Tpng foo.dot -o foo.png as well. You can output the image files anywhere on your system by pre-pending foo.png with a path of your choosing.

like image 43
Kevin Avatar answered Sep 27 '22 22:09

Kevin