/src/CMake/Source/cmQtAutoGenInitializer.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 <cstddef> |
8 | | #include <limits> |
9 | | #include <memory> |
10 | | #include <set> |
11 | | #include <string> |
12 | | #include <unordered_map> |
13 | | #include <unordered_set> |
14 | | #include <utility> |
15 | | #include <vector> |
16 | | |
17 | | #include <cm/string_view> |
18 | | |
19 | | #include "cmFilePathChecksum.h" |
20 | | #include "cmQtAutoGen.h" |
21 | | |
22 | | class cmCustomCommandLines; |
23 | | class cmGeneratorTarget; |
24 | | class cmGlobalGenerator; |
25 | | class cmLocalGenerator; |
26 | | class cmMakefile; |
27 | | class cmQtAutoGenGlobalInitializer; |
28 | | class cmSourceFile; |
29 | | class cmTarget; |
30 | | |
31 | | /** \class cmQtAutoGenerator |
32 | | * \brief Initializes the QtAutoGen generators |
33 | | */ |
34 | | class cmQtAutoGenInitializer : public cmQtAutoGen |
35 | | { |
36 | | public: |
37 | | /** rcc job. */ |
38 | | class Qrc |
39 | | { |
40 | | public: |
41 | | std::string LockFile; |
42 | | std::string QrcFile; |
43 | | std::string QrcName; |
44 | | std::string QrcPathChecksum; |
45 | | std::string InfoFile; |
46 | | // Base name of the files caching the rcc listing of the qrc file |
47 | | std::string ListFileBase; |
48 | | ConfigString SettingsFile; |
49 | | ConfigString OutputFile; |
50 | | std::string OutputFileGenex; |
51 | | bool Generated = false; |
52 | | bool Unique = false; |
53 | | std::vector<std::string> Options; |
54 | | ConfigStrings<std::vector<std::string>> Resources; |
55 | | }; |
56 | | |
57 | | /** moc and/or uic file. */ |
58 | | struct MUFile |
59 | | { |
60 | | std::string FullPath; |
61 | | cmSourceFile* SF = nullptr; |
62 | | std::vector<size_t> Configs; |
63 | | bool Generated = false; |
64 | | bool SkipMoc = false; |
65 | | bool SkipUic = false; |
66 | | bool MocIt = false; |
67 | | bool UicIt = false; |
68 | | // Memoized GetMocBuildPath() result. Mutable because the info file |
69 | | // writer reaches this through const references. |
70 | | mutable std::string MocBuildPath; |
71 | | }; |
72 | | using MUFileHandle = std::unique_ptr<MUFile>; |
73 | | |
74 | | /** Abstract moc/uic/rcc generator variables base class. */ |
75 | | struct GenVarsT |
76 | | { |
77 | | bool Enabled = false; |
78 | | // Generator type/name |
79 | | GenT Gen; |
80 | | cm::string_view GenNameUpper; |
81 | | // Executable |
82 | | std::string ExecutableTargetName; |
83 | | cmGeneratorTarget* ExecutableTarget = nullptr; |
84 | | ConfigString Executable; |
85 | | ConfigStrings<CompilerFeaturesHandle> ExecutableFeatures; |
86 | | |
87 | | GenVarsT(GenT gen) |
88 | 0 | : Gen(gen) |
89 | 0 | , GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen)) |
90 | 0 | { |
91 | 0 | } |
92 | | }; |
93 | | |
94 | | /** @param mocExecutable The file path to the moc executable. Will be used as |
95 | | fallback to query the version |
96 | | @return The detected Qt version and the required Qt major version. */ |
97 | | static std::pair<IntegerVersion, unsigned int> GetQtVersion( |
98 | | cmGeneratorTarget const* genTarget, std::string mocExecutable); |
99 | | |
100 | | cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer, |
101 | | cmGeneratorTarget* genTarget, |
102 | | IntegerVersion qtVersion, bool mocEnabled, |
103 | | bool uicEnabled, bool rccEnabled, |
104 | | bool globalAutogenTarget, bool globalAutoRccTarget); |
105 | | |
106 | | bool InitCustomTargets(); |
107 | | bool SetupCustomTargets(); |
108 | | |
109 | | private: |
110 | | /** If moc or uic is enabled, the autogen target will be generated. */ |
111 | | bool MocOrUicEnabled() const |
112 | 0 | { |
113 | 0 | return (this->Moc.Enabled || this->Uic.Enabled); |
114 | 0 | } |
115 | | |
116 | | /** Whether the CXX compiler targets the MSVC ABI. */ |
117 | | bool IsMsvcAbi() const; |
118 | | |
119 | | bool InitMoc(); |
120 | | bool InitUic(); |
121 | | bool InitRcc(); |
122 | | |
123 | | bool InitScanFiles(); |
124 | | bool InitAutogenTarget(); |
125 | | bool InitRccTargets(); |
126 | | |
127 | | bool SetupWriteAutogenInfo(); |
128 | | bool SetupWriteRccInfo(); |
129 | | |
130 | | /** Whether a generated source is scanned for C++ module dependencies. */ |
131 | | enum class ModuleScan |
132 | | { |
133 | | Never, // It imports nothing. |
134 | | Always, // It is a unit of a module. |
135 | | LikeTarget, // It may import whatever the target's own sources import. |
136 | | }; |
137 | | |
138 | | cmSourceFile* RegisterGeneratedSource( |
139 | | std::string const& filename, ModuleScan moduleScan = ModuleScan::Never); |
140 | | cmSourceFile* AddGeneratedSource(std::string const& filename, |
141 | | GenVarsT const& genVars, |
142 | | bool prepend = false, |
143 | | ModuleScan moduleScan = ModuleScan::Never); |
144 | | void AddGeneratedSource(ConfigString const& filename, |
145 | | GenVarsT const& genVars, bool prepend = false, |
146 | | ModuleScan moduleScan = ModuleScan::Never); |
147 | | void AddToSourceGroup(std::string const& fileName, |
148 | | cm::string_view genNameUpper); |
149 | | void AddCMakeProcessToCommandLines(std::string const& infoFile, |
150 | | std::string const& processName, |
151 | | cmCustomCommandLines& commandLines); |
152 | | void AddCleanFile(std::string const& fileName); |
153 | | |
154 | | void ConfigFileNames(ConfigString& configString, cm::string_view prefix, |
155 | | cm::string_view suffix); |
156 | | void ConfigFileNamesAndGenex(ConfigString& configString, std::string& genex, |
157 | | cm::string_view prefix, cm::string_view suffix); |
158 | | void ConfigFileNameCommon(ConfigString& configString, |
159 | | std::string const& fileName); |
160 | | void ConfigFileClean(ConfigString& configString); |
161 | | |
162 | | std::string const& GetMocBuildPath(MUFile const& muf); |
163 | | |
164 | | bool GetQtExecutable(GenVarsT& genVars, std::string const& executable, |
165 | | bool ignoreMissingTarget) const; |
166 | | |
167 | | void handleSkipPch(cmSourceFile* sf); |
168 | | void AddAutogenExecutableToDependencies( |
169 | | cmQtAutoGenInitializer::GenVarsT const& genVars, |
170 | | std::vector<std::string>& dependencies) const; |
171 | | |
172 | | cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr; |
173 | | cmGeneratorTarget* GenTarget = nullptr; |
174 | | cmGlobalGenerator* GlobalGen = nullptr; |
175 | | cmLocalGenerator* LocalGen = nullptr; |
176 | | cmMakefile* Makefile = nullptr; |
177 | | cmFilePathChecksum const PathCheckSum; |
178 | | |
179 | | // -- Configuration |
180 | | IntegerVersion QtVersion; |
181 | | unsigned int Verbosity = 0; |
182 | | bool MultiConfig = false; |
183 | | bool CrossConfig = false; |
184 | | bool UseBetterGraph = false; |
185 | | bool CMP0071Accept = false; |
186 | | bool CMP0071Warn = false; |
187 | | bool CMP0100Accept = false; |
188 | | bool CMP0100Warn = false; |
189 | | std::string ConfigDefault; |
190 | | std::vector<std::string> ConfigsList; |
191 | | std::string TargetsFolder; |
192 | | |
193 | | /** Common directories. */ |
194 | | struct |
195 | | { |
196 | | std::string Info; |
197 | | std::string Build; |
198 | | std::string RelativeBuild; |
199 | | std::string Work; |
200 | | ConfigString Include; |
201 | | std::string IncludeGenExp; |
202 | | } Dir; |
203 | | |
204 | | /** Autogen target variables. */ |
205 | | struct |
206 | | { |
207 | | std::string Name; |
208 | | bool GlobalTarget = false; |
209 | | // Settings |
210 | | unsigned int Parallel = 1; |
211 | | unsigned int MaxCommandLineLength = |
212 | | std::numeric_limits<unsigned int>::max(); |
213 | | // Configuration files |
214 | | std::string InfoFile; |
215 | | ConfigString SettingsFile; |
216 | | ConfigString ParseCacheFile; |
217 | | // Dependencies |
218 | | bool DependOrigin = false; |
219 | | std::set<std::string> DependFiles; |
220 | | std::set<cmTarget*> DependTargets; |
221 | | ConfigString DepFile; |
222 | | ConfigString DepFileRuleName; |
223 | | // Sources to process |
224 | | std::unordered_map<cmSourceFile*, MUFileHandle> Headers; |
225 | | std::unordered_map<cmSourceFile*, MUFileHandle> Sources; |
226 | | std::unordered_map<cmSourceFile*, MUFileHandle> ModuleUnits; |
227 | | std::vector<MUFile*> FilesGenerated; |
228 | | std::vector<cmSourceFile*> CMP0100HeadersWarn; |
229 | | } AutogenTarget; |
230 | | |
231 | | /** moc variables. */ |
232 | | struct MocT : public GenVarsT |
233 | | { |
234 | | MocT() |
235 | 0 | : GenVarsT(GenT::MOC) |
236 | 0 | { |
237 | 0 | } |
238 | | |
239 | | bool RelaxedMode = false; |
240 | | bool PathPrefix = false; |
241 | | ConfigString CompilationFile; |
242 | | std::string CompilationFileGenex; |
243 | | // Compiler implicit pre defines |
244 | | std::vector<std::string> PredefsCmd; |
245 | | ConfigString PredefsFile; |
246 | | // Defines |
247 | | ConfigStrings<std::set<std::string>> Defines; |
248 | | // Includes |
249 | | ConfigStrings<std::vector<std::string>> Includes; |
250 | | // Options |
251 | | std::vector<std::string> Options; |
252 | | // Filters |
253 | | std::vector<std::string> MacroNames; |
254 | | std::vector<std::pair<std::string, std::string>> DependFilters; |
255 | | // Utility |
256 | | std::unordered_set<std::string> EmittedBuildPaths; |
257 | | } Moc; |
258 | | |
259 | | /** uic variables. */ |
260 | | struct UicT : public GenVarsT |
261 | | { |
262 | | using UiFileT = std::pair<std::string, std::vector<std::string>>; |
263 | | |
264 | | UicT() |
265 | 0 | : GenVarsT(GenT::UIC) |
266 | 0 | { |
267 | 0 | } |
268 | | |
269 | | std::set<std::string> SkipUi; |
270 | | std::vector<std::string> UiFilesNoOptions; |
271 | | std::vector<UiFileT> UiFilesWithOptions; |
272 | | ConfigStrings<std::vector<std::string>> Options; |
273 | | std::vector<std::string> SearchPaths; |
274 | | std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>> |
275 | | UiHeaders; |
276 | | } Uic; |
277 | | |
278 | | /** rcc variables. */ |
279 | | struct RccT : public GenVarsT |
280 | | { |
281 | | RccT() |
282 | 0 | : GenVarsT(GenT::RCC) |
283 | 0 | { |
284 | 0 | } |
285 | | |
286 | | bool GlobalTarget = false; |
287 | | std::vector<Qrc> Qrcs; |
288 | | } Rcc; |
289 | | }; |