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.
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}")
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With