-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnigraphViz.cmake
83 lines (71 loc) · 4.93 KB
/
UnigraphViz.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
79
80
81
82
83
function(_unigraph_append_line_to_dot in_str line indent_key indent_depth out_str)
set(output "${in_str}")
_unigraph_append_indent("${output}" "${indent_key}" ${indent_depth} output)
string(APPEND output "${line}\n")
set(${out_str} "${output}" PARENT_SCOPE)
endfunction(_unigraph_append_line_to_dot)
function(_unigraph_append_legend_block_to_dot in_str block_name label color indent_key indent_depth out_str)
set(output "${in_str}")
_unigraph_append_line_to_dot("${output}" "${block_name} [label=\"${label}\",color=${color}]" "${indent_key}" ${indent_depth} output)
_unigraph_append_line_to_dot("${output}" "{" "${indent_key}" ${indent_depth} output)
math(EXPR indent_depth "${indent_depth} + 1")
_unigraph_append_line_to_dot("${output}" "rank=same;" "${indent_key}" ${indent_depth} output)
math(EXPR indent_depth "${indent_depth} - 1")
_unigraph_append_line_to_dot("${output}" "}" "${indent_key}" ${indent_depth} output)
set(${out_str} "${output}" PARENT_SCOPE)
endfunction(_unigraph_append_legend_block_to_dot)
function(_unigraph_generate_dependency_graph_dot_file)
set(viz_path "${CMAKE_BINARY_DIR}/unigraph_${PROJECT_NAME}_dependency_graph.dot")
_unigraph_message(STATUS "Generating unigraph dependency graph '${viz_path}'")
set(indent " ")
set(graph_content "digraph ${PROJECT_NAME} {\n")
set(executable_color "blue")
set(static_library_color "green")
set(shared_library_color "magenta4")
set(interface_color "gray16")
set(executable_attributes "[color=${executable_color}]")
set(static_library_attributes "[color=${static_library_color}]")
set(shared_library_attributes "[color=${shared_library_color}]")
set(interface_attributes "[color=${interface_color},style=dashed]")
_unigraph_append_line_to_dot("${graph_content}" "subgraph cluster_legend {" "${indent}" 1 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "label=\"Legend\";" "${indent}" 2 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "style=\"solid\";" "${indent}" 2 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "fontsize=10;" "${indent}" 2 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "ranksep=0.01;" "${indent}" 2 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "labelloc=b;" "${indent}" 2 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "node [shape=rectangle,style=filled,fontcolor=white,labelloc=c];" "${indent}" 2 graph_content)
_unigraph_append_legend_block_to_dot("${graph_content}" "ExecutableBlock" "Executable" "${executable_color}" "${indent}" 2 graph_content)
_unigraph_append_legend_block_to_dot("${graph_content}" "StaticLibBlock" "StaticLibrary" "${static_library_color}" "${indent}" 2 graph_content)
_unigraph_append_legend_block_to_dot("${graph_content}" "SharedLibBlock" "SharedLibrary" "${shared_library_color}" "${indent}" 2 graph_content)
_unigraph_append_legend_block_to_dot("${graph_content}" "InterfaceBlock" "Interface" "${interface_color}" "${indent}" 2 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "ExecutableBlock -> StaticLibBlock -> SharedLibBlock -> InterfaceBlock [style=invis];" "${indent}" 2 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "}" "${indent}" 1 graph_content)
_unigraph_append_line_to_dot("${graph_content}" "node [penwidth=2];" "${indent}" 1 graph_content)
get_property(unit_list GLOBAL PROPERTY _UNIGRAPH_UNITS_LIST)
foreach (unit IN LISTS unit_list)
_unigraph_dict_from_list_compatible(unit)
_unigraph_get_value_from_dict(STRING unit "name" unit_name)
_unigraph_get_value_from_dict(STRING unit "type" target_type)
if (target_type STREQUAL "Executable")
set(label_properties "${executable_attributes}")
elseif (target_type STREQUAL "StaticLibrary")
set(label_properties "${static_library_attributes}")
elseif (target_type STREQUAL "SharedLibrary")
set(label_properties "${shared_library_attributes}")
elseif (target_type STREQUAL "Interface")
set(label_properties "${interface_attributes}")
endif ()
_unigraph_append_line_to_dot("${graph_content}" "${unit_name} ${label_properties};" "${indent}" 1 graph_content)
endforeach ()
foreach (unit IN LISTS unit_list)
_unigraph_dict_from_list_compatible(unit)
_unigraph_get_value_from_dict(STRING unit "name" unit_name)
_unigraph_get_value_from_dict(LIST unit "dependencies" target_dependencies)
list(FILTER target_dependencies EXCLUDE REGEX "^\"\"$")
foreach (dependency IN LISTS target_dependencies)
_unigraph_append_line_to_dot("${graph_content}" "\"${unit_name}\" -> \"${dependency}\";" "${indent}" 1 graph_content)
endforeach ()
endforeach ()
string(APPEND graph_content "}")
file(WRITE "${viz_path}" "${graph_content}")
endfunction(_unigraph_generate_dependency_graph_dot_file)