cmQtAutoGenInitializer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 <vector>
  13. class cmGeneratorTarget;
  14. class cmTarget;
  15. class cmQtAutoGenGlobalInitializer;
  16. /// @brief Initializes the QtAutoGen generators
  17. class cmQtAutoGenInitializer : public cmQtAutoGen
  18. {
  19. public:
  20. /// @brief Rcc job information
  21. class Qrc
  22. {
  23. public:
  24. Qrc()
  25. : Generated(false)
  26. , Unique(false)
  27. {
  28. }
  29. public:
  30. std::string LockFile;
  31. std::string QrcFile;
  32. std::string QrcName;
  33. std::string PathChecksum;
  34. std::string InfoFile;
  35. std::string SettingsFile;
  36. std::map<std::string, std::string> ConfigSettingsFile;
  37. std::string RccFile;
  38. bool Generated;
  39. bool Unique;
  40. std::vector<std::string> Options;
  41. std::vector<std::string> Resources;
  42. };
  43. /// @brief Writes a CMake info file
  44. class InfoWriter
  45. {
  46. public:
  47. /// @brief Open the given file
  48. InfoWriter(std::string const& filename);
  49. /// @return True if the file is open
  50. explicit operator bool() const { return static_cast<bool>(Ofs_); }
  51. void Write(const char* text) { Ofs_ << text; }
  52. void Write(const char* key, std::string const& value);
  53. void WriteUInt(const char* key, unsigned int value);
  54. template <class C>
  55. void WriteStrings(const char* key, C const& container);
  56. void WriteConfig(const char* key,
  57. std::map<std::string, std::string> const& map);
  58. template <class C>
  59. void WriteConfigStrings(const char* key,
  60. std::map<std::string, C> const& map);
  61. void WriteNestedLists(const char* key,
  62. std::vector<std::vector<std::string>> const& lists);
  63. private:
  64. template <class IT>
  65. static std::string ListJoin(IT it_begin, IT it_end);
  66. static std::string ConfigKey(const char* key, std::string const& config);
  67. private:
  68. cmGeneratedFileStream Ofs_;
  69. };
  70. public:
  71. static IntegerVersion GetQtVersion(cmGeneratorTarget const* target);
  72. cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
  73. cmGeneratorTarget* target,
  74. IntegerVersion const& qtVersion, bool mocEnabled,
  75. bool uicEnabled, bool rccEnabled,
  76. bool globalAutogenTarget, bool globalAutoRccTarget);
  77. bool InitCustomTargets();
  78. bool SetupCustomTargets();
  79. private:
  80. bool InitMoc();
  81. bool InitUic();
  82. bool InitRcc();
  83. bool InitScanFiles();
  84. bool InitAutogenTarget();
  85. bool InitRccTargets();
  86. bool SetupWriteAutogenInfo();
  87. bool SetupWriteRccInfo();
  88. void AddGeneratedSource(std::string const& filename, GeneratorT genType);
  89. bool GetMocExecutable();
  90. bool GetUicExecutable();
  91. bool GetRccExecutable();
  92. bool RccListInputs(std::string const& fileName,
  93. std::vector<std::string>& files,
  94. std::string& errorMessage);
  95. private:
  96. cmQtAutoGenGlobalInitializer* GlobalInitializer;
  97. cmGeneratorTarget* Target;
  98. // Configuration
  99. IntegerVersion QtVersion;
  100. bool MultiConfig = false;
  101. std::string ConfigDefault;
  102. std::vector<std::string> ConfigsList;
  103. std::string Verbosity;
  104. std::string TargetsFolder;
  105. /// @brief Common directories
  106. struct
  107. {
  108. std::string Info;
  109. std::string Build;
  110. std::string Work;
  111. std::string Include;
  112. std::map<std::string, std::string> ConfigInclude;
  113. } Dir;
  114. /// @brief Autogen target variables
  115. struct
  116. {
  117. std::string Name;
  118. bool GlobalTarget = false;
  119. // Settings
  120. std::string Parallel;
  121. // Configuration files
  122. std::string InfoFile;
  123. std::string SettingsFile;
  124. std::map<std::string, std::string> ConfigSettingsFile;
  125. // Dependencies
  126. bool DependOrigin = false;
  127. std::set<std::string> DependFiles;
  128. std::set<cmTarget*> DependTargets;
  129. // Sources to process
  130. std::vector<std::string> Headers;
  131. std::vector<std::string> Sources;
  132. std::vector<std::string> HeadersGenerated;
  133. std::vector<std::string> SourcesGenerated;
  134. } AutogenTarget;
  135. /// @brief Moc only variables
  136. struct
  137. {
  138. bool Enabled = false;
  139. std::string Executable;
  140. std::string PredefsCmd;
  141. std::set<std::string> Skip;
  142. std::vector<std::string> Includes;
  143. std::map<std::string, std::vector<std::string>> ConfigIncludes;
  144. std::set<std::string> Defines;
  145. std::map<std::string, std::set<std::string>> ConfigDefines;
  146. std::string MocsCompilation;
  147. } Moc;
  148. ///@brief Uic only variables
  149. struct
  150. {
  151. bool Enabled = false;
  152. std::string Executable;
  153. std::set<std::string> Skip;
  154. std::vector<std::string> SearchPaths;
  155. std::vector<std::string> Options;
  156. std::map<std::string, std::vector<std::string>> ConfigOptions;
  157. std::vector<std::string> FileFiles;
  158. std::vector<std::vector<std::string>> FileOptions;
  159. } Uic;
  160. /// @brief Rcc only variables
  161. struct
  162. {
  163. bool Enabled = false;
  164. bool GlobalTarget = false;
  165. std::string Executable;
  166. std::vector<std::string> ListOptions;
  167. std::vector<Qrc> Qrcs;
  168. } Rcc;
  169. };
  170. #endif