summaryrefslogtreecommitdiffstats
path: root/Source/cmQtAutoGen.h
blob: e62a947dbae371b72fd7479479ed87d83af9d1cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#ifndef cmQtAutoGen_h
#define cmQtAutoGen_h

#include "cmConfigure.h" // IWYU pragma: keep

#include <string>
#include <vector>

/** \class cmQtAutoGen
 * \brief Common base class for QtAutoGen classes
 */
class cmQtAutoGen
{
public:
  /// @brief Integer version
  struct IntegerVersion
  {
    unsigned int Major = 0;
    unsigned int Minor = 0;

    IntegerVersion() = default;
    IntegerVersion(unsigned int major, unsigned int minor)
      : Major(major)
      , Minor(minor)
    {
    }

    bool operator>(IntegerVersion const version)
    {
      return (this->Major > version.Major) ||
        ((this->Major == version.Major) && (this->Minor > version.Minor));
    }

    bool operator>=(IntegerVersion const version)
    {
      return (this->Major > version.Major) ||
        ((this->Major == version.Major) && (this->Minor >= version.Minor));
    }
  };

  /// @brief AutoGen generator type
  enum class GenT
  {
    GEN, // AUTOGEN
    MOC, // AUTOMOC
    UIC, // AUTOUIC
    RCC  // AUTORCC
  };

  /// @brief Nested lists separator
  static std::string const ListSep;
  // Generator names
  static std::string const GenNameGen;
  static std::string const GenNameMoc;
  static std::string const GenNameUic;
  static std::string const GenNameRcc;
  static std::string const GenNameGenUpper;
  static std::string const GenNameMocUpper;
  static std::string const GenNameUicUpper;
  static std::string const GenNameRccUpper;
  /// @brief Maximum number of parallel threads/processes in a generator
  static unsigned int const ParallelMax;

public:
  /// @brief Returns the generator name
  static std::string const& GeneratorName(GenT genType);
  /// @brief Returns the generator name in upper case
  static std::string const& GeneratorNameUpper(GenT genType);

  /// @brief Returns a string with the requested tool names
  static std::string Tools(bool moc, bool uic, bool rcc);

  /// @brief Returns the string escaped and enclosed in quotes
  static std::string Quoted(std::string const& text);

  static std::string QuotedCommand(std::vector<std::string> const& command);

  /// @brief Returns the parent directory of the file with a "/" suffix
  static std::string SubDirPrefix(std::string const& filename);

  /// @brief Appends the suffix to the filename before the last dot
  static std::string AppendFilenameSuffix(std::string const& filename,
                                          std::string const& suffix);

  /// @brief Merges newOpts into baseOpts
  static void UicMergeOptions(std::vector<std::string>& baseOpts,
                              std::vector<std::string> const& newOpts,
                              bool isQt5);

  /// @brief Merges newOpts into baseOpts
  static void RccMergeOptions(std::vector<std::string>& baseOpts,
                              std::vector<std::string> const& newOpts,
                              bool isQt5);

  /// @brief Parses the content of a qrc file
  ///
  /// Use when rcc does not support the "--list" option
  static void RccListParseContent(std::string const& content,
                                  std::vector<std::string>& files);

  /// @brief Parses the output of the "rcc --list ..." command
  static bool RccListParseOutput(std::string const& rccStdOut,
                                 std::string const& rccStdErr,
                                 std::vector<std::string>& files,
                                 std::string& error);

  /// @brief Converts relative qrc entry paths to full paths
  static void RccListConvertFullPath(std::string const& qrcFileDir,
                                     std::vector<std::string>& files);
};

#endif