cmQtAutoGenInitializer.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmQtAutoGenInitializer_h
  4. #define cmQtAutoGenInitializer_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  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. bool Generated = false;
  66. bool SkipMoc = false;
  67. bool SkipUic = false;
  68. bool MocIt = false;
  69. bool UicIt = false;
  70. };
  71. using MUFileHandle = std::unique_ptr<MUFile>;
  72. /** Abstract moc/uic/rcc generator variables base class. */
  73. struct GenVarsT
  74. {
  75. bool Enabled = false;
  76. // Generator type/name
  77. GenT Gen;
  78. cm::string_view GenNameUpper;
  79. // Executable
  80. std::string ExecutableTargetName;
  81. cmGeneratorTarget* ExecutableTarget = nullptr;
  82. std::string Executable;
  83. CompilerFeaturesHandle ExecutableFeatures;
  84. GenVarsT(GenT gen)
  85. : Gen(gen)
  86. , GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen)){};
  87. };
  88. public:
  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 AddToSourceGroup(std::string const& fileName,
  118. cm::string_view genNameUpper);
  119. void AddCleanFile(std::string const& fileName);
  120. void ConfigFileNames(ConfigString& configString, cm::string_view prefix,
  121. cm::string_view suffix);
  122. void ConfigFileClean(ConfigString& configString);
  123. std::string GetMocBuildPath(MUFile const& muf);
  124. bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
  125. bool ignoreMissingTarget) const;
  126. private:
  127. cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
  128. cmGeneratorTarget* GenTarget = nullptr;
  129. cmGlobalGenerator* GlobalGen = nullptr;
  130. cmLocalGenerator* LocalGen = nullptr;
  131. cmMakefile* Makefile = nullptr;
  132. cmFilePathChecksum const PathCheckSum;
  133. // -- Configuration
  134. IntegerVersion QtVersion;
  135. unsigned int Verbosity = 0;
  136. bool MultiConfig = false;
  137. bool CMP0071Accept = false;
  138. bool CMP0071Warn = false;
  139. bool CMP0100Accept = false;
  140. bool CMP0100Warn = false;
  141. std::string ConfigDefault;
  142. std::vector<std::string> ConfigsList;
  143. std::string TargetsFolder;
  144. /** Common directories. */
  145. struct
  146. {
  147. std::string Info;
  148. std::string Build;
  149. std::string Work;
  150. ConfigString Include;
  151. std::string IncludeGenExp;
  152. } Dir;
  153. /** Autogen target variables. */
  154. struct
  155. {
  156. std::string Name;
  157. bool GlobalTarget = false;
  158. // Settings
  159. unsigned int Parallel = 1;
  160. // Configuration files
  161. std::string InfoFile;
  162. ConfigString SettingsFile;
  163. ConfigString ParseCacheFile;
  164. // Dependencies
  165. bool DependOrigin = false;
  166. std::set<std::string> DependFiles;
  167. std::set<cmTarget*> DependTargets;
  168. std::string DepFile;
  169. std::string DepFileRuleName;
  170. // Sources to process
  171. std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
  172. std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
  173. std::vector<MUFile*> FilesGenerated;
  174. std::vector<cmSourceFile*> CMP0100HeadersWarn;
  175. } AutogenTarget;
  176. /** moc variables. */
  177. struct MocT : public GenVarsT
  178. {
  179. MocT()
  180. : GenVarsT(GenT::MOC){};
  181. bool RelaxedMode = false;
  182. bool PathPrefix = false;
  183. std::string CompilationFile;
  184. // Compiler implicit pre defines
  185. std::vector<std::string> PredefsCmd;
  186. ConfigString PredefsFile;
  187. // Defines
  188. ConfigStrings<std::set<std::string>> Defines;
  189. // Includes
  190. ConfigStrings<std::vector<std::string>> Includes;
  191. // Options
  192. std::vector<std::string> Options;
  193. // Filters
  194. std::vector<std::string> MacroNames;
  195. std::vector<std::pair<std::string, std::string>> DependFilters;
  196. // Utility
  197. std::unordered_set<std::string> EmittedBuildPaths;
  198. } Moc;
  199. /** uic variables. */
  200. struct UicT : public GenVarsT
  201. {
  202. using UiFileT = std::pair<std::string, std::vector<std::string>>;
  203. UicT()
  204. : GenVarsT(GenT::UIC){};
  205. std::set<std::string> SkipUi;
  206. std::vector<UiFileT> UiFiles;
  207. ConfigStrings<std::vector<std::string>> Options;
  208. std::vector<std::string> SearchPaths;
  209. } Uic;
  210. /** rcc variables. */
  211. struct RccT : public GenVarsT
  212. {
  213. RccT()
  214. : GenVarsT(GenT::RCC){};
  215. bool GlobalTarget = false;
  216. std::vector<Qrc> Qrcs;
  217. } Rcc;
  218. };
  219. #endif