cmQtAutoGenInitializer.h 6.5 KB

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