/src/CMake/Source/cmGraphVizWriter.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <map> |
8 | | #include <memory> |
9 | | #include <set> |
10 | | #include <string> |
11 | | #include <utility> |
12 | | #include <vector> |
13 | | |
14 | | #include "cmGeneratedFileStream.h" |
15 | | #include "cmLinkItem.h" |
16 | | #include "cmLinkItemGraphVisitor.h" |
17 | | |
18 | | namespace cmsys { |
19 | | class RegularExpression; |
20 | | } |
21 | | |
22 | | class cmGlobalGenerator; |
23 | | |
24 | | namespace cm { |
25 | | enum class TargetType; |
26 | | } // namespace cm |
27 | | |
28 | | /** This class implements writing files for graphviz (dot) for graphs |
29 | | * representing the dependencies between the targets in the project. */ |
30 | | class cmGraphVizWriter : public cmLinkItemGraphVisitor |
31 | | { |
32 | | public: |
33 | | cmGraphVizWriter(std::string const& fileName, |
34 | | cmGlobalGenerator const* globalGenerator); |
35 | | ~cmGraphVizWriter() override; |
36 | | |
37 | | void VisitGraph(std::string const& name) override; |
38 | | |
39 | | void OnItem(cmLinkItem const& item) override; |
40 | | |
41 | | void OnDirectLink(cmLinkItem const& depender, cmLinkItem const& dependee, |
42 | | DependencyType dt) override; |
43 | | |
44 | | void OnIndirectLink(cmLinkItem const& depender, |
45 | | cmLinkItem const& dependee) override; |
46 | | |
47 | | void ReadSettings(std::string const& settingsFileName, |
48 | | std::string const& fallbackSettingsFileName); |
49 | | |
50 | | void Write(); |
51 | | |
52 | | private: |
53 | | struct Connection |
54 | | { |
55 | | Connection(cmLinkItem s, cmLinkItem d, std::string scope) |
56 | 0 | : src(std::move(s)) |
57 | 0 | , dst(std::move(d)) |
58 | 0 | , scopeType(std::move(scope)) |
59 | 0 | { |
60 | 0 | } |
61 | | |
62 | | cmLinkItem src; |
63 | | cmLinkItem dst; |
64 | | std::string scopeType; |
65 | | }; |
66 | | using Connections = std::vector<Connection>; |
67 | | using ConnectionsMap = std::map<cmLinkItem, Connections>; |
68 | | |
69 | | void VisitLink(cmLinkItem const& depender, cmLinkItem const& dependee, |
70 | | bool isDirectLink, std::string const& scopeType = ""); |
71 | | |
72 | | void WriteHeader(cmGeneratedFileStream& fs, std::string const& name); |
73 | | |
74 | | void WriteFooter(cmGeneratedFileStream& fs); |
75 | | |
76 | | void WriteLegend(cmGeneratedFileStream& fs); |
77 | | |
78 | | void WriteNode(cmGeneratedFileStream& fs, cmLinkItem const& item); |
79 | | |
80 | | std::unique_ptr<cmGeneratedFileStream> CreateTargetFile( |
81 | | cmLinkItem const& target, std::string const& fileNameSuffix = ""); |
82 | | |
83 | | void WriteConnection(cmGeneratedFileStream& fs, |
84 | | cmLinkItem const& dependerTargetName, |
85 | | cmLinkItem const& dependeeTargetName, |
86 | | std::string const& edgeStyle); |
87 | | |
88 | | void FindAllConnections(ConnectionsMap const& connectionMap, |
89 | | cmLinkItem const& rootItem, |
90 | | Connections& extendedCons, |
91 | | std::set<cmLinkItem>& visitedItems); |
92 | | |
93 | | void FindAllConnections(ConnectionsMap const& connectionMap, |
94 | | cmLinkItem const& rootItem, |
95 | | Connections& extendedCons); |
96 | | |
97 | | template <typename DirFunc> |
98 | | void WritePerTargetConnections(ConnectionsMap const& connections, |
99 | | std::string const& fileNameSuffix = ""); |
100 | | |
101 | | bool ItemExcluded(cmLinkItem const& item); |
102 | | bool ItemNameFilteredOut(std::string const& itemName); |
103 | | bool TargetTypeEnabled(cm::TargetType targetType) const; |
104 | | |
105 | | std::string ItemNameWithAliases(std::string const& itemName) const; |
106 | | |
107 | | static std::string GetEdgeStyle(DependencyType dt); |
108 | | |
109 | | static std::string EscapeForDotFile(std::string const& str); |
110 | | |
111 | | static std::string PathSafeString(std::string const& str); |
112 | | |
113 | | std::string FileName; |
114 | | cmGeneratedFileStream GlobalFileStream; |
115 | | |
116 | | ConnectionsMap PerTargetConnections; |
117 | | ConnectionsMap TargetDependersConnections; |
118 | | |
119 | | std::string GraphName; |
120 | | std::string GraphHeader; |
121 | | std::string GraphNodePrefix; |
122 | | |
123 | | std::vector<cmsys::RegularExpression> TargetsToIgnoreRegex; |
124 | | |
125 | | cmGlobalGenerator const* GlobalGenerator; |
126 | | |
127 | | int NextNodeId = 0; |
128 | | // maps from the actual item names to node names in dot: |
129 | | std::map<std::string, std::string> NodeNames; |
130 | | |
131 | | bool GenerateForExecutables = true; |
132 | | bool GenerateForStaticLibs = true; |
133 | | bool GenerateForSharedLibs = true; |
134 | | bool GenerateForModuleLibs = true; |
135 | | bool GenerateForInterfaceLibs = true; |
136 | | bool GenerateForObjectLibs = true; |
137 | | bool GenerateForUnknownLibs = true; |
138 | | bool GenerateForCustomTargets = false; |
139 | | bool GenerateForExternals = true; |
140 | | bool GeneratePerTarget = true; |
141 | | bool GenerateDependers = true; |
142 | | }; |