cmQtAutoGenInitializer.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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> // IWYU pragma: keep
  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. bool ExecutableExists = false;
  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. bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
  128. bool ignoreMissingTarget, std::string* output) const;
  129. bool RccListInputs(std::string const& fileName,
  130. std::vector<std::string>& files,
  131. std::string& errorMessage);
  132. private:
  133. cmQtAutoGenGlobalInitializer* GlobalInitializer;
  134. cmGeneratorTarget* Target;
  135. // Configuration
  136. IntegerVersion QtVersion;
  137. bool MultiConfig = false;
  138. std::string ConfigDefault;
  139. std::vector<std::string> ConfigsList;
  140. std::string Verbosity;
  141. std::string TargetsFolder;
  142. bool CMP0071Accept = false;
  143. bool CMP0071Warn = false;
  144. /// @brief Common directories
  145. struct
  146. {
  147. std::string Info;
  148. std::string Build;
  149. std::string Work;
  150. std::string Include;
  151. std::map<std::string, std::string> ConfigInclude;
  152. } Dir;
  153. /// @brief Autogen target variables
  154. struct
  155. {
  156. std::string Name;
  157. bool GlobalTarget = false;
  158. // Settings
  159. std::string Parallel;
  160. // Configuration files
  161. std::string InfoFile;
  162. std::string SettingsFile;
  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<std::string> ListOptions;
  204. std::vector<Qrc> Qrcs;
  205. /// @brief Constructor
  206. RccT()
  207. : GenVarsT(GenT::RCC){};
  208. } Rcc;
  209. };
  210. #endif