cmQtAutoGenInitializer.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 RelativeBuild;
  157. std::string Work;
  158. ConfigString Include;
  159. std::string IncludeGenExp;
  160. } Dir;
  161. /** Autogen target variables. */
  162. struct
  163. {
  164. std::string Name;
  165. bool GlobalTarget = false;
  166. // Settings
  167. unsigned int Parallel = 1;
  168. // Configuration files
  169. std::string InfoFile;
  170. ConfigString SettingsFile;
  171. ConfigString ParseCacheFile;
  172. // Dependencies
  173. bool DependOrigin = false;
  174. std::set<std::string> DependFiles;
  175. std::set<cmTarget*> DependTargets;
  176. std::string DepFile;
  177. std::string DepFileRuleName;
  178. // Sources to process
  179. std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
  180. std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
  181. std::vector<MUFile*> FilesGenerated;
  182. std::vector<cmSourceFile*> CMP0100HeadersWarn;
  183. } AutogenTarget;
  184. /** moc variables. */
  185. struct MocT : public GenVarsT
  186. {
  187. MocT()
  188. : GenVarsT(GenT::MOC)
  189. {
  190. }
  191. bool RelaxedMode = false;
  192. bool PathPrefix = false;
  193. ConfigString CompilationFile;
  194. std::string CompilationFileGenex;
  195. // Compiler implicit pre defines
  196. std::vector<std::string> PredefsCmd;
  197. ConfigString PredefsFile;
  198. // Defines
  199. ConfigStrings<std::set<std::string>> Defines;
  200. // Includes
  201. ConfigStrings<std::vector<std::string>> Includes;
  202. // Options
  203. std::vector<std::string> Options;
  204. // Filters
  205. std::vector<std::string> MacroNames;
  206. std::vector<std::pair<std::string, std::string>> DependFilters;
  207. // Utility
  208. std::unordered_set<std::string> EmittedBuildPaths;
  209. } Moc;
  210. /** uic variables. */
  211. struct UicT : public GenVarsT
  212. {
  213. using UiFileT = std::pair<std::string, std::vector<std::string>>;
  214. UicT()
  215. : GenVarsT(GenT::UIC)
  216. {
  217. }
  218. std::set<std::string> SkipUi;
  219. std::vector<std::string> UiFilesNoOptions;
  220. std::vector<UiFileT> UiFilesWithOptions;
  221. ConfigStrings<std::vector<std::string>> Options;
  222. std::vector<std::string> SearchPaths;
  223. std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>>
  224. UiHeaders;
  225. } Uic;
  226. /** rcc variables. */
  227. struct RccT : public GenVarsT
  228. {
  229. RccT()
  230. : GenVarsT(GenT::RCC)
  231. {
  232. }
  233. bool GlobalTarget = false;
  234. std::vector<Qrc> Qrcs;
  235. } Rcc;
  236. };