1
0

cmQtAutoGenInitializer.h 6.5 KB

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