Coverage Report

Created: 2026-06-15 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmLocalGenerator.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 <iosfwd>
9
#include <map>
10
#include <memory>
11
#include <set>
12
#include <string>
13
#include <unordered_map>
14
#include <utility>
15
#include <vector>
16
17
#include <cm/optional>
18
#include <cm/string_view>
19
20
#include "cmCustomCommandTypes.h"
21
#include "cmDiagnosticContext.h"
22
#include "cmDiagnostics.h"
23
#include "cmGeneratorOptions.h"
24
#include "cmGeneratorTarget.h"
25
#include "cmListFileCache.h"
26
#include "cmMessageType.h" // IWYU pragma: keep
27
#include "cmOutputConverter.h"
28
#include "cmPolicies.h"
29
#include "cmStateSnapshot.h"
30
#include "cmStateTypes.h"
31
#include "cmValue.h"
32
33
class cmCompiledGeneratorExpression;
34
class cmComputeLinkInformation;
35
class cmCustomCommand;
36
class cmCustomCommandGenerator;
37
class cmCustomCommandLines;
38
class cmGlobalGenerator;
39
class cmImplicitDependsList;
40
class cmLinkLineComputer;
41
class cmLinkLineDeviceComputer;
42
class cmMakefile;
43
struct cmObjectLocation;
44
struct cmObjectLocations;
45
class cmRulePlaceholderExpander;
46
class cmSourceFile;
47
class cmSourceGroup;
48
class cmState;
49
class cmTarget;
50
class cmake;
51
52
template <typename Iter>
53
class cmRange;
54
55
/** Target and source file which have a specific output.  */
56
struct cmSourcesWithOutput
57
{
58
  /** Target with byproduct.  */
59
  cmTarget* Target = nullptr;
60
61
  /** Source file with output or byproduct.  */
62
  cmSourceFile* Source = nullptr;
63
  bool SourceIsByproduct = false;
64
};
65
66
/** \class cmLocalGenerator
67
 * \brief Create required build files for a directory.
68
 *
69
 * Subclasses of this abstract class generate makefiles, DSP, etc for various
70
 * platforms. This class should never be constructed directly. A
71
 * GlobalGenerator will create it and invoke the appropriate commands on it.
72
 */
73
class cmLocalGenerator : public cmOutputConverter
74
{
75
public:
76
  cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile);
77
  ~cmLocalGenerator() override;
78
79
  /**
80
   * Generate the makefile for this directory.
81
   */
82
0
  virtual void Generate() {}
83
84
0
  virtual void ComputeHomeRelativeOutputPath() {}
85
86
  /**
87
   * Calls TraceVSDependencies() on all targets of this generator.
88
   */
89
  void TraceDependencies() const;
90
91
#ifndef CMAKE_BOOTSTRAP
92
  /**
93
   * Resolve source group genex.
94
   */
95
  void ResolveSourceGroupGenex();
96
#endif
97
98
0
  virtual void AddHelperCommands() {}
99
100
  /**
101
   * Generate the install rules files in this directory.
102
   */
103
  void GenerateInstallRules();
104
105
  /**
106
   * Generate the test files for tests.
107
   */
108
  void GenerateTestFiles();
109
110
  /**
111
   * Generate a manifest of target files that will be built.
112
   */
113
  void ComputeTargetManifest();
114
115
  bool ComputeTargetCompileFeatures();
116
117
  bool IsRootMakefile() const;
118
119
  //! Get the makefile for this generator
120
0
  cmMakefile* GetMakefile() const { return this->Makefile; }
121
122
  //! Get the GlobalGenerator this is associated with
123
0
  cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }
124
  cmGlobalGenerator const* GetGlobalGenerator() const
125
0
  {
126
0
    return this->GlobalGenerator;
127
0
  }
128
129
  virtual std::unique_ptr<cmRulePlaceholderExpander>
130
  CreateRulePlaceholderExpander(
131
    cmBuildStep buildStep = cmBuildStep::Compile) const;
132
133
  std::string GetExeExportFlags(std::string const& linkLanguage,
134
                                cmGeneratorTarget& tgt) const;
135
136
  cmState* GetState() const;
137
  cmStateSnapshot GetStateSnapshot() const;
138
139
  void AddArchitectureFlags(std::string& flags,
140
                            cmGeneratorTarget const* target,
141
                            std::string const& lang, std::string const& config,
142
                            std::string const& filterArch = std::string());
143
144
  void AddLanguageFlags(std::string& flags, cmGeneratorTarget const* target,
145
                        cmBuildStep compileOrLink, std::string const& lang,
146
                        std::string const& config);
147
  void AddLanguageFlagsForLinking(std::string& flags,
148
                                  cmGeneratorTarget const* target,
149
                                  std::string const& lang,
150
                                  std::string const& config);
151
  void AddFeatureFlags(std::string& flags, cmGeneratorTarget const* target,
152
                       std::string const& lang, std::string const& config);
153
  void AddVisibilityPresetFlags(std::string& flags,
154
                                cmGeneratorTarget const* target,
155
                                std::string const& lang);
156
  void AddConfigVariableFlags(std::string& flags, std::string const& var,
157
                              std::string const& config);
158
  // Handle prefixes processing (like LINKER:)
159
  void AddConfigVariableFlags(std::string& flags, std::string const& var,
160
                              cmGeneratorTarget const* target,
161
                              cmBuildStep compileOrLink,
162
                              std::string const& lang,
163
                              std::string const& config);
164
  void AddColorDiagnosticsFlags(std::string& flags, std::string const& lang);
165
  //! Append flags to a string.
166
  virtual void AppendFlags(std::string& flags,
167
                           std::string const& newFlags) const;
168
  virtual void AppendFlags(std::string& flags,
169
                           std::vector<BT<std::string>> const& newFlags) const;
170
  virtual void AppendFlagEscape(std::string& flags,
171
                                std::string const& rawFlag) const;
172
  /**
173
   * Append flags after parsing, prefixes processing (like LINKER:) and
174
   * escaping
175
   */
176
  void AppendLinkFlagsWithParsing(std::string& flags,
177
                                  std::string const& newFlags,
178
                                  cmGeneratorTarget const* target,
179
                                  std::string const& lang);
180
  void AppendFlags(std::string& flags, std::string const& newFlags,
181
                   std::string const& name, cmGeneratorTarget const* target,
182
                   cmBuildStep compileOrLink, std::string const& lang);
183
  void AddISPCDependencies(cmGeneratorTarget* target);
184
  void AddPchDependencies(cmGeneratorTarget* target);
185
  void AddUnityBuild(cmGeneratorTarget* target);
186
0
  virtual void AddXCConfigSources(cmGeneratorTarget* /* target */) {}
187
  void AddPerLanguageLinkFlags(std::string& flags,
188
                               cmGeneratorTarget const* target,
189
                               std::string const& lang,
190
                               std::string const& config);
191
  void AppendTargetCreationLinkFlags(std::string& flags,
192
                                     cmGeneratorTarget const* target,
193
                                     std::string const& linkLanguage);
194
  void AppendLinkerTypeFlags(std::string& flags, cmGeneratorTarget* target,
195
                             std::string const& config,
196
                             std::string const& linkLanguage);
197
  void AddTargetTypeLinkerFlags(std::string& flags,
198
                                cmGeneratorTarget const* target,
199
                                std::string const& lang,
200
                                std::string const& config);
201
  void AddTargetPropertyLinkFlags(std::string& flags,
202
                                  cmGeneratorTarget const* target,
203
                                  std::string const& config);
204
  void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target,
205
                            std::string const& config,
206
                            std::string const& lang);
207
  void AppendPositionIndependentLinkerFlags(std::string& flags,
208
                                            cmGeneratorTarget* target,
209
                                            std::string const& config,
210
                                            std::string const& lang);
211
  void AppendWarningAsErrorLinkerFlags(std::string& flags,
212
                                       cmGeneratorTarget* target,
213
                                       std::string const& lang);
214
  void AppendDependencyInfoLinkerFlags(std::string& flags,
215
                                       cmGeneratorTarget* target,
216
                                       std::string const& config,
217
                                       std::string const& lang);
218
  virtual std::string GetLinkDependencyFile(cmGeneratorTarget* target,
219
                                            std::string const& config) const;
220
  void AppendModuleDefinitionFlag(std::string& flags,
221
                                  cmGeneratorTarget const* target,
222
                                  cmLinkLineComputer* linkLineComputer,
223
                                  std::string const& config,
224
                                  std::string const& lang);
225
  bool AppendLWYUFlags(std::string& flags, cmGeneratorTarget const* target,
226
                       std::string const& lang);
227
228
  //! Get the include flags for the current makefile and language
229
  std::string GetIncludeFlags(std::vector<std::string> const& includes,
230
                              cmGeneratorTarget* target,
231
                              std::string const& lang,
232
                              std::string const& config,
233
                              bool forResponseFile = false);
234
235
  using GeneratorTargetVector =
236
    std::vector<std::unique_ptr<cmGeneratorTarget>>;
237
  GeneratorTargetVector const& GetGeneratorTargets() const
238
0
  {
239
0
    return this->GeneratorTargets;
240
0
  }
241
242
  GeneratorTargetVector const& GetOwnedImportedGeneratorTargets() const
243
0
  {
244
0
    return this->OwnedImportedGeneratorTargets;
245
0
  }
246
247
  void AddGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
248
  void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
249
  void AddOwnedImportedGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
250
251
  cmGeneratorTarget* FindLocalNonAliasGeneratorTarget(
252
    std::string const& name) const;
253
  cmGeneratorTarget* FindGeneratorTargetToUse(std::string const& name) const;
254
255
  /**
256
   * Process a list of include directories
257
   */
258
  void AppendIncludeDirectories(std::vector<std::string>& includes,
259
                                std::string const& includes_list,
260
                                cmSourceFile const& sourceFile) const;
261
  void AppendIncludeDirectories(std::vector<std::string>& includes,
262
                                std::vector<std::string> const& includes_vec,
263
                                cmSourceFile const& sourceFile) const;
264
265
  /**
266
   * Encode a list of preprocessor definitions for the compiler
267
   * command line.
268
   */
269
  void AppendDefines(std::set<std::string>& defines,
270
                     std::string const& defines_list) const;
271
  void AppendDefines(std::set<std::string>& defines,
272
                     std::vector<BT<std::string>> const& defines_vec) const;
273
  void AppendDefines(std::set<BT<std::string>>& defines,
274
                     std::string const& defines_list) const;
275
  void AppendDefines(std::set<BT<std::string>>& defines,
276
                     std::vector<BT<std::string>> const& defines_vec) const;
277
278
  /**
279
   * Encode a list of compile options for the compiler
280
   * command line.
281
   */
282
  void AppendCompileOptions(std::string& options,
283
                            std::string const& options_list,
284
                            char const* regex = nullptr) const;
285
  void AppendCompileOptions(std::string& options,
286
                            std::vector<std::string> const& options_vec,
287
                            char const* regex = nullptr) const;
288
  void AppendCompileOptions(std::vector<BT<std::string>>& options,
289
                            std::vector<BT<std::string>> const& options_vec,
290
                            char const* regex = nullptr) const;
291
292
  /**
293
   * Join a set of defines into a definesString with a space separator.
294
   */
295
  void JoinDefines(std::set<std::string> const& defines,
296
                   std::string& definesString, std::string const& lang);
297
298
  /** Lookup and append options associated with a particular feature.  */
299
  void AppendFeatureOptions(std::string& flags, std::string const& lang,
300
                            char const* feature);
301
302
  cmValue GetFeature(std::string const& feature, std::string const& config);
303
304
  /** \brief Get absolute path to dependency \a name
305
   *
306
   * Translate a dependency as given in CMake code to the name to
307
   * appear in a generated build file.
308
   * - If \a name is a utility target, returns false.
309
   * - If \a name is a CMake target, it will be transformed to the real output
310
   *   location of that target for the given configuration.
311
   * - If \a name is the full path to a file, it will be returned.
312
   * - Otherwise \a name is treated as a relative path with respect to
313
   *   the source directory of this generator.  This should only be
314
   *   used for dependencies of custom commands.
315
   */
316
  bool GetRealDependency(std::string const& name, std::string const& config,
317
                         std::string& dep, cmPolicies::PolicyStatus cmp0212);
318
319
  /** Called from command-line hook to clear dependencies.  */
320
0
  virtual void ClearDependencies(cmMakefile* /* mf */, bool /* verbose */) {}
321
322
  /** Called from command-line hook to update dependencies.  */
323
  virtual bool UpdateDependencies(std::string const& /* tgtInfo */,
324
                                  std::string const& /* targetName */,
325
                                  bool /*verbose*/, bool /*color*/)
326
0
  {
327
0
    return true;
328
0
  }
329
330
  /** @brief Get the include directories for the current makefile and language
331
   * and optional the compiler implicit include directories.
332
   *
333
   * @arg stripImplicitDirs Strip all directories found in
334
   *      CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES from the result.
335
   * @arg appendAllImplicitDirs Append all directories found in
336
   *      CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES to the result.
337
   */
338
  std::vector<BT<std::string>> GetIncludeDirectoriesImplicit(
339
    cmGeneratorTarget const* target, std::string const& lang = "C",
340
    std::string const& config = "", bool stripImplicitDirs = true,
341
    bool appendAllImplicitDirs = false) const;
342
343
  /** @brief Get the include directories for the current makefile and language
344
   * and optional the compiler implicit include directories.
345
   *
346
   * @arg dirs Directories are appended to this list
347
   */
348
  void GetIncludeDirectoriesImplicit(std::vector<std::string>& dirs,
349
                                     cmGeneratorTarget const* target,
350
                                     std::string const& lang = "C",
351
                                     std::string const& config = "",
352
                                     bool stripImplicitDirs = true,
353
                                     bool appendAllImplicitDirs = false) const;
354
355
  /** @brief Get the include directories for the current makefile and language.
356
   * @arg dirs Include directories are appended to this list
357
   */
358
  void GetIncludeDirectories(std::vector<std::string>& dirs,
359
                             cmGeneratorTarget const* target,
360
                             std::string const& lang = "C",
361
                             std::string const& config = "") const;
362
363
  /** @brief Get the include directories for the current makefile and language.
364
   * @return The include directory list
365
   */
366
  std::vector<BT<std::string>> GetIncludeDirectories(
367
    cmGeneratorTarget const* target, std::string const& lang = "C",
368
    std::string const& config = "") const;
369
370
  void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
371
                         std::string const& lang, std::string const& config);
372
  void AddCompileOptions(std::vector<BT<std::string>>& flags,
373
                         cmGeneratorTarget* target, std::string const& lang,
374
                         std::string const& config);
375
376
  /**
377
   * Add a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a target.
378
   */
379
  cmTarget* AddCustomCommandToTarget(
380
    std::string const& target, cmCustomCommandType type,
381
    std::unique_ptr<cmCustomCommand> cc,
382
    cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject);
383
384
  /**
385
   * Add a custom command to a source file.
386
   */
387
  cmSourceFile* AddCustomCommandToOutput(std::unique_ptr<cmCustomCommand> cc,
388
                                         bool replace = false);
389
390
  /**
391
   * Add a utility to the build.  A utility target is a command that is run
392
   * every time the target is built.
393
   */
394
  cmTarget* AddUtilityCommand(std::string const& utilityName,
395
                              bool excludeFromAll,
396
                              std::unique_ptr<cmCustomCommand> cc);
397
398
  virtual std::string CreateUtilityOutput(
399
    std::string const& targetName, std::vector<std::string> const& byproducts,
400
    cmListFileBacktrace const& bt);
401
402
  virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
403
    cmCustomCommand const& cc, std::string const& config);
404
405
  std::vector<std::string> ExpandCustomCommandOutputPaths(
406
    cmCompiledGeneratorExpression const& cge, std::string const& config);
407
  std::vector<std::string> ExpandCustomCommandOutputGenex(
408
    std::string const& o, cmListFileBacktrace const& bt);
409
410
  /**
411
   * Add target byproducts.
412
   */
413
  void AddTargetByproducts(cmTarget* target,
414
                           std::vector<std::string> const& byproducts,
415
                           cmListFileBacktrace const& bt,
416
                           cmCommandOrigin origin);
417
418
  enum class OutputRole
419
  {
420
    Primary,
421
    Byproduct,
422
  };
423
424
  /**
425
   * Add source file outputs.
426
   */
427
  void AddSourceOutputs(cmSourceFile* source,
428
                        std::vector<std::string> const& outputs,
429
                        OutputRole role, cmListFileBacktrace const& bt,
430
                        cmCommandOrigin origin);
431
432
  /**
433
   * Return the target if the provided source name is a byproduct of a utility
434
   * target or a PRE_BUILD, PRE_LINK, or POST_BUILD command.
435
   * Return the source file which has the provided source name as output.
436
   */
437
  cmSourcesWithOutput GetSourcesWithOutput(std::string const& name) const;
438
439
  /**
440
   * Is there a source file that has the provided source name as an output?
441
   * If so then return it.
442
   */
443
  cmSourceFile* GetSourceFileWithOutput(
444
    std::string const& name,
445
    cmSourceOutputKind kind = cmSourceOutputKind::OutputOnly) const;
446
447
  std::string GetProjectName() const;
448
449
  /** Compute the language used to compile the given source file.  */
450
  std::string GetSourceFileLanguage(cmSourceFile const& source);
451
452
  // Fill the vector with the target names for the object files,
453
  // preprocessed files and assembly files.
454
0
  void GetIndividualFileTargets(std::vector<std::string>&) {}
455
456
  /**
457
   * Get the relative path from the generator output directory to a
458
   * per-target support directory.
459
   */
460
  virtual std::string GetTargetDirectory(
461
    cmGeneratorTarget const* target,
462
    cmStateEnums::IntermediateDirKind kind) const;
463
464
  cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
465
466
  cmake* GetCMakeInstance() const;
467
468
  std::string const& GetSourceDirectory() const;
469
  std::string const& GetBinaryDirectory() const;
470
471
  std::string const& GetCurrentBinaryDirectory() const;
472
  std::string const& GetCurrentSourceDirectory() const;
473
474
  bool UseShortObjectNames(
475
    cmStateEnums::IntermediateDirKind kind =
476
      cmStateEnums::IntermediateDirKind::ObjectFiles) const;
477
  virtual std::string GetObjectOutputRoot(
478
    cmStateEnums::IntermediateDirKind kind =
479
      cmStateEnums::IntermediateDirKind::ObjectFiles) const;
480
  virtual bool AlwaysUsesCMFPaths() const;
481
  virtual std::string GetShortObjectFileName(cmSourceFile const& source) const;
482
  virtual std::string ComputeShortTargetDirectory(
483
    cmGeneratorTarget const* gt) const;
484
  std::string GetCustomObjectFileName(cmSourceFile const& source) const;
485
  std::string GetCustomInstallObjectFileName(cmSourceFile const& source,
486
                                             std::string const& config,
487
                                             char const* custom_ext) const;
488
  void FillCustomInstallObjectLocations(
489
    cmSourceFile const& source, std::string const& config,
490
    char const* custom_ext,
491
    std::map<std::string, cmObjectLocation>& mapping) const;
492
493
  /**
494
   * Generate a macOS application bundle Info.plist file.
495
   */
496
  void GenerateAppleInfoPList(cmGeneratorTarget* target,
497
                              std::string const& targetName,
498
                              std::string const& fname);
499
500
  /**
501
   * Generate a macOS framework Info.plist file.
502
   */
503
  void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
504
                                  std::string const& targetName,
505
                                  std::string const& fname);
506
  /** Construct a comment for a custom command.  */
507
  std::string ConstructComment(cmCustomCommandGenerator const& ccg,
508
                               char const* default_comment = "") const;
509
  // Computes relative path to source respective to source or binary dir.
510
  std::string GetRelativeSourceFileName(cmSourceFile const& source) const;
511
  // Compute object file names.
512
  std::string GetObjectFileNameWithoutTarget(
513
    cmSourceFile const& source, std::string const& dir_max,
514
    bool* hasSourceExtension = nullptr,
515
    char const* customOutputExtension = nullptr,
516
    bool const* forceShortObjectName = nullptr);
517
518
  /** Fill out the static linker flags for the given target.  */
519
  void GetStaticLibraryFlags(std::string& flags, std::string const& config,
520
                             std::string const& linkLanguage,
521
                             cmGeneratorTarget* target);
522
  std::vector<BT<std::string>> GetStaticLibraryFlags(
523
    std::string const& config, std::string const& linkLanguage,
524
    cmGeneratorTarget* target);
525
526
  /** Fill out these strings for the given target.  Libraries to link,
527
   *  flags, and linkflags. */
528
  void GetDeviceLinkFlags(cmLinkLineDeviceComputer& linkLineComputer,
529
                          std::string const& config, std::string& linkLibs,
530
                          std::string& linkFlags, std::string& frameworkPath,
531
                          std::string& linkPath, cmGeneratorTarget* target);
532
533
  void GetTargetFlags(cmLinkLineComputer* linkLineComputer,
534
                      std::string const& config, std::string& linkLibs,
535
                      std::string& flags, std::string& linkFlags,
536
                      std::string& frameworkPath, std::string& linkPath,
537
                      cmGeneratorTarget* target);
538
  void GetTargetFlags(
539
    cmLinkLineComputer* linkLineComputer, std::string const& config,
540
    std::vector<BT<std::string>>& linkLibs, std::string& flags,
541
    std::vector<BT<std::string>>& linkFlags, std::string& frameworkPath,
542
    std::vector<BT<std::string>>& linkPath, cmGeneratorTarget* target);
543
  void GetTargetDefines(cmGeneratorTarget const* target,
544
                        std::string const& config, std::string const& lang,
545
                        std::set<std::string>& defines) const;
546
  std::set<BT<std::string>> GetTargetDefines(cmGeneratorTarget const* target,
547
                                             std::string const& config,
548
                                             std::string const& lang) const;
549
  void GetTargetCompileFlags(cmGeneratorTarget* target,
550
                             std::string const& config,
551
                             std::string const& lang, std::string& flags,
552
                             std::string const& arch);
553
  std::vector<BT<std::string>> GetTargetCompileFlags(
554
    cmGeneratorTarget* target, std::string const& config,
555
    std::string const& lang, std::string const& arch = std::string());
556
557
  std::string GetFrameworkFlags(std::string const& l,
558
                                std::string const& config,
559
                                cmGeneratorTarget* target);
560
  std::string GetXcFrameworkFlags(std::string const& l,
561
                                  std::string const& config,
562
                                  cmGeneratorTarget* target);
563
  virtual std::string GetTargetFortranFlags(cmGeneratorTarget const* target,
564
                                            std::string const& config);
565
566
  virtual void ComputeObjectFilenames(
567
    std::map<cmSourceFile const*, cmObjectLocations>& mapping,
568
    std::string const& config, cmGeneratorTarget const* gt = nullptr);
569
570
  bool IsWindowsShell() const;
571
  bool IsWatcomWMake() const;
572
  bool IsMinGWMake() const;
573
  bool IsNMake() const;
574
  bool IsNinjaMulti() const;
575
  bool IsWindowsVSIDE() const;
576
577
  void IssueMessage(MessageType type, std::string const& text) const
578
0
  {
579
0
    this->IssueMessage(type, text, this->DirectoryBacktrace);
580
0
  }
581
  void IssueMessage(MessageType type, std::string const& text,
582
                    cmListFileBacktrace const& bt) const;
583
  void IssueDiagnostic(cmDiagnosticCategory category,
584
                       std::string const& text) const
585
0
  {
586
0
    this->IssueDiagnostic(category, text,
587
0
                          cmDiagnosticContext{ this->DirectoryBacktrace });
588
0
  }
589
  void IssueDiagnostic(cmDiagnosticCategory category, std::string const& text,
590
                       cmListFileBacktrace const& bt) const
591
0
  {
592
0
    this->IssueDiagnostic(category, text, cmDiagnosticContext{ bt });
593
0
  }
594
  void IssueDiagnostic(cmDiagnosticCategory category, std::string const& text,
595
                       cmDiagnosticContext const& context) const;
596
  void IssuePolicyWarning(cmPolicies::PolicyID policy, cm::string_view preface,
597
                          cm::string_view postface,
598
                          cmListFileBacktrace const& bt) const;
599
  void IssuePolicyWarning(cmPolicies::PolicyID policy,
600
                          cm::string_view preface = {},
601
                          cm::string_view postface = {}) const
602
0
  {
603
0
    this->IssuePolicyWarning(policy, preface, postface,
604
0
                             this->DirectoryBacktrace);
605
0
  }
606
607
  void CreateEvaluationFileOutputs();
608
  void CreateEvaluationFileOutputs(std::string const& config);
609
  void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
610
611
  std::string GetRuleLauncher(cmGeneratorTarget* target,
612
                              std::string const& prop,
613
                              std::string const& config);
614
615
  // Return Swift_COMPILATION_MODE value if CMP0157 is NEW.
616
  cm::optional<cmSwiftCompileMode> GetSwiftCompileMode(
617
    cmGeneratorTarget const* target, std::string const& config);
618
619
  // Can we build Swift with a separate object build and link step
620
  // (If CMP0157 is NEW, we can do a split build)
621
  bool IsSplitSwiftBuild() const;
622
623
  std::string CreateSafeObjectFileName(std::string const& sin) const;
624
625
  /**
626
   * Build the search index from source files to source groups
627
   */
628
  void ComputeSourceGroupSearchIndex();
629
630
  /**
631
   * find what source group this source is in
632
   */
633
  cmSourceGroup* FindSourceGroup(std::string const& source);
634
635
protected:
636
  // The default implementation converts to a Windows shortpath to
637
  // help older toolchains handle spaces and such.  A generator may
638
  // override this to avoid that conversion.
639
  virtual std::string ConvertToIncludeReference(
640
    std::string const& path, cmOutputConverter::OutputFormat format);
641
642
  //! put all the libraries for a target on into the given stream
643
  void OutputLinkLibraries(cmComputeLinkInformation* pcli,
644
                           cmLinkLineComputer* linkLineComputer,
645
                           std::string& linkLibraries,
646
                           std::string& frameworkPath, std::string& linkPath);
647
  void OutputLinkLibraries(cmComputeLinkInformation* pcli,
648
                           cmLinkLineComputer* linkLineComputer,
649
                           std::vector<BT<std::string>>& linkLibraries,
650
                           std::string& frameworkPath,
651
                           std::vector<BT<std::string>>& linkPath);
652
653
  // Handle old-style install rules stored in the targets.
654
  void GenerateTargetInstallRules(
655
    std::ostream& os, std::string const& config,
656
    std::vector<std::string> const& configurationTypes);
657
658
0
  virtual void AddGeneratorSpecificInstallSetup(std::ostream&) {}
659
660
  std::string& CreateSafeUniqueObjectFileName(std::string const& sin,
661
                                              std::string const& dir_max);
662
663
  /** Check whether the native build system supports the given
664
      definition.  Issues a warning.  */
665
  virtual bool CheckDefinition(std::string const& define) const;
666
667
  cmMakefile* Makefile;
668
  cmListFileBacktrace DirectoryBacktrace;
669
  cmGlobalGenerator* GlobalGenerator;
670
  std::map<std::string, std::string> UniqueObjectNamesMap;
671
  std::string::size_type ObjectPathMax;
672
  std::set<std::string> ObjectMaxPathViolations;
673
674
  std::vector<std::string> EnvCPATH;
675
676
  using GeneratorTargetMap =
677
    std::unordered_map<std::string, cmGeneratorTarget*>;
678
  GeneratorTargetMap GeneratorTargetSearchIndex;
679
  GeneratorTargetVector GeneratorTargets;
680
681
  GeneratorTargetMap ImportedGeneratorTargets;
682
  GeneratorTargetVector OwnedImportedGeneratorTargets;
683
  std::map<std::string, std::string> AliasTargets;
684
685
  std::map<std::string, std::string> Compilers;
686
  std::map<std::string, std::string> VariableMappings;
687
  std::string CompilerSysroot;
688
  std::string LinkerSysroot;
689
  std::unordered_map<std::string, std::string> AppleArchSysroots;
690
691
  bool EmitUniversalBinaryFlags;
692
693
#if !defined(CMAKE_BOOTSTRAP)
694
  // Map from source file path to source group for lookup acceleration
695
  using SourceGroupMap = std::unordered_map<std::string, cmSourceGroup*>;
696
  SourceGroupMap SourceGroupSearchIndex;
697
#endif
698
699
private:
700
  /**
701
   * See LinearGetSourceFileWithOutput for background information
702
   */
703
  cmTarget* LinearGetTargetWithOutput(std::string const& name) const;
704
705
  /**
706
   * Generalized old version of GetSourceFileWithOutput kept for
707
   * backward-compatibility. It implements a linear search and supports
708
   * relative file paths. It is used as a fall back by GetSourceFileWithOutput
709
   * and GetSourcesWithOutput.
710
   */
711
  cmSourceFile* LinearGetSourceFileWithOutput(std::string const& name,
712
                                              cmSourceOutputKind kind,
713
                                              bool& byproduct) const;
714
  struct SourceEntry
715
  {
716
    cmSourcesWithOutput Sources;
717
  };
718
719
  // A map for fast output to input look up.
720
  using OutputToSourceMap = std::unordered_map<std::string, SourceEntry>;
721
  OutputToSourceMap OutputToSource;
722
723
  void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target,
724
                               cmListFileBacktrace const& bt,
725
                               cmCommandOrigin origin);
726
  void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source,
727
                               OutputRole role, cmListFileBacktrace const& bt,
728
                               cmCommandOrigin origin);
729
730
  void AddPositionIndependentFlags(std::string& flags, std::string const& l,
731
                                   int targetType);
732
733
  void ComputeObjectMaxPath();
734
  bool AllAppleArchSysrootsAreTheSame(std::vector<std::string> const& archs,
735
                                      cmValue sysroot);
736
737
  void CopyPchCompilePdb(std::string const& config,
738
                         std::string const& language,
739
                         cmGeneratorTarget* target,
740
                         cmGeneratorTarget* reuseTarget,
741
                         std::vector<std::string> const& extensions);
742
743
  // Returns MSVC_DEBUG_INFORMATION_FORMAT value if CMP0141 is NEW.
744
  cm::optional<std::string> GetMSVCDebugFormatName(
745
    std::string const& config, cmGeneratorTarget const* target);
746
747
  struct UnityBatchedSource
748
  {
749
    cmSourceFile* Source = nullptr;
750
    std::vector<size_t> Configs;
751
    UnityBatchedSource(cmSourceFile* sf)
752
0
      : Source(sf)
753
0
    {
754
0
    }
755
  };
756
  struct UnitySource
757
  {
758
    std::string Path;
759
    bool PerConfig = false;
760
    UnitySource(std::string path, bool perConfig)
761
0
      : Path(std::move(path))
762
0
      , PerConfig(perConfig)
763
0
    {
764
0
    }
765
  };
766
  /** Whether to insert relative or absolute paths into unity files */
767
  enum class UnityPathMode
768
  {
769
    Absolute,
770
    Relative
771
  };
772
773
  UnitySource WriteUnitySource(
774
    cmGeneratorTarget* target, std::vector<std::string> const& configs,
775
    cmRange<std::vector<UnityBatchedSource>::const_iterator> sources,
776
    cmValue beforeInclude, cmValue afterInclude, std::string filename,
777
    std::string const& unityFileDirectory, UnityPathMode pathMode) const;
778
  void WriteUnitySourceInclude(std::ostream& unity_file,
779
                               cm::optional<std::string> const& cond,
780
                               std::string const& sf_full_path,
781
                               cmValue beforeInclude, cmValue afterInclude,
782
                               cmValue uniqueIdName, UnityPathMode pathMode,
783
                               std::string const& unityFileDirectory) const;
784
  std::vector<UnitySource> AddUnityFilesModeAuto(
785
    cmGeneratorTarget* target, std::string const& lang,
786
    std::vector<std::string> const& configs,
787
    std::vector<UnityBatchedSource> const& filtered_sources,
788
    cmValue beforeInclude, cmValue afterInclude,
789
    std::string const& filename_base, UnityPathMode pathMode,
790
    size_t batchSize);
791
  std::vector<UnitySource> AddUnityFilesModeGroup(
792
    cmGeneratorTarget* target, std::string const& lang,
793
    std::vector<std::string> const& configs,
794
    std::vector<UnityBatchedSource> const& filtered_sources,
795
    cmValue beforeInclude, cmValue afterInclude,
796
    std::string const& filename_base, UnityPathMode pathMode);
797
};
798
799
namespace detail {
800
void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin,
801
                              cmTarget* target, cmCustomCommandType type,
802
                              std::unique_ptr<cmCustomCommand> cc);
803
804
cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg,
805
                                       cmCommandOrigin origin,
806
                                       std::unique_ptr<cmCustomCommand> cc,
807
                                       bool replace);
808
809
void AppendCustomCommandToOutput(cmLocalGenerator& lg,
810
                                 cmListFileBacktrace const& lfbt,
811
                                 std::string const& output,
812
                                 std::vector<std::string> const& depends,
813
                                 cmImplicitDependsList const& implicit_depends,
814
                                 cmCustomCommandLines const& commandLines);
815
816
void AddUtilityCommand(cmLocalGenerator& lg, cmCommandOrigin origin,
817
                       cmTarget* target, std::unique_ptr<cmCustomCommand> cc);
818
819
std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target);
820
std::vector<std::string> ComputeISPCExtraObjects(
821
  std::string const& objectName, std::string const& buildDirectory,
822
  std::vector<std::string> const& ispcSuffixes);
823
}