1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
11 #include <unordered_map>
12 #include <unordered_set>
16 #include <cm/string_view>
18 #include "cmFilePathChecksum.h"
19 #include "cmQtAutoGen.h"
21 class cmGeneratorTarget;
22 class cmGlobalGenerator;
23 class cmLocalGenerator;
25 class cmQtAutoGenGlobalInitializer;
29 /** \class cmQtAutoGenerator
30 * \brief Initializes the QtAutoGen generators
32 class cmQtAutoGenInitializer : public cmQtAutoGen
35 /** String value with per configuration variants. */
40 std::unordered_map<std::string, std::string> Config;
43 /** String values with per configuration variants. */
49 std::unordered_map<std::string, C> Config;
59 std::string QrcPathChecksum;
61 ConfigString SettingsFile;
62 std::string OutputFile;
63 bool Generated = false;
65 std::vector<std::string> Options;
66 std::vector<std::string> Resources;
69 /** moc and/or uic file. */
73 cmSourceFile* SF = nullptr;
74 std::vector<size_t> Configs;
75 bool Generated = false;
81 using MUFileHandle = std::unique_ptr<MUFile>;
83 /** Abstract moc/uic/rcc generator variables base class. */
87 // Generator type/name
89 cm::string_view GenNameUpper;
91 std::string ExecutableTargetName;
92 cmGeneratorTarget* ExecutableTarget = nullptr;
93 std::string Executable;
94 CompilerFeaturesHandle ExecutableFeatures;
98 , GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen))
103 /** @param mocExecutable The file path to the moc executable. Will be used as
104 fallback to query the version
105 @return The detected Qt version and the required Qt major version. */
106 static std::pair<IntegerVersion, unsigned int> GetQtVersion(
107 cmGeneratorTarget const* genTarget, std::string mocExecutable);
109 cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
110 cmGeneratorTarget* genTarget,
111 IntegerVersion const& qtVersion, bool mocEnabled,
112 bool uicEnabled, bool rccEnabled,
113 bool globalAutogenTarget, bool globalAutoRccTarget);
115 bool InitCustomTargets();
116 bool SetupCustomTargets();
119 /** If moc or uic is enabled, the autogen target will be generated. */
120 bool MocOrUicEnabled() const
122 return (this->Moc.Enabled || this->Uic.Enabled);
129 bool InitScanFiles();
130 bool InitAutogenTarget();
131 bool InitRccTargets();
133 bool SetupWriteAutogenInfo();
134 bool SetupWriteRccInfo();
136 cmSourceFile* RegisterGeneratedSource(std::string const& filename);
137 cmSourceFile* AddGeneratedSource(std::string const& filename,
138 GenVarsT const& genVars,
139 bool prepend = false);
140 void AddGeneratedSource(ConfigString const& filename,
141 GenVarsT const& genVars, bool prepend = false);
142 void AddToSourceGroup(std::string const& fileName,
143 cm::string_view genNameUpper);
144 void AddCleanFile(std::string const& fileName);
146 void ConfigFileNames(ConfigString& configString, cm::string_view prefix,
147 cm::string_view suffix);
148 void ConfigFileNamesAndGenex(ConfigString& configString, std::string& genex,
149 cm::string_view prefix, cm::string_view suffix);
150 void ConfigFileClean(ConfigString& configString);
152 std::string GetMocBuildPath(MUFile const& muf);
154 bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
155 bool ignoreMissingTarget) const;
157 void handleSkipPch(cmSourceFile* sf);
159 cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
160 cmGeneratorTarget* GenTarget = nullptr;
161 cmGlobalGenerator* GlobalGen = nullptr;
162 cmLocalGenerator* LocalGen = nullptr;
163 cmMakefile* Makefile = nullptr;
164 cmFilePathChecksum const PathCheckSum;
167 IntegerVersion QtVersion;
168 unsigned int Verbosity = 0;
169 bool MultiConfig = false;
170 bool CMP0071Accept = false;
171 bool CMP0071Warn = false;
172 bool CMP0100Accept = false;
173 bool CMP0100Warn = false;
174 std::string ConfigDefault;
175 std::vector<std::string> ConfigsList;
176 std::string TargetsFolder;
178 /** Common directories. */
183 std::string RelativeBuild;
185 ConfigString Include;
186 std::string IncludeGenExp;
189 /** Autogen target variables. */
193 bool GlobalTarget = false;
195 unsigned int Parallel = 1;
196 // Configuration files
197 std::string InfoFile;
198 ConfigString SettingsFile;
199 ConfigString ParseCacheFile;
201 bool DependOrigin = false;
202 std::set<std::string> DependFiles;
203 std::set<cmTarget*> DependTargets;
205 std::string DepFileRuleName;
206 // Sources to process
207 std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
208 std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
209 std::vector<MUFile*> FilesGenerated;
210 std::vector<cmSourceFile*> CMP0100HeadersWarn;
213 /** moc variables. */
214 struct MocT : public GenVarsT
217 : GenVarsT(GenT::MOC)
221 bool RelaxedMode = false;
222 bool PathPrefix = false;
223 ConfigString CompilationFile;
224 std::string CompilationFileGenex;
225 // Compiler implicit pre defines
226 std::vector<std::string> PredefsCmd;
227 ConfigString PredefsFile;
229 ConfigStrings<std::set<std::string>> Defines;
231 ConfigStrings<std::vector<std::string>> Includes;
233 std::vector<std::string> Options;
235 std::vector<std::string> MacroNames;
236 std::vector<std::pair<std::string, std::string>> DependFilters;
238 std::unordered_set<std::string> EmittedBuildPaths;
241 /** uic variables. */
242 struct UicT : public GenVarsT
244 using UiFileT = std::pair<std::string, std::vector<std::string>>;
247 : GenVarsT(GenT::UIC)
251 std::set<std::string> SkipUi;
252 std::vector<std::string> UiFilesNoOptions;
253 std::vector<UiFileT> UiFilesWithOptions;
254 ConfigStrings<std::vector<std::string>> Options;
255 std::vector<std::string> SearchPaths;
256 std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>>
260 /** rcc variables. */
261 struct RccT : public GenVarsT
264 : GenVarsT(GenT::RCC)
268 bool GlobalTarget = false;
269 std::vector<Qrc> Qrcs;