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