cmQtAutoGen.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <memory>
  6. #include <string>
  7. #include <unordered_map>
  8. #include <vector>
  9. #include <cm/string_view>
  10. /** \class cmQtAutoGen
  11. * \brief Common base class for QtAutoGen classes
  12. */
  13. class cmQtAutoGen
  14. {
  15. public:
  16. /** String value with per configuration variants. */
  17. class ConfigString
  18. {
  19. public:
  20. std::string Default;
  21. std::unordered_map<std::string, std::string> Config;
  22. };
  23. /** String values with per configuration variants. */
  24. template <typename C>
  25. class ConfigStrings
  26. {
  27. public:
  28. C Default;
  29. std::unordered_map<std::string, C> Config;
  30. };
  31. /** Integer version. */
  32. struct IntegerVersion
  33. {
  34. unsigned int Major = 0;
  35. unsigned int Minor = 0;
  36. IntegerVersion() = default;
  37. IntegerVersion(unsigned int major, unsigned int minor)
  38. : Major(major)
  39. , Minor(minor)
  40. {
  41. }
  42. bool operator>(IntegerVersion const version) const
  43. {
  44. return (this->Major > version.Major) ||
  45. ((this->Major == version.Major) && (this->Minor > version.Minor));
  46. }
  47. bool operator>=(IntegerVersion const version) const
  48. {
  49. return (this->Major > version.Major) ||
  50. ((this->Major == version.Major) && (this->Minor >= version.Minor));
  51. }
  52. };
  53. /** Compiler features. */
  54. class CompilerFeatures
  55. {
  56. public:
  57. bool Evaluated = false;
  58. std::string HelpOutput;
  59. std::vector<std::string> ListOptions;
  60. };
  61. using CompilerFeaturesHandle = std::shared_ptr<CompilerFeatures>;
  62. /** AutoGen generator type. */
  63. enum class GenT
  64. {
  65. GEN, // AUTOGEN
  66. MOC, // AUTOMOC
  67. UIC, // AUTOUIC
  68. RCC // AUTORCC
  69. };
  70. /// @brief Maximum number of parallel threads/processes in a generator
  71. static unsigned int const ParallelMax;
  72. /// @brief Returns the generator name
  73. static cm::string_view GeneratorName(GenT genType);
  74. /// @brief Returns the generator name in upper case
  75. static cm::string_view GeneratorNameUpper(GenT genType);
  76. /// @brief Returns a string with the requested tool names
  77. static std::string Tools(bool moc, bool uic, bool rcc);
  78. /// @brief Returns the string escaped and enclosed in quotes
  79. static std::string Quoted(cm::string_view text);
  80. static std::string QuotedCommand(std::vector<std::string> const& command);
  81. /// @brief Returns the file name without path and extension (thread safe)
  82. static std::string FileNameWithoutLastExtension(cm::string_view filename);
  83. /// @brief Returns the parent directory of the file (thread safe)
  84. static std::string ParentDir(cm::string_view filename);
  85. /// @brief Returns the parent directory of the file with a "/" suffix
  86. static std::string SubDirPrefix(cm::string_view filename);
  87. /// @brief Appends the suffix to the filename before the last dot
  88. static std::string AppendFilenameSuffix(cm::string_view filename,
  89. cm::string_view suffix);
  90. /// @brief Merges newOpts into baseOpts
  91. static void UicMergeOptions(std::vector<std::string>& baseOpts,
  92. std::vector<std::string> const& newOpts,
  93. bool isQt5OrLater);
  94. /// @brief Merges newOpts into baseOpts
  95. static void RccMergeOptions(std::vector<std::string>& baseOpts,
  96. std::vector<std::string> const& newOpts,
  97. bool isQt5OrLater);
  98. /** @class RccLister
  99. * @brief Lists files in qrc resource files
  100. */
  101. class RccLister
  102. {
  103. public:
  104. RccLister();
  105. RccLister(std::string rccExecutable, std::vector<std::string> listOptions);
  106. //! The rcc executable
  107. std::string const& RccExcutable() const { return this->RccExcutable_; }
  108. void SetRccExecutable(std::string const& rccExecutable)
  109. {
  110. this->RccExcutable_ = rccExecutable;
  111. }
  112. //! The rcc executable list options
  113. std::vector<std::string> const& ListOptions() const
  114. {
  115. return this->ListOptions_;
  116. }
  117. void SetListOptions(std::vector<std::string> const& listOptions)
  118. {
  119. this->ListOptions_ = listOptions;
  120. }
  121. /**
  122. * @brief Lists a files in the qrcFile
  123. * @arg files The file names are appended to this list
  124. * @arg error contains the error message when the function fails
  125. */
  126. bool list(std::string const& qrcFile, std::vector<std::string>& files,
  127. std::string& error, bool verbose = false) const;
  128. private:
  129. std::string RccExcutable_;
  130. std::vector<std::string> ListOptions_;
  131. };
  132. };