cmQtAutoGenInitializer.h 5.5 KB

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