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 cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
158 cmGeneratorTarget* GenTarget = nullptr;
159 cmGlobalGenerator* GlobalGen = nullptr;
160 cmLocalGenerator* LocalGen = nullptr;
161 cmMakefile* Makefile = nullptr;
162 cmFilePathChecksum const PathCheckSum;
165 IntegerVersion QtVersion;
166 unsigned int Verbosity = 0;
167 bool MultiConfig = false;
168 bool CMP0071Accept = false;
169 bool CMP0071Warn = false;
170 bool CMP0100Accept = false;
171 bool CMP0100Warn = false;
172 std::string ConfigDefault;
173 std::vector<std::string> ConfigsList;
174 std::string TargetsFolder;
176 /** Common directories. */
181 std::string RelativeBuild;
183 ConfigString Include;
184 std::string IncludeGenExp;
187 /** Autogen target variables. */
191 bool GlobalTarget = false;
193 unsigned int Parallel = 1;
194 // Configuration files
195 std::string InfoFile;
196 ConfigString SettingsFile;
197 ConfigString ParseCacheFile;
199 bool DependOrigin = false;
200 std::set<std::string> DependFiles;
201 std::set<cmTarget*> DependTargets;
203 std::string DepFileRuleName;
204 // Sources to process
205 std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
206 std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
207 std::vector<MUFile*> FilesGenerated;
208 std::vector<cmSourceFile*> CMP0100HeadersWarn;
211 /** moc variables. */
212 struct MocT : public GenVarsT
215 : GenVarsT(GenT::MOC)
219 bool RelaxedMode = false;
220 bool PathPrefix = false;
221 ConfigString CompilationFile;
222 std::string CompilationFileGenex;
223 // Compiler implicit pre defines
224 std::vector<std::string> PredefsCmd;
225 ConfigString PredefsFile;
227 ConfigStrings<std::set<std::string>> Defines;
229 ConfigStrings<std::vector<std::string>> Includes;
231 std::vector<std::string> Options;
233 std::vector<std::string> MacroNames;
234 std::vector<std::pair<std::string, std::string>> DependFilters;
236 std::unordered_set<std::string> EmittedBuildPaths;
239 /** uic variables. */
240 struct UicT : public GenVarsT
242 using UiFileT = std::pair<std::string, std::vector<std::string>>;
245 : GenVarsT(GenT::UIC)
249 std::set<std::string> SkipUi;
250 std::vector<std::string> UiFilesNoOptions;
251 std::vector<UiFileT> UiFilesWithOptions;
252 ConfigStrings<std::vector<std::string>> Options;
253 std::vector<std::string> SearchPaths;
254 std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>>
258 /** rcc variables. */
259 struct RccT : public GenVarsT
262 : GenVarsT(GenT::RCC)
266 bool GlobalTarget = false;
267 std::vector<Qrc> Qrcs;