forked from Eyescale/CMake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonGraph.cmake
78 lines (68 loc) · 2.8 KB
/
CommonGraph.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Provides functions to generate dependency graph images using graphviz.
# Used by common_package.
# common_graph_dep(): Write a dependency from->to into global properties
# common_graph(): Write .dot from the global properties and add Name-graph rule
include(CommonTarget)
if(COMMON_GRAPH_DONE)
return()
endif()
set(COMMON_GRAPH_DONE ON)
find_program(DOT_EXECUTABLE dot)
find_program(TRED_EXECUTABLE tred)
common_target(graphs doxygen)
function(common_graph_dep From To Required Source)
string(REPLACE "-" "_" Title ${From})
string(REPLACE "-" "_" Dep ${To})
if(Source)
set(style "style=bold")
elseif(Required)
set(style "style=solid")
else()
set(style "style=dashed")
endif()
set_property(GLOBAL APPEND_STRING PROPERTY ${From}_COMMON_GRAPH
"${Title} [label=\"${From}\"]\n")
if(Required)
set_property(GLOBAL APPEND_STRING PROPERTY ${From}_COMMON_GRAPH
"${Dep} [${style}, label=\"${To}\"]\n"
"\"${Dep}\" -> \"${Title}\" [${style}]\n" )
else()
set_property(GLOBAL APPEND_STRING PROPERTY ${From}_COMMON_GRAPH
"${Dep} [${style}, label=\"${To}\", fontsize=10]\n"
"\"${Dep}\" -> \"${Title}\" [${style}]\n" )
endif()
set_property(GLOBAL APPEND PROPERTY ${From}_COMMON_GRAPH_DEPENDS ${To})
endfunction()
function(common_graph Name)
# collect graph recursively
get_property(graph GLOBAL PROPERTY ${Name}_COMMON_GRAPH)
get_property(graph_depends GLOBAL PROPERTY ${Name}_COMMON_GRAPH_DEPENDS)
list(LENGTH graph_depends nDepends)
while(nDepends)
list(GET graph_depends 0 dep)
list(REMOVE_AT graph_depends 0)
get_property(graph_dep GLOBAL PROPERTY ${dep}_COMMON_GRAPH)
get_property(graph_dep_depends GLOBAL PROPERTY ${dep}_COMMON_GRAPH_DEPENDS)
set(graph "${graph_dep} ${graph}")
list(APPEND graph_dep ${graph_dep_depends})
list(LENGTH graph_depends nDepends)
endwhile()
# write .dot
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${Name}.dot
"strict digraph G { rankdir=\"RL\"; ${graph} }" )
if(DOT_EXECUTABLE AND TRED_EXECUTABLE)
set(dest ${PROJECT_BINARY_DIR}/doc/images)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${Name}_tred.dot
COMMAND ${TRED_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/${Name}.dot >
${CMAKE_CURRENT_BINARY_DIR}/${Name}_tred.dot
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${Name}.dot)
add_custom_command(OUTPUT ${dest}/${Name}.png
COMMAND ${CMAKE_COMMAND} -E make_directory ${dest}
COMMAND ${DOT_EXECUTABLE} -o ${dest}/${Name}.png -Tpng ${CMAKE_CURRENT_BINARY_DIR}/${Name}_tred.dot
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${Name}_tred.dot)
add_custom_target(${Name}-graph DEPENDS ${dest}/${Name}.png)
set_target_properties(${Name}-graph PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON
FOLDER doxygen)
add_dependencies(graphs ${Name}-graph)
endif()
endfunction()