cmQtAutoGen.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. /// @brief Returns the generator name
  57. static cm::string_view GeneratorName(GenT genType);
  58. /// @brief Returns the generator name in upper case
  59. static cm::string_view GeneratorNameUpper(GenT genType);
  60. /// @brief Returns a string with the requested tool names
  61. static std::string Tools(bool moc, bool uic, bool rcc);
  62. /// @brief Returns the string escaped and enclosed in quotes
  63. static std::string Quoted(cm::string_view text);
  64. static std::string QuotedCommand(std::vector<std::string> const& command);
  65. /// @brief Returns the file name without path and extension (thread safe)
  66. static std::string FileNameWithoutLastExtension(cm::string_view filename);
  67. /// @brief Returns the parent directory of the file (thread safe)
  68. static std::string ParentDir(cm::string_view filename);
  69. /// @brief Returns the parent directory of the file with a "/" suffix
  70. static std::string SubDirPrefix(cm::string_view filename);
  71. /// @brief Appends the suffix to the filename before the last dot
  72. static std::string AppendFilenameSuffix(cm::string_view filename,
  73. cm::string_view suffix);
  74. /// @brief Merges newOpts into baseOpts
  75. static void UicMergeOptions(std::vector<std::string>& baseOpts,
  76. std::vector<std::string> const& newOpts,
  77. bool isQt5);
  78. /// @brief Merges newOpts into baseOpts
  79. static void RccMergeOptions(std::vector<std::string>& baseOpts,
  80. std::vector<std::string> const& newOpts,
  81. bool isQt5);
  82. static bool FileRead(std::string& content, std::string const& filename,
  83. std::string* error = nullptr);
  84. /** @class RccLister
  85. * @brief Lists files in qrc resource files
  86. */
  87. class RccLister
  88. {
  89. public:
  90. RccLister();
  91. RccLister(std::string rccExecutable, std::vector<std::string> listOptions);
  92. //! The rcc executable
  93. std::string const& RccExcutable() const { return this->RccExcutable_; }
  94. void SetRccExecutable(std::string const& rccExecutable)
  95. {
  96. this->RccExcutable_ = rccExecutable;
  97. }
  98. //! The rcc executable list options
  99. std::vector<std::string> const& ListOptions() const
  100. {
  101. return this->ListOptions_;
  102. }
  103. void SetListOptions(std::vector<std::string> const& listOptions)
  104. {
  105. this->ListOptions_ = listOptions;
  106. }
  107. /**
  108. * @brief Lists a files in the qrcFile
  109. * @arg files The file names are appended to this list
  110. * @arg error contains the error message when the function fails
  111. */
  112. bool list(std::string const& qrcFile, std::vector<std::string>& files,
  113. std::string& error, bool verbose = false) const;
  114. private:
  115. std::string RccExcutable_;
  116. std::vector<std::string> ListOptions_;
  117. };
  118. };