I would like to add more information about targets in the graph that is built with the graphviz option of CMake:
cmake -S . --graphviz=targets.dot
The targets.dot graph shows only target names and their types, and how they depend on each other. I would like to add more information about the targets, hidden in Graphviz tooltip or maybe with some embedded URLs. For example, the information could include the source files of the targets, which CMakeLists.txt declared a target, what are the INSTALL parameters, target_compile_options and features, etc.
As far as I understand, currently there is no option in CMake CMakeGraphVizOptions to add such information to the dot graph.
I was wondering whether there is already a way to combine such information in a graph of target dependencies? Or are there existing developments towards that?
For example, CMake could dump the information about the project targets in a serialized format (a json like compile_commands.json), so that a dot graph could be built out of it with a third party tool. Or maybe there could be a tool that generates such a graph file from the build directory and CMakeFiles etc. (I am not sure if there is a way to get all the information from parsing CMakeFiles. There are tools that turn Makefiles to graphs. That’s probably not the right way to go either.)
If there is currently no clear way to do it, I would like to propose such a feature for development. I could try to put together a draft merge request with the idea.
You might want to check out CMake’s file API. Quite a lot of information about the code model is available through that mechanism, and that should be the canonical place to look for such detailed information, not the graphviz output.
So, I started a Python project to explore how things work and what graphs could be useful. It looks like file-api contains everything Thanks!
Running it on CMake itself, I get the following graph (the SVG does not get uploaded correctly):
It just reproduces cmake --graphviz and adds the source paths in the tooltips.
When testing it on cmake_template, I did not see some expected INTERFACE targets in the reply to the codemodel-v2 query. For example, the INTERFACE targets myproject_options and myproject_warnings (declared in ProjectOptions.cmake) that contain the project-wide settings for the C++ compiler, which are set with target_compile_features etc commands. Probably, I am missing something. But I thought these two INTERFACE targets are always enabled and always linked to all other targets in the project.
They do show up in the codemodel reply jsons. In the directory-.-Release-…json, under “installers”, it has one with “type”: “export” and a list of “exportTargets” with ids “intro…”, “myproject_options…” and “myproject_warnings”. But that’s the only place that mentions these targets.