cmQtAutoGenInitializer.h 7.2 KB

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