cmQtAutoGen.h 4.1 KB

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