Add setup to generate graphs for cmake target dependencies (#7383)
authorGereon Kremer <nafur42@gmail.com>
Thu, 21 Oct 2021 12:10:20 +0000 (05:10 -0700)
committerGitHub <noreply@github.com>
Thu, 21 Oct 2021 12:10:20 +0000 (12:10 +0000)
This adds the target `target-graphs` that generated graphs of cmake dependencies based on `cmake --graphviz`. It is a nice to tool to debug the cmake setup in some cases.

CMakeLists.txt
cmake/CMakeGraphVizOptions.cmake.in [new file with mode: 0644]
cmake/target-graphs.cmake [new file with mode: 0644]

index 3d173c8453b252048b0fcade74e29283ed5684bf..2f6fa434e67ed3161b2c5885edc61cc107cf1681 100644 (file)
@@ -488,6 +488,8 @@ endif()
 
 add_subdirectory(test)
 
+include(target-graphs)
+
 #-----------------------------------------------------------------------------#
 # Package configuration
 #
diff --git a/cmake/CMakeGraphVizOptions.cmake.in b/cmake/CMakeGraphVizOptions.cmake.in
new file mode 100644 (file)
index 0000000..d3be598
--- /dev/null
@@ -0,0 +1,28 @@
+###############################################################################
+# Top contributors (to current version):
+#   Gereon Kremer
+#
+# This file is part of the cvc5 project.
+#
+# Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
+# in the top-level source directory and their institutional affiliations.
+# All rights reserved.  See the file COPYING in the top-level source
+# directory for licensing information.
+# #############################################################################
+# Configuration file for the generation of cmake dependency graphs of cmake
+# targets.
+##
+
+set(CTX "@CMAKE_BINARY_DIR@/src/context/CMakeFiles/cvc5base.dir/")
+set(BASE "@CMAKE_BINARY_DIR@/src/base/CMakeFiles/cvc5base.dir/")
+
+# ignore targets that do not actually help the understanding or are (usually)
+# not interesting: tests and object files.
+set(GRAPHVIZ_IGNORE_TARGETS 
+    main-test
+    @APITESTS@
+    ${CTX}context.cpp.o ${CTX}context_mm.cpp.o
+    ${BASE}check.cpp.o ${BASE}configuration.cpp.o ${BASE}exception.cpp.o
+    ${BASE}git_versioninfo.cpp.o ${BASE}listener.cpp.o ${BASE}output.cpp.o
+)
+set(GRAPHVIZ_GENERATE_DEPENDERS FALSE)
\ No newline at end of file
diff --git a/cmake/target-graphs.cmake b/cmake/target-graphs.cmake
new file mode 100644 (file)
index 0000000..ad1023c
--- /dev/null
@@ -0,0 +1,32 @@
+###############################################################################
+# Top contributors (to current version):
+#   Gereon Kremer
+#
+# This file is part of the cvc5 project.
+#
+# Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
+# in the top-level source directory and their institutional affiliations.
+# All rights reserved.  See the file COPYING in the top-level source
+# directory for licensing information.
+# #############################################################################
+# Provides cmake target target-graphs with generates (png) dependency graphs
+# to visualize the interdependencies of all cmake targets.
+##
+
+get_target_property(APITESTS build-apitests MANUALLY_ADDED_DEPENDENCIES)
+string(REPLACE ";" " " APITESTS "${APITESTS}")
+
+configure_file(
+    cmake/CMakeGraphVizOptions.cmake.in 
+    ${CMAKE_BINARY_DIR}/CMakeGraphVizOptions.cmake
+    @ONLY
+)
+
+add_custom_target(target-graphs
+    COMMAND
+        ${CMAKE_COMMAND} --graphviz=target-graphs/graph.dot ${CMAKE_SOURCE_DIR}
+    COMMAND
+        find target-graphs/ -iname "graph.dot*" -and \! -iname "*.png"
+        -exec dot -Tpng -O {} +
+    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+)