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
12 #include <unordered_map>
13 #include <unordered_set>
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
;
27 class cmQtAutoGenGlobalInitializer
;
31 /** \class cmQtAutoGenerator
32 * \brief Initializes the QtAutoGen generators
34 class cmQtAutoGenInitializer
: public cmQtAutoGen
44 std::string QrcPathChecksum
;
46 ConfigString SettingsFile
;
47 std::string OutputFile
;
48 bool Generated
= false;
50 std::vector
<std::string
> Options
;
51 ConfigStrings
<std::vector
<std::string
>> Resources
;
54 /** moc and/or uic file. */
58 cmSourceFile
* SF
= nullptr;
59 std::vector
<size_t> Configs
;
60 bool Generated
= false;
66 using MUFileHandle
= std::unique_ptr
<MUFile
>;
68 /** Abstract moc/uic/rcc generator variables base class. */
72 // Generator type/name
74 cm::string_view GenNameUpper
;
76 std::string ExecutableTargetName
;
77 cmGeneratorTarget
* ExecutableTarget
= nullptr;
78 ConfigString Executable
;
79 ConfigStrings
<CompilerFeaturesHandle
> ExecutableFeatures
;
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();
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
);
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
;
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. */
176 std::string RelativeBuild
;
178 ConfigString Include
;
179 std::string IncludeGenExp
;
182 /** Autogen target variables. */
186 bool GlobalTarget
= false;
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
;
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
;
208 /** moc variables. */
209 struct MocT
: public GenVarsT
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
;
224 ConfigStrings
<std::set
<std::string
>> Defines
;
226 ConfigStrings
<std::vector
<std::string
>> Includes
;
228 std::vector
<std::string
> Options
;
230 std::vector
<std::string
> MacroNames
;
231 std::vector
<std::pair
<std::string
, std::string
>> DependFilters
;
233 std::unordered_set
<std::string
> EmittedBuildPaths
;
236 /** uic variables. */
237 struct UicT
: public GenVarsT
239 using UiFileT
= std::pair
<std::string
, std::vector
<std::string
>>;
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*/>>
255 /** rcc variables. */
256 struct RccT
: public GenVarsT
259 : GenVarsT(GenT::RCC
)
263 bool GlobalTarget
= false;
264 std::vector
<Qrc
> Qrcs
;