Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmQtAutoGenInitializer.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 <cstddef>
8
#include <limits>
9
#include <memory>
10
#include <set>
11
#include <string>
12
#include <unordered_map>
13
#include <unordered_set>
14
#include <utility>
15
#include <vector>
16
17
#include <cm/string_view>
18
19
#include "cmFilePathChecksum.h"
20
#include "cmQtAutoGen.h"
21
22
class cmCustomCommandLines;
23
class cmGeneratorTarget;
24
class cmGlobalGenerator;
25
class cmLocalGenerator;
26
class cmMakefile;
27
class cmQtAutoGenGlobalInitializer;
28
class cmSourceFile;
29
class cmTarget;
30
31
/** \class cmQtAutoGenerator
32
 * \brief Initializes the QtAutoGen generators
33
 */
34
class cmQtAutoGenInitializer : public cmQtAutoGen
35
{
36
public:
37
  /** rcc job.  */
38
  class Qrc
39
  {
40
  public:
41
    std::string LockFile;
42
    std::string QrcFile;
43
    std::string QrcName;
44
    std::string QrcPathChecksum;
45
    std::string InfoFile;
46
    ConfigString SettingsFile;
47
    ConfigString OutputFile;
48
    std::string OutputFileGenex;
49
    bool Generated = false;
50
    bool Unique = false;
51
    std::vector<std::string> Options;
52
    ConfigStrings<std::vector<std::string>> Resources;
53
  };
54
55
  /** moc and/or uic file.  */
56
  struct MUFile
57
  {
58
    std::string FullPath;
59
    cmSourceFile* SF = nullptr;
60
    std::vector<size_t> Configs;
61
    bool Generated = false;
62
    bool SkipMoc = false;
63
    bool SkipUic = false;
64
    bool MocIt = false;
65
    bool UicIt = false;
66
  };
67
  using MUFileHandle = std::unique_ptr<MUFile>;
68
69
  /** Abstract moc/uic/rcc generator variables base class.  */
70
  struct GenVarsT
71
  {
72
    bool Enabled = false;
73
    // Generator type/name
74
    GenT Gen;
75
    cm::string_view GenNameUpper;
76
    // Executable
77
    std::string ExecutableTargetName;
78
    cmGeneratorTarget* ExecutableTarget = nullptr;
79
    ConfigString Executable;
80
    ConfigStrings<CompilerFeaturesHandle> ExecutableFeatures;
81
82
    GenVarsT(GenT gen)
83
0
      : Gen(gen)
84
0
      , GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen))
85
0
    {
86
0
    }
87
  };
88
89
  /** @param mocExecutable The file path to the moc executable. Will be used as
90
     fallback to query the version
91
      @return The detected Qt version and the required Qt major version. */
92
  static std::pair<IntegerVersion, unsigned int> GetQtVersion(
93
    cmGeneratorTarget const* genTarget, std::string mocExecutable);
94
95
  cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
96
                         cmGeneratorTarget* genTarget,
97
                         IntegerVersion qtVersion, bool mocEnabled,
98
                         bool uicEnabled, bool rccEnabled,
99
                         bool globalAutogenTarget, bool globalAutoRccTarget);
100
101
  bool InitCustomTargets();
102
  bool SetupCustomTargets();
103
104
private:
105
  /** If moc or uic is enabled, the autogen target will be generated.  */
106
  bool MocOrUicEnabled() const
107
0
  {
108
0
    return (this->Moc.Enabled || this->Uic.Enabled);
109
0
  }
110
111
  bool InitMoc();
112
  bool InitUic();
113
  bool InitRcc();
114
115
  bool InitScanFiles();
116
  bool InitAutogenTarget();
117
  bool InitRccTargets();
118
119
  bool SetupWriteAutogenInfo();
120
  bool SetupWriteRccInfo();
121
122
  cmSourceFile* RegisterGeneratedSource(std::string const& filename);
123
  cmSourceFile* AddGeneratedSource(std::string const& filename,
124
                                   GenVarsT const& genVars,
125
                                   bool prepend = false);
126
  void AddGeneratedSource(ConfigString const& filename,
127
                          GenVarsT const& genVars, bool prepend = false);
128
  void AddToSourceGroup(std::string const& fileName,
129
                        cm::string_view genNameUpper);
130
  void AddCMakeProcessToCommandLines(std::string const& infoFile,
131
                                     std::string const& processName,
132
                                     cmCustomCommandLines& commandLines);
133
  void AddCleanFile(std::string const& fileName);
134
135
  void ConfigFileNames(ConfigString& configString, cm::string_view prefix,
136
                       cm::string_view suffix);
137
  void ConfigFileNamesAndGenex(ConfigString& configString, std::string& genex,
138
                               cm::string_view prefix, cm::string_view suffix);
139
  void ConfigFileNameCommon(ConfigString& configString,
140
                            std::string const& fileName);
141
  void ConfigFileClean(ConfigString& configString);
142
143
  std::string GetMocBuildPath(MUFile const& muf);
144
145
  bool GetQtExecutable(GenVarsT& genVars, std::string const& executable,
146
                       bool ignoreMissingTarget) const;
147
148
  void handleSkipPch(cmSourceFile* sf);
149
  void AddAutogenExecutableToDependencies(
150
    cmQtAutoGenInitializer::GenVarsT const& genVars,
151
    std::vector<std::string>& dependencies) const;
152
153
  cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
154
  cmGeneratorTarget* GenTarget = nullptr;
155
  cmGlobalGenerator* GlobalGen = nullptr;
156
  cmLocalGenerator* LocalGen = nullptr;
157
  cmMakefile* Makefile = nullptr;
158
  cmFilePathChecksum const PathCheckSum;
159
160
  // -- Configuration
161
  IntegerVersion QtVersion;
162
  unsigned int Verbosity = 0;
163
  bool MultiConfig = false;
164
  bool CrossConfig = false;
165
  bool UseBetterGraph = false;
166
  bool CMP0071Accept = false;
167
  bool CMP0071Warn = false;
168
  bool CMP0100Accept = false;
169
  bool CMP0100Warn = false;
170
  std::string ConfigDefault;
171
  std::vector<std::string> ConfigsList;
172
  std::string TargetsFolder;
173
174
  /** Common directories.  */
175
  struct
176
  {
177
    std::string Info;
178
    std::string Build;
179
    std::string RelativeBuild;
180
    std::string Work;
181
    ConfigString Include;
182
    std::string IncludeGenExp;
183
  } Dir;
184
185
  /** Autogen target variables.  */
186
  struct
187
  {
188
    std::string Name;
189
    bool GlobalTarget = false;
190
    // Settings
191
    unsigned int Parallel = 1;
192
    unsigned int MaxCommandLineLength =
193
      std::numeric_limits<unsigned int>::max();
194
    // Configuration files
195
    std::string InfoFile;
196
    ConfigString SettingsFile;
197
    ConfigString ParseCacheFile;
198
    // Dependencies
199
    bool DependOrigin = false;
200
    std::set<std::string> DependFiles;
201
    std::set<cmTarget*> DependTargets;
202
    ConfigString DepFile;
203
    ConfigString DepFileRuleName;
204
    // Sources to process
205
    std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
206
    std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
207
    std::vector<MUFile*> FilesGenerated;
208
    std::vector<cmSourceFile*> CMP0100HeadersWarn;
209
  } AutogenTarget;
210
211
  /** moc variables.  */
212
  struct MocT : public GenVarsT
213
  {
214
    MocT()
215
0
      : GenVarsT(GenT::MOC)
216
0
    {
217
0
    }
218
219
    bool RelaxedMode = false;
220
    bool PathPrefix = false;
221
    ConfigString CompilationFile;
222
    std::string CompilationFileGenex;
223
    // Compiler implicit pre defines
224
    std::vector<std::string> PredefsCmd;
225
    ConfigString PredefsFile;
226
    // Defines
227
    ConfigStrings<std::set<std::string>> Defines;
228
    // Includes
229
    ConfigStrings<std::vector<std::string>> Includes;
230
    // Options
231
    std::vector<std::string> Options;
232
    // Filters
233
    std::vector<std::string> MacroNames;
234
    std::vector<std::pair<std::string, std::string>> DependFilters;
235
    // Utility
236
    std::unordered_set<std::string> EmittedBuildPaths;
237
  } Moc;
238
239
  /** uic variables.  */
240
  struct UicT : public GenVarsT
241
  {
242
    using UiFileT = std::pair<std::string, std::vector<std::string>>;
243
244
    UicT()
245
0
      : GenVarsT(GenT::UIC)
246
0
    {
247
0
    }
248
249
    std::set<std::string> SkipUi;
250
    std::vector<std::string> UiFilesNoOptions;
251
    std::vector<UiFileT> UiFilesWithOptions;
252
    ConfigStrings<std::vector<std::string>> Options;
253
    std::vector<std::string> SearchPaths;
254
    std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>>
255
      UiHeaders;
256
  } Uic;
257
258
  /** rcc variables.  */
259
  struct RccT : public GenVarsT
260
  {
261
    RccT()
262
0
      : GenVarsT(GenT::RCC)
263
0
    {
264
0
    }
265
266
    bool GlobalTarget = false;
267
    std::vector<Qrc> Qrcs;
268
  } Rcc;
269
};