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