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