/src/CMake/Source/cmFindCommon.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 "cmPathLabel.h" |
15 | | #include "cmSearchPath.h" |
16 | | #include "cmWindowsRegistry.h" |
17 | | |
18 | | class cmConfigureLog; |
19 | | class cmFindCommonDebugState; |
20 | | class cmExecutionStatus; |
21 | | class cmMakefile; |
22 | | |
23 | | /** \class cmFindCommon |
24 | | * \brief Base class for FIND_XXX implementations. |
25 | | * |
26 | | * cmFindCommon is a parent class for cmFindBase, |
27 | | * cmFindProgramCommand, cmFindPathCommand, cmFindLibraryCommand, |
28 | | * cmFindFileCommand, and cmFindPackageCommand. |
29 | | */ |
30 | | class cmFindCommon |
31 | | { |
32 | | public: |
33 | | cmFindCommon(cmExecutionStatus& status); |
34 | | virtual ~cmFindCommon(); |
35 | | |
36 | | void SetError(std::string const& e); |
37 | | |
38 | | bool DebugModeEnabled() const; |
39 | | |
40 | | protected: |
41 | | friend class cmSearchPath; |
42 | | friend class cmFindBaseDebugState; |
43 | | friend class cmFindCommonDebugState; |
44 | | friend class cmFindPackageDebugState; |
45 | | |
46 | | /** Used to define groups of path labels */ |
47 | | class PathGroup : public cmPathLabel |
48 | | { |
49 | | protected: |
50 | | PathGroup(); |
51 | | |
52 | | public: |
53 | | PathGroup(std::string const& label) |
54 | 4 | : cmPathLabel(label) |
55 | 4 | { |
56 | 4 | } |
57 | | static PathGroup All; |
58 | | }; |
59 | | |
60 | | /* Individual path types */ |
61 | | class PathLabel : public cmPathLabel |
62 | | { |
63 | | protected: |
64 | | PathLabel(); |
65 | | |
66 | | public: |
67 | | PathLabel(std::string const& label) |
68 | 44 | : cmPathLabel(label) |
69 | 44 | { |
70 | 44 | } |
71 | | static PathLabel PackageRoot; |
72 | | static PathLabel CMake; |
73 | | static PathLabel CMakeEnvironment; |
74 | | static PathLabel Hints; |
75 | | static PathLabel SystemEnvironment; |
76 | | static PathLabel CMakeSystem; |
77 | | static PathLabel Guess; |
78 | | }; |
79 | | |
80 | | enum RootPathMode |
81 | | { |
82 | | RootPathModeNever, |
83 | | RootPathModeOnly, |
84 | | RootPathModeBoth |
85 | | }; |
86 | | |
87 | | virtual bool IsFound() const = 0; |
88 | | virtual bool IsDefined() const = 0; |
89 | | |
90 | | /** Construct the various path groups and labels */ |
91 | | void InitializeSearchPathGroups(); |
92 | | |
93 | | /** Place a set of search paths under the search roots. */ |
94 | | void RerootPaths(std::vector<std::string>& paths, |
95 | | std::string* debugBuffer = nullptr); |
96 | | |
97 | | /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PATH variables. */ |
98 | | void GetIgnoredPaths(std::vector<std::string>& ignore); |
99 | | void GetIgnoredPaths(std::set<std::string>& ignore); |
100 | | |
101 | | /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PREFIX_PATH variables. */ |
102 | | void GetIgnoredPrefixPaths(std::vector<std::string>& ignore); |
103 | | void GetIgnoredPrefixPaths(std::set<std::string>& ignore); |
104 | | |
105 | | /** Compute final search path list (reroot + trailing slash). */ |
106 | | enum class IgnorePaths |
107 | | { |
108 | | No, |
109 | | Yes, |
110 | | }; |
111 | | void ComputeFinalPaths(IgnorePaths ignorePaths, |
112 | | std::string* debugBuffer = nullptr); |
113 | | |
114 | | /** Compute the current default root path mode. */ |
115 | | void SelectDefaultRootPathMode(); |
116 | | |
117 | | /** Compute the current default bundle/framework search policy. */ |
118 | | void SelectDefaultMacMode(); |
119 | | |
120 | | /** Compute the current default search modes based on global variables. */ |
121 | | void SelectDefaultSearchModes(); |
122 | | |
123 | | /** The `InitialPass` functions of the child classes should set |
124 | | this->FullDebugMode to the result of these. */ |
125 | | bool ComputeIfDebugModeWanted(); |
126 | | bool ComputeIfDebugModeWanted(std::string const& var); |
127 | | |
128 | | /** The `InitialPass` functions of the child classes should not initialize |
129 | | `DebugState` if there is not a debug mode wanted and these return `true`. |
130 | | */ |
131 | | bool ComputeIfImplicitDebugModeSuppressed(); |
132 | | |
133 | | // Path arguments prior to path manipulation routines |
134 | | std::vector<std::string> UserHintsArgs; |
135 | | std::vector<std::string> UserGuessArgs; |
136 | | |
137 | | std::string CMakePathName; |
138 | | RootPathMode FindRootPathMode; |
139 | | |
140 | | bool CheckCommonArgument(std::string const& arg); |
141 | | void AddPathSuffix(std::string const& arg); |
142 | | |
143 | | void DebugMessage(std::string const& msg) const; |
144 | | bool FullDebugMode; |
145 | | std::unique_ptr<cmFindCommonDebugState> DebugState; |
146 | | bool NoDefaultPath; |
147 | | bool NoPackageRootPath; |
148 | | bool NoCMakePath; |
149 | | bool NoCMakeEnvironmentPath; |
150 | | bool NoSystemEnvironmentPath; |
151 | | bool NoCMakeSystemPath; |
152 | | bool NoCMakeInstallPath; |
153 | | cmWindowsRegistry::View RegistryView = cmWindowsRegistry::View::Target; |
154 | | |
155 | | std::vector<std::string> SearchPathSuffixes; |
156 | | |
157 | | std::map<PathGroup, std::vector<PathLabel>> PathGroupLabelMap; |
158 | | std::vector<PathGroup> PathGroupOrder; |
159 | | std::map<std::string, PathLabel> PathLabelStringMap; |
160 | | std::map<PathLabel, cmSearchPath> LabeledPaths; |
161 | | |
162 | | std::vector<std::string> SearchPaths; |
163 | | std::set<cmSearchPath::PathWithPrefix> SearchPathsEmitted; |
164 | | |
165 | | bool SearchFrameworkFirst; |
166 | | bool SearchFrameworkOnly; |
167 | | bool SearchFrameworkLast; |
168 | | |
169 | | bool SearchAppBundleFirst; |
170 | | bool SearchAppBundleOnly; |
171 | | bool SearchAppBundleLast; |
172 | | |
173 | | cmMakefile* Makefile; |
174 | | cmExecutionStatus& Status; |
175 | | }; |
176 | | |
177 | | class cmFindCommonDebugState |
178 | | { |
179 | | public: |
180 | | cmFindCommonDebugState(std::string name, cmFindCommon const* findCommand); |
181 | 0 | virtual ~cmFindCommonDebugState() = default; |
182 | | |
183 | | void FoundAt(std::string const& path, std::string regexName = std::string()); |
184 | | void FailedAt(std::string const& path, |
185 | | std::string regexName = std::string()); |
186 | | |
187 | | void Write(); |
188 | | |
189 | | protected: |
190 | | virtual void FoundAtImpl(std::string const& path, std::string regexName) = 0; |
191 | | virtual void FailedAtImpl(std::string const& path, |
192 | | std::string regexName) = 0; |
193 | | virtual bool ShouldImplicitlyLogEvents() const; |
194 | | |
195 | | virtual void WriteDebug() const = 0; |
196 | | #ifndef CMAKE_BOOTSTRAP |
197 | | virtual void WriteEvent(cmConfigureLog& log, cmMakefile const& mf) const = 0; |
198 | | void WriteSearchVariables(cmConfigureLog& log, cmMakefile const& mf) const; |
199 | | enum class VariableSource |
200 | | { |
201 | | String, |
202 | | PathList, |
203 | | EnvironmentList, |
204 | | }; |
205 | | virtual std::vector<std::pair<VariableSource, std::string>> |
206 | | ExtraSearchVariables() const; |
207 | | #endif |
208 | | |
209 | | cmFindCommon const* const FindCommand; |
210 | | std::string const CommandName; |
211 | | std::string const Mode; |
212 | 0 | bool HasBeenFound() const { return this->IsFound; } |
213 | | |
214 | | private: |
215 | | bool TrackSearchProgress() const; |
216 | | |
217 | | bool IsFound{ false }; |
218 | | }; |