Coverage Report

Created: 2026-09-14 06:43

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
    // Memoized GetMocBuildPath() result. Mutable because the info file
67
    // writer reaches this through const references.
68
    mutable std::string MocBuildPath;
69
  };
70
  using MUFileHandle = std::unique_ptr<MUFile>;
71
72
  /** Abstract moc/uic/rcc generator variables base class.  */
73
  struct GenVarsT
74
  {
75
    bool Enabled = false;
76
    // Generator type/name
77
    GenT Gen;
78
    cm::string_view GenNameUpper;
79
    // Executable
80
    std::string ExecutableTargetName;
81
    cmGeneratorTarget* ExecutableTarget = nullptr;
82
    ConfigString Executable;
83
    ConfigStrings<CompilerFeaturesHandle> ExecutableFeatures;
84
85
    GenVarsT(GenT gen)
86
0
      : Gen(gen)
87
0
      , GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen))
88
0
    {
89
0
    }
90
  };
91
92
  /** @param mocExecutable The file path to the moc executable. Will be used as
93
     fallback to query the version
94
      @return The detected Qt version and the required Qt major version. */
95
  static std::pair<IntegerVersion, unsigned int> GetQtVersion(
96
    cmGeneratorTarget const* genTarget, std::string mocExecutable);
97
98
  cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
99
                         cmGeneratorTarget* genTarget,
100
                         IntegerVersion qtVersion, bool mocEnabled,
101
                         bool uicEnabled, bool rccEnabled,
102
                         bool globalAutogenTarget, bool globalAutoRccTarget);
103
104
  bool InitCustomTargets();
105
  bool SetupCustomTargets();
106
107
private:
108
  /** If moc or uic is enabled, the autogen target will be generated.  */
109
  bool MocOrUicEnabled() const
110
0
  {
111
0
    return (this->Moc.Enabled || this->Uic.Enabled);
112
0
  }
113
114
  bool InitMoc();
115
  bool InitUic();
116
  bool InitRcc();
117
118
  bool InitScanFiles();
119
  bool InitAutogenTarget();
120
  bool InitRccTargets();
121
122
  bool SetupWriteAutogenInfo();
123
  bool SetupWriteRccInfo();
124
125
  cmSourceFile* RegisterGeneratedSource(std::string const& filename,
126
                                        bool scanForModules = false);
127
  cmSourceFile* AddGeneratedSource(std::string const& filename,
128
                                   GenVarsT const& genVars,
129
                                   bool prepend = false);
130
  void AddGeneratedSource(ConfigString const& filename,
131
                          GenVarsT const& genVars, bool prepend = false);
132
  void AddToSourceGroup(std::string const& fileName,
133
                        cm::string_view genNameUpper);
134
  void AddCMakeProcessToCommandLines(std::string const& infoFile,
135
                                     std::string const& processName,
136
                                     cmCustomCommandLines& commandLines);
137
  void AddCleanFile(std::string const& fileName);
138
139
  void ConfigFileNames(ConfigString& configString, cm::string_view prefix,
140
                       cm::string_view suffix);
141
  void ConfigFileNamesAndGenex(ConfigString& configString, std::string& genex,
142
                               cm::string_view prefix, cm::string_view suffix);
143
  void ConfigFileNameCommon(ConfigString& configString,
144
                            std::string const& fileName);
145
  void ConfigFileClean(ConfigString& configString);
146
147
  std::string const& GetMocBuildPath(MUFile const& muf);
148
149
  bool GetQtExecutable(GenVarsT& genVars, std::string const& executable,
150
                       bool ignoreMissingTarget) const;
151
152
  void handleSkipPch(cmSourceFile* sf);
153
  void AddAutogenExecutableToDependencies(
154
    cmQtAutoGenInitializer::GenVarsT const& genVars,
155
    std::vector<std::string>& dependencies) const;
156
157
  cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
158
  cmGeneratorTarget* GenTarget = nullptr;
159
  cmGlobalGenerator* GlobalGen = nullptr;
160
  cmLocalGenerator* LocalGen = nullptr;
161
  cmMakefile* Makefile = nullptr;
162
  cmFilePathChecksum const PathCheckSum;
163
164
  // -- Configuration
165
  IntegerVersion QtVersion;
166
  unsigned int Verbosity = 0;
167
  bool MultiConfig = false;
168
  bool CrossConfig = false;
169
  bool UseBetterGraph = false;
170
  bool CMP0071Accept = false;
171
  bool CMP0071Warn = false;
172
  bool CMP0100Accept = false;
173
  bool CMP0100Warn = false;
174
  std::string ConfigDefault;
175
  std::vector<std::string> ConfigsList;
176
  std::string TargetsFolder;
177
178
  /** Common directories.  */
179
  struct
180
  {
181
    std::string Info;
182
    std::string Build;
183
    std::string RelativeBuild;
184
    std::string Work;
185
    ConfigString Include;
186
    std::string IncludeGenExp;
187
  } Dir;
188
189
  /** Autogen target variables.  */
190
  struct
191
  {
192
    std::string Name;
193
    bool GlobalTarget = false;
194
    // Settings
195
    unsigned int Parallel = 1;
196
    unsigned int MaxCommandLineLength =
197
      std::numeric_limits<unsigned int>::max();
198
    // Configuration files
199
    std::string InfoFile;
200
    ConfigString SettingsFile;
201
    ConfigString ParseCacheFile;
202
    // Dependencies
203
    bool DependOrigin = false;
204
    std::set<std::string> DependFiles;
205
    std::set<cmTarget*> DependTargets;
206
    ConfigString DepFile;
207
    ConfigString DepFileRuleName;
208
    // Sources to process
209
    std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
210
    std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
211
    std::unordered_map<cmSourceFile*, MUFileHandle> ModuleUnits;
212
    std::vector<MUFile*> FilesGenerated;
213
    std::vector<cmSourceFile*> CMP0100HeadersWarn;
214
  } AutogenTarget;
215
216
  /** moc variables.  */
217
  struct MocT : public GenVarsT
218
  {
219
    MocT()
220
0
      : GenVarsT(GenT::MOC)
221
0
    {
222
0
    }
223
224
    bool RelaxedMode = false;
225
    bool PathPrefix = false;
226
    ConfigString CompilationFile;
227
    std::string CompilationFileGenex;
228
    // Compiler implicit pre defines
229
    std::vector<std::string> PredefsCmd;
230
    ConfigString PredefsFile;
231
    // Defines
232
    ConfigStrings<std::set<std::string>> Defines;
233
    // Includes
234
    ConfigStrings<std::vector<std::string>> Includes;
235
    // Options
236
    std::vector<std::string> Options;
237
    // Filters
238
    std::vector<std::string> MacroNames;
239
    std::vector<std::pair<std::string, std::string>> DependFilters;
240
    // Utility
241
    std::unordered_set<std::string> EmittedBuildPaths;
242
  } Moc;
243
244
  /** uic variables.  */
245
  struct UicT : public GenVarsT
246
  {
247
    using UiFileT = std::pair<std::string, std::vector<std::string>>;
248
249
    UicT()
250
0
      : GenVarsT(GenT::UIC)
251
0
    {
252
0
    }
253
254
    std::set<std::string> SkipUi;
255
    std::vector<std::string> UiFilesNoOptions;
256
    std::vector<UiFileT> UiFilesWithOptions;
257
    ConfigStrings<std::vector<std::string>> Options;
258
    std::vector<std::string> SearchPaths;
259
    std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>>
260
      UiHeaders;
261
  } Uic;
262
263
  /** rcc variables.  */
264
  struct RccT : public GenVarsT
265
  {
266
    RccT()
267
0
      : GenVarsT(GenT::RCC)
268
0
    {
269
0
    }
270
271
    bool GlobalTarget = false;
272
    std::vector<Qrc> Qrcs;
273
  } Rcc;
274
};