CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmQtAutoGenInitializer.h
blob1ab038b18eeb48cc09f4ec602e1a849467ff5fdd
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
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>
17 #include <cm/string_view>
19 #include "cmFilePathChecksum.h"
20 #include "cmQtAutoGen.h"
22 class cmCustomCommandLines;
23 class cmGeneratorTarget;
24 class cmGlobalGenerator;
25 class cmLocalGenerator;
26 class cmMakefile;
27 class cmQtAutoGenGlobalInitializer;
28 class cmSourceFile;
29 class cmTarget;
31 /** \class cmQtAutoGenerator
32 * \brief Initializes the QtAutoGen generators
34 class cmQtAutoGenInitializer : public cmQtAutoGen
36 public:
37 /** rcc job. */
38 class Qrc
40 public:
41 std::string LockFile;
42 std::string QrcFile;
43 std::string QrcName;
44 std::string QrcPathChecksum;
45 std::string InfoFile;
46 ConfigString SettingsFile;
47 std::string OutputFile;
48 bool Generated = false;
49 bool Unique = false;
50 std::vector<std::string> Options;
51 ConfigStrings<std::vector<std::string>> Resources;
54 /** moc and/or uic file. */
55 struct MUFile
57 std::string FullPath;
58 cmSourceFile* SF = nullptr;
59 std::vector<size_t> Configs;
60 bool Generated = false;
61 bool SkipMoc = false;
62 bool SkipUic = false;
63 bool MocIt = false;
64 bool UicIt = false;
66 using MUFileHandle = std::unique_ptr<MUFile>;
68 /** Abstract moc/uic/rcc generator variables base class. */
69 struct GenVarsT
71 bool Enabled = false;
72 // Generator type/name
73 GenT Gen;
74 cm::string_view GenNameUpper;
75 // Executable
76 std::string ExecutableTargetName;
77 cmGeneratorTarget* ExecutableTarget = nullptr;
78 ConfigString Executable;
79 ConfigStrings<CompilerFeaturesHandle> ExecutableFeatures;
81 GenVarsT(GenT gen)
82 : Gen(gen)
83 , GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen))
88 /** @param mocExecutable The file path to the moc executable. Will be used as
89 fallback to query the version
90 @return The detected Qt version and the required Qt major version. */
91 static std::pair<IntegerVersion, unsigned int> GetQtVersion(
92 cmGeneratorTarget const* genTarget, std::string mocExecutable);
94 cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
95 cmGeneratorTarget* genTarget,
96 IntegerVersion const& qtVersion, bool mocEnabled,
97 bool uicEnabled, bool rccEnabled,
98 bool globalAutogenTarget, bool globalAutoRccTarget);
100 bool InitCustomTargets();
101 bool SetupCustomTargets();
103 private:
104 /** If moc or uic is enabled, the autogen target will be generated. */
105 bool MocOrUicEnabled() const
107 return (this->Moc.Enabled || this->Uic.Enabled);
110 bool InitMoc();
111 bool InitUic();
112 bool InitRcc();
114 bool InitScanFiles();
115 bool InitAutogenTarget();
116 bool InitRccTargets();
118 bool SetupWriteAutogenInfo();
119 bool SetupWriteRccInfo();
121 cmSourceFile* RegisterGeneratedSource(std::string const& filename);
122 cmSourceFile* AddGeneratedSource(std::string const& filename,
123 GenVarsT const& genVars,
124 bool prepend = false);
125 void AddGeneratedSource(ConfigString const& filename,
126 GenVarsT const& genVars, bool prepend = false);
127 void AddToSourceGroup(std::string const& fileName,
128 cm::string_view genNameUpper);
129 void AddCMakeProcessToCommandLines(std::string const& infoFile,
130 std::string const& processName,
131 cmCustomCommandLines& commandLines);
132 void AddCleanFile(std::string const& fileName);
134 void ConfigFileNames(ConfigString& configString, cm::string_view prefix,
135 cm::string_view suffix);
136 void ConfigFileNamesAndGenex(ConfigString& configString, std::string& genex,
137 cm::string_view prefix, cm::string_view suffix);
138 void ConfigFileClean(ConfigString& configString);
140 std::string GetMocBuildPath(MUFile const& muf);
142 bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
143 bool ignoreMissingTarget) const;
145 void handleSkipPch(cmSourceFile* sf);
146 void AddAutogenExecutableToDependencies(
147 cmQtAutoGenInitializer::GenVarsT const& genVars,
148 std::vector<std::string>& dependencies) const;
150 cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
151 cmGeneratorTarget* GenTarget = nullptr;
152 cmGlobalGenerator* GlobalGen = nullptr;
153 cmLocalGenerator* LocalGen = nullptr;
154 cmMakefile* Makefile = nullptr;
155 cmFilePathChecksum const PathCheckSum;
157 // -- Configuration
158 IntegerVersion QtVersion;
159 unsigned int Verbosity = 0;
160 bool MultiConfig = false;
161 bool CrossConfig = false;
162 bool UseBetterGraph = false;
163 bool CMP0071Accept = false;
164 bool CMP0071Warn = false;
165 bool CMP0100Accept = false;
166 bool CMP0100Warn = false;
167 std::string ConfigDefault;
168 std::vector<std::string> ConfigsList;
169 std::string TargetsFolder;
171 /** Common directories. */
172 struct
174 std::string Info;
175 std::string Build;
176 std::string RelativeBuild;
177 std::string Work;
178 ConfigString Include;
179 std::string IncludeGenExp;
180 } Dir;
182 /** Autogen target variables. */
183 struct
185 std::string Name;
186 bool GlobalTarget = false;
187 // Settings
188 unsigned int Parallel = 1;
189 unsigned int MaxCommandLineLength =
190 std::numeric_limits<unsigned int>::max();
191 // Configuration files
192 std::string InfoFile;
193 ConfigString SettingsFile;
194 ConfigString ParseCacheFile;
195 // Dependencies
196 bool DependOrigin = false;
197 std::set<std::string> DependFiles;
198 std::set<cmTarget*> DependTargets;
199 ConfigString DepFile;
200 ConfigString DepFileRuleName;
201 // Sources to process
202 std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
203 std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
204 std::vector<MUFile*> FilesGenerated;
205 std::vector<cmSourceFile*> CMP0100HeadersWarn;
206 } AutogenTarget;
208 /** moc variables. */
209 struct MocT : public GenVarsT
211 MocT()
212 : GenVarsT(GenT::MOC)
216 bool RelaxedMode = false;
217 bool PathPrefix = false;
218 ConfigString CompilationFile;
219 std::string CompilationFileGenex;
220 // Compiler implicit pre defines
221 std::vector<std::string> PredefsCmd;
222 ConfigString PredefsFile;
223 // Defines
224 ConfigStrings<std::set<std::string>> Defines;
225 // Includes
226 ConfigStrings<std::vector<std::string>> Includes;
227 // Options
228 std::vector<std::string> Options;
229 // Filters
230 std::vector<std::string> MacroNames;
231 std::vector<std::pair<std::string, std::string>> DependFilters;
232 // Utility
233 std::unordered_set<std::string> EmittedBuildPaths;
234 } Moc;
236 /** uic variables. */
237 struct UicT : public GenVarsT
239 using UiFileT = std::pair<std::string, std::vector<std::string>>;
241 UicT()
242 : GenVarsT(GenT::UIC)
246 std::set<std::string> SkipUi;
247 std::vector<std::string> UiFilesNoOptions;
248 std::vector<UiFileT> UiFilesWithOptions;
249 ConfigStrings<std::vector<std::string>> Options;
250 std::vector<std::string> SearchPaths;
251 std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>>
252 UiHeaders;
253 } Uic;
255 /** rcc variables. */
256 struct RccT : public GenVarsT
258 RccT()
259 : GenVarsT(GenT::RCC)
263 bool GlobalTarget = false;
264 std::vector<Qrc> Qrcs;
265 } Rcc;