resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmQtAutoGen.h
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;
26     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 #ifdef _WIN32
68   /// @brief Maximum number of characters on command line
69   static size_t const CommandLineLengthMax;
70 #endif
71
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
77   /// @brief Returns a string with the requested tool names
78   static std::string Tools(bool moc, bool uic, bool rcc);
79
80   /// @brief Returns the string escaped and enclosed in quotes
81   static std::string Quoted(cm::string_view text);
82
83   static std::string QuotedCommand(std::vector<std::string> const& command);
84
85   /// @brief Returns the file name without path and extension (thread safe)
86   static std::string FileNameWithoutLastExtension(cm::string_view filename);
87
88   /// @brief Returns the parent directory of the file (thread safe)
89   static std::string ParentDir(cm::string_view filename);
90
91   /// @brief Returns the parent directory of the file with a "/" suffix
92   static std::string SubDirPrefix(cm::string_view filename);
93
94   /// @brief Appends the suffix to the filename before the last dot
95   static std::string AppendFilenameSuffix(cm::string_view filename,
96                                           cm::string_view suffix);
97
98   /// @brief Merges newOpts into baseOpts
99   static void UicMergeOptions(std::vector<std::string>& baseOpts,
100                               std::vector<std::string> const& newOpts,
101                               bool isQt5OrLater);
102
103   /// @brief Merges newOpts into baseOpts
104   static void RccMergeOptions(std::vector<std::string>& baseOpts,
105                               std::vector<std::string> const& newOpts,
106                               bool isQt5OrLater);
107
108   /** @class RccLister
109    * @brief Lists files in qrc resource files
110    */
111   class RccLister
112   {
113   public:
114     RccLister();
115     RccLister(std::string rccExecutable, std::vector<std::string> listOptions);
116
117     //! The rcc executable
118     std::string const& RccExcutable() const { return this->RccExcutable_; }
119     void SetRccExecutable(std::string const& rccExecutable)
120     {
121       this->RccExcutable_ = rccExecutable;
122     }
123
124     //! The rcc executable list options
125     std::vector<std::string> const& ListOptions() const
126     {
127       return this->ListOptions_;
128     }
129     void SetListOptions(std::vector<std::string> const& listOptions)
130     {
131       this->ListOptions_ = listOptions;
132     }
133
134     /**
135      * @brief Lists a files in the qrcFile
136      * @arg files The file names are appended to this list
137      * @arg error contains the error message when the function fails
138      */
139     bool list(std::string const& qrcFile, std::vector<std::string>& files,
140               std::string& error, bool verbose = false) const;
141
142   private:
143     std::string RccExcutable_;
144     std::vector<std::string> ListOptions_;
145   };
146 };