Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/KexiGenerateDependencyGraph.cmake
- This file was added.
1 | # Generates dependency graphs for current project | ||||
---|---|---|---|---|---|
2 | # | ||||
3 | # Copyright (C) 2017 Jarosław Staniek <staniek@kde.org> | ||||
4 | # | ||||
5 | # Redistribution and use is allowed according to the terms of the BSD license. | ||||
6 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||||
7 | | ||||
8 | if(TARGET generate_dependency_graph) | ||||
9 | return() | ||||
10 | endif() | ||||
11 | | ||||
12 | find_package(Doxygen) | ||||
13 | | ||||
14 | if(NOT DOXYGEN_DOT_EXECUTABLE) | ||||
15 | message(STATUS "Graphviz dot tool not found, won't generate dependency graphs") | ||||
16 | return() | ||||
17 | endif() | ||||
18 | | ||||
19 | set(_graph_dir ${CMAKE_BINARY_DIR}/dependencies) | ||||
20 | set(_dot_file ${_graph_dir}/graph.dot) | ||||
21 | set(_image_file "dependency-graph-${CMAKE_PROJECT_NAME}.png") | ||||
22 | | ||||
23 | simple_option(${PROJECT_NAME_UPPER}_DEPENDENCY_GRAPH_INCLUDE_KEXI_FRAMEWORKS "Include Kexi frameworks in the dependency graph" ON) | ||||
24 | simple_option(${PROJECT_NAME_UPPER}_DEPENDENCY_GRAPH_INCLUDE_ALL_LIBS "Include all libs in the dependency graph" OFF) | ||||
25 | | ||||
26 | configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeGraphVizOptions.cmake.in | ||||
27 | ${CMAKE_BINARY_DIR}/CMakeGraphVizOptions.cmake) | ||||
28 | | ||||
29 | add_custom_target(generate_dependency_graph) | ||||
30 | | ||||
31 | add_custom_command( | ||||
32 | TARGET generate_dependency_graph POST_BUILD | ||||
33 | COMMAND ${CMAKE_COMMAND} -E make_directory ${_graph_dir} | ||||
34 | COMMAND cmake --graphviz=${_dot_file} . | ||||
35 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | ||||
36 | COMMENT "Generating dependency graph ${_graph_dir}/${_dot_file} for " | ||||
37 | "${CMAKE_PROJECT_NAME} project" | ||||
38 | ) | ||||
39 | add_custom_command( | ||||
40 | TARGET generate_dependency_graph POST_BUILD | ||||
41 | COMMAND ${DOXYGEN_DOT_EXECUTABLE} ${_dot_file} -T png > "${_graph_dir}/${_image_file}" | ||||
42 | WORKING_DIRECTORY ${_graph_dir} | ||||
43 | COMMENT "Generating dependency graph image ${_graph_dir}/${_image_file} for " | ||||
44 | "${CMAKE_PROJECT_NAME} project" | ||||
45 | ) | ||||
46 | | ||||
47 | add_custom_target(show_dependency_graph) | ||||
48 | if(WIN32) | ||||
49 | set(_open_command start) | ||||
50 | else() | ||||
51 | set(_open_command xdg-open) | ||||
52 | endif() | ||||
53 | add_custom_command( | ||||
54 | TARGET show_dependency_graph POST_BUILD | ||||
55 | COMMAND ${_open_command} "${_graph_dir}/${_image_file}" | ||||
56 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | ||||
57 | COMMENT "Show dependency graph image for ${CMAKE_PROJECT_NAME} project" | ||||
58 | ) | ||||
59 | | ||||
60 | unset(_dot_file) | ||||
61 | unset(_image_file) | ||||
62 | unset(_graph_dir) | ||||
63 | unset(_open_command) |