cmQtAutoGenInitializer.h 7.5 KB

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