cmQtAutoGenInitializer.h 7.2 KB

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