cmQtAutoGenInitializer.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. /** @return The detected Qt version and the required Qt major version. */
  90. static std::pair<IntegerVersion, unsigned int> GetQtVersion(
  91. cmGeneratorTarget const* genTarget);
  92. cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
  93. cmGeneratorTarget* genTarget,
  94. IntegerVersion const& qtVersion, bool mocEnabled,
  95. bool uicEnabled, bool rccEnabled,
  96. bool globalAutogenTarget, bool globalAutoRccTarget);
  97. bool InitCustomTargets();
  98. bool SetupCustomTargets();
  99. private:
  100. /** If moc or uic is enabled, the autogen target will be generated. */
  101. bool MocOrUicEnabled() const
  102. {
  103. return (this->Moc.Enabled || this->Uic.Enabled);
  104. }
  105. bool InitMoc();
  106. bool InitUic();
  107. bool InitRcc();
  108. bool InitScanFiles();
  109. bool InitAutogenTarget();
  110. bool InitRccTargets();
  111. bool SetupWriteAutogenInfo();
  112. bool SetupWriteRccInfo();
  113. cmSourceFile* RegisterGeneratedSource(std::string const& filename);
  114. cmSourceFile* AddGeneratedSource(std::string const& filename,
  115. GenVarsT const& genVars,
  116. bool prepend = false);
  117. void AddGeneratedSource(ConfigString const& filename,
  118. GenVarsT const& genVars, bool prepend = false);
  119. void AddToSourceGroup(std::string const& fileName,
  120. cm::string_view genNameUpper);
  121. void AddCleanFile(std::string const& fileName);
  122. void ConfigFileNames(ConfigString& configString, cm::string_view prefix,
  123. cm::string_view suffix);
  124. void ConfigFileClean(ConfigString& configString);
  125. std::string GetMocBuildPath(MUFile const& muf);
  126. bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
  127. bool ignoreMissingTarget) 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 CMP0071Accept = false;
  139. bool CMP0071Warn = false;
  140. bool CMP0100Accept = false;
  141. bool CMP0100Warn = false;
  142. std::string ConfigDefault;
  143. std::vector<std::string> ConfigsList;
  144. std::string TargetsFolder;
  145. /** Common directories. */
  146. struct
  147. {
  148. std::string Info;
  149. std::string Build;
  150. std::string Work;
  151. ConfigString Include;
  152. std::string IncludeGenExp;
  153. } Dir;
  154. /** Autogen target variables. */
  155. struct
  156. {
  157. std::string Name;
  158. bool GlobalTarget = false;
  159. // Settings
  160. unsigned int Parallel = 1;
  161. // Configuration files
  162. std::string InfoFile;
  163. ConfigString SettingsFile;
  164. ConfigString ParseCacheFile;
  165. // Dependencies
  166. bool DependOrigin = false;
  167. std::set<std::string> DependFiles;
  168. std::set<cmTarget*> DependTargets;
  169. std::string DepFile;
  170. std::string DepFileRuleName;
  171. // Sources to process
  172. std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
  173. std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
  174. std::vector<MUFile*> FilesGenerated;
  175. std::vector<cmSourceFile*> CMP0100HeadersWarn;
  176. } AutogenTarget;
  177. /** moc variables. */
  178. struct MocT : public GenVarsT
  179. {
  180. MocT()
  181. : GenVarsT(GenT::MOC){};
  182. bool RelaxedMode = false;
  183. bool PathPrefix = false;
  184. ConfigString CompilationFile;
  185. std::string CompilationFileGenex;
  186. // Compiler implicit pre defines
  187. std::vector<std::string> PredefsCmd;
  188. ConfigString PredefsFile;
  189. // Defines
  190. ConfigStrings<std::set<std::string>> Defines;
  191. // Includes
  192. ConfigStrings<std::vector<std::string>> Includes;
  193. // Options
  194. std::vector<std::string> Options;
  195. // Filters
  196. std::vector<std::string> MacroNames;
  197. std::vector<std::pair<std::string, std::string>> DependFilters;
  198. // Utility
  199. std::unordered_set<std::string> EmittedBuildPaths;
  200. } Moc;
  201. /** uic variables. */
  202. struct UicT : public GenVarsT
  203. {
  204. using UiFileT = std::pair<std::string, std::vector<std::string>>;
  205. UicT()
  206. : GenVarsT(GenT::UIC){};
  207. std::set<std::string> SkipUi;
  208. std::vector<UiFileT> UiFiles;
  209. ConfigStrings<std::vector<std::string>> Options;
  210. std::vector<std::string> SearchPaths;
  211. std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>>
  212. UiHeaders;
  213. } Uic;
  214. /** rcc variables. */
  215. struct RccT : public GenVarsT
  216. {
  217. RccT()
  218. : GenVarsT(GenT::RCC){};
  219. bool GlobalTarget = false;
  220. std::vector<Qrc> Qrcs;
  221. } Rcc;
  222. };