cmQtAutoGenInitializer.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 "cmGeneratedFileStream.h"
  7. #include "cmQtAutoGen.h"
  8. #include "cm_string_view.hxx"
  9. #include <map>
  10. #include <memory>
  11. #include <ostream>
  12. #include <set>
  13. #include <string>
  14. #include <unordered_map>
  15. #include <utility>
  16. #include <vector>
  17. class cmGeneratorTarget;
  18. class cmTarget;
  19. class cmQtAutoGenGlobalInitializer;
  20. class cmSourceFile;
  21. /// @brief Initializes the QtAutoGen generators
  22. class cmQtAutoGenInitializer : public cmQtAutoGen
  23. {
  24. public:
  25. /// @brief Rcc job information
  26. class Qrc
  27. {
  28. public:
  29. std::string LockFile;
  30. std::string QrcFile;
  31. std::string QrcName;
  32. std::string PathChecksum;
  33. std::string InfoFile;
  34. std::string SettingsFile;
  35. std::map<std::string, std::string> ConfigSettingsFile;
  36. std::string RccFile;
  37. bool Generated = false;
  38. bool Unique = false;
  39. std::vector<std::string> Options;
  40. std::vector<std::string> Resources;
  41. };
  42. /// @brief Moc/Uic file
  43. struct MUFile
  44. {
  45. std::string RealPath;
  46. cmSourceFile* SF = nullptr;
  47. bool Generated = false;
  48. bool SkipMoc = false;
  49. bool SkipUic = false;
  50. bool MocIt = false;
  51. bool UicIt = false;
  52. };
  53. typedef std::unique_ptr<MUFile> MUFileHandle;
  54. /// @brief Abstract moc/uic/rcc generator variables base class
  55. struct GenVarsT
  56. {
  57. bool Enabled = false;
  58. // Generator type/name
  59. GenT Gen;
  60. std::string const& GenNameUpper;
  61. // Executable
  62. std::string ExecutableTargetName;
  63. cmGeneratorTarget* ExecutableTarget = nullptr;
  64. std::string Executable;
  65. CompilerFeaturesHandle ExecutableFeatures;
  66. /// @brief Constructor
  67. GenVarsT(GenT gen)
  68. : Gen(gen)
  69. , GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen)){};
  70. };
  71. /// @brief Writes a CMake info file
  72. class InfoWriter
  73. {
  74. public:
  75. /// @brief Open the given file
  76. InfoWriter(std::string const& filename);
  77. /// @return True if the file is open
  78. explicit operator bool() const { return static_cast<bool>(Ofs_); }
  79. void Write(cm::string_view text) { Ofs_ << text; }
  80. void Write(cm::string_view, std::string const& value);
  81. void WriteUInt(cm::string_view, unsigned int value);
  82. template <class C>
  83. void WriteStrings(cm::string_view, C const& container);
  84. void WriteConfig(cm::string_view,
  85. std::map<std::string, std::string> const& map);
  86. template <class C>
  87. void WriteConfigStrings(cm::string_view,
  88. std::map<std::string, C> const& map);
  89. void WriteNestedLists(cm::string_view,
  90. std::vector<std::vector<std::string>> const& lists);
  91. private:
  92. template <class IT>
  93. static std::string ListJoin(IT it_begin, IT it_end);
  94. static std::string ConfigKey(cm::string_view, std::string const& config);
  95. private:
  96. cmGeneratedFileStream Ofs_;
  97. };
  98. public:
  99. /// @return The detected Qt version and the required Qt major version
  100. static std::pair<IntegerVersion, unsigned int> GetQtVersion(
  101. cmGeneratorTarget const* target);
  102. cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
  103. cmGeneratorTarget* target,
  104. IntegerVersion const& qtVersion, bool mocEnabled,
  105. bool uicEnabled, bool rccEnabled,
  106. bool globalAutogenTarget, bool globalAutoRccTarget);
  107. bool InitCustomTargets();
  108. bool SetupCustomTargets();
  109. private:
  110. /// @brief If moc or uic is enabled, the autogen target will be generated
  111. bool MocOrUicEnabled() const
  112. {
  113. return (this->Moc.Enabled || this->Uic.Enabled);
  114. }
  115. bool InitMoc();
  116. bool InitUic();
  117. bool InitRcc();
  118. bool InitScanFiles();
  119. bool InitAutogenTarget();
  120. bool InitRccTargets();
  121. bool SetupWriteAutogenInfo();
  122. bool SetupWriteRccInfo();
  123. void RegisterGeneratedSource(std::string const& filename);
  124. bool AddGeneratedSource(std::string const& filename, GenVarsT const& genVars,
  125. bool prepend = false);
  126. bool AddToSourceGroup(std::string const& fileName,
  127. std::string const& genNameUpper);
  128. void AddCleanFile(std::string const& fileName);
  129. bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
  130. bool ignoreMissingTarget) const;
  131. private:
  132. cmQtAutoGenGlobalInitializer* GlobalInitializer;
  133. cmGeneratorTarget* Target;
  134. // Configuration
  135. IntegerVersion QtVersion;
  136. bool MultiConfig = false;
  137. std::string ConfigDefault;
  138. std::vector<std::string> ConfigsList;
  139. std::string Verbosity;
  140. std::string TargetsFolder;
  141. bool CMP0071Accept = false;
  142. bool CMP0071Warn = false;
  143. /// @brief Common directories
  144. struct
  145. {
  146. std::string Info;
  147. std::string Build;
  148. std::string Work;
  149. std::string Include;
  150. std::map<std::string, std::string> ConfigInclude;
  151. } Dir;
  152. /// @brief Autogen target variables
  153. struct
  154. {
  155. std::string Name;
  156. bool GlobalTarget = false;
  157. // Settings
  158. std::string Parallel;
  159. // Configuration files
  160. std::string InfoFile;
  161. std::string SettingsFile;
  162. std::string ParseCacheFile;
  163. std::map<std::string, std::string> ConfigSettingsFile;
  164. // Dependencies
  165. bool DependOrigin = false;
  166. std::set<std::string> DependFiles;
  167. std::set<cmTarget*> DependTargets;
  168. // Sources to process
  169. std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
  170. std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
  171. std::vector<MUFile*> FilesGenerated;
  172. } AutogenTarget;
  173. /// @brief Moc only variables
  174. struct MocT : public GenVarsT
  175. {
  176. std::string PredefsCmd;
  177. std::vector<std::string> Includes;
  178. std::map<std::string, std::vector<std::string>> ConfigIncludes;
  179. std::set<std::string> Defines;
  180. std::map<std::string, std::set<std::string>> ConfigDefines;
  181. std::string MocsCompilation;
  182. /// @brief Constructor
  183. MocT()
  184. : GenVarsT(GenT::MOC){};
  185. } Moc;
  186. /// @brief Uic only variables
  187. struct UicT : public GenVarsT
  188. {
  189. std::set<std::string> SkipUi;
  190. std::vector<std::string> SearchPaths;
  191. std::vector<std::string> Options;
  192. std::map<std::string, std::vector<std::string>> ConfigOptions;
  193. std::vector<std::string> FileFiles;
  194. std::vector<std::vector<std::string>> FileOptions;
  195. /// @brief Constructor
  196. UicT()
  197. : GenVarsT(GenT::UIC){};
  198. } Uic;
  199. /// @brief Rcc only variables
  200. struct RccT : public GenVarsT
  201. {
  202. bool GlobalTarget = false;
  203. std::vector<Qrc> Qrcs;
  204. /// @brief Constructor
  205. RccT()
  206. : GenVarsT(GenT::RCC){};
  207. } Rcc;
  208. };
  209. #endif