cmQtAutoGenInitializer.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 "cmFilePathChecksum.h"
  7. #include "cmQtAutoGen.h"
  8. #include <cm/string_view>
  9. #include <memory>
  10. #include <set>
  11. #include <string>
  12. #include <unordered_map>
  13. #include <unordered_set>
  14. #include <utility>
  15. #include <vector>
  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. void RegisterGeneratedSource(std::string const& filename);
  114. bool AddGeneratedSource(std::string const& filename, GenVarsT const& genVars,
  115. bool prepend = false);
  116. bool AddToSourceGroup(std::string const& fileName,
  117. cm::string_view genNameUpper);
  118. void AddCleanFile(std::string const& fileName);
  119. void ConfigFileNames(ConfigString& configString, cm::string_view prefix,
  120. cm::string_view suffix);
  121. void ConfigFileClean(ConfigString& configString);
  122. std::string GetMocBuildPath(MUFile const& muf);
  123. bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
  124. bool ignoreMissingTarget) const;
  125. private:
  126. cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
  127. cmGeneratorTarget* GenTarget = nullptr;
  128. cmGlobalGenerator* GlobalGen = nullptr;
  129. cmLocalGenerator* LocalGen = nullptr;
  130. cmMakefile* Makefile = nullptr;
  131. cmFilePathChecksum const PathCheckSum;
  132. // -- Configuration
  133. IntegerVersion QtVersion;
  134. unsigned int Verbosity = 0;
  135. bool MultiConfig = false;
  136. bool CMP0071Accept = false;
  137. bool CMP0071Warn = false;
  138. std::string ConfigDefault;
  139. std::vector<std::string> ConfigsList;
  140. std::string TargetsFolder;
  141. /** Common directories. */
  142. struct
  143. {
  144. std::string Info;
  145. std::string Build;
  146. std::string Work;
  147. ConfigString Include;
  148. std::string IncludeGenExp;
  149. } Dir;
  150. /** Autogen target variables. */
  151. struct
  152. {
  153. std::string Name;
  154. bool GlobalTarget = false;
  155. // Settings
  156. unsigned int Parallel = 1;
  157. // Configuration files
  158. std::string InfoFile;
  159. ConfigString SettingsFile;
  160. ConfigString ParseCacheFile;
  161. // Dependencies
  162. bool DependOrigin = false;
  163. std::set<std::string> DependFiles;
  164. std::set<cmTarget*> DependTargets;
  165. // Sources to process
  166. std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
  167. std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
  168. std::vector<MUFile*> FilesGenerated;
  169. } AutogenTarget;
  170. /** moc variables. */
  171. struct MocT : public GenVarsT
  172. {
  173. MocT()
  174. : GenVarsT(GenT::MOC){};
  175. bool RelaxedMode = false;
  176. bool PathPrefix = false;
  177. std::string CompilationFile;
  178. // Compiler implicit pre defines
  179. std::vector<std::string> PredefsCmd;
  180. ConfigString PredefsFile;
  181. // Defines
  182. ConfigStrings<std::set<std::string>> Defines;
  183. // Includes
  184. ConfigStrings<std::vector<std::string>> Includes;
  185. // Options
  186. std::vector<std::string> Options;
  187. // Filters
  188. std::vector<std::string> MacroNames;
  189. std::vector<std::pair<std::string, std::string>> DependFilters;
  190. // Utility
  191. std::unordered_set<std::string> EmittedBuildPaths;
  192. } Moc;
  193. /** uic variables. */
  194. struct UicT : public GenVarsT
  195. {
  196. using UiFileT = std::pair<std::string, std::vector<std::string>>;
  197. UicT()
  198. : GenVarsT(GenT::UIC){};
  199. std::set<std::string> SkipUi;
  200. std::vector<UiFileT> UiFiles;
  201. ConfigStrings<std::vector<std::string>> Options;
  202. std::vector<std::string> SearchPaths;
  203. } Uic;
  204. /** rcc variables. */
  205. struct RccT : public GenVarsT
  206. {
  207. RccT()
  208. : GenVarsT(GenT::RCC){};
  209. bool GlobalTarget = false;
  210. std::vector<Qrc> Qrcs;
  211. } Rcc;
  212. };
  213. #endif