Coverage Report

Created: 2026-03-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmCommonTargetGenerator.cxx
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
#include "cmCommonTargetGenerator.h"
4
5
#include <algorithm>
6
#include <sstream>
7
#include <utility>
8
9
#include <cm/string_view>
10
#include <cmext/string_view>
11
12
#include "cmComputeLinkInformation.h"
13
#include "cmGenExContext.h"
14
#include "cmGeneratorExpression.h"
15
#include "cmGeneratorExpressionDAGChecker.h"
16
#include "cmGeneratorTarget.h"
17
#include "cmGlobalCommonGenerator.h"
18
#include "cmGlobalGenerator.h"
19
#include "cmList.h"
20
#include "cmLocalCommonGenerator.h"
21
#include "cmLocalGenerator.h"
22
#include "cmMakefile.h"
23
#include "cmMessageType.h"
24
#include "cmOutputConverter.h"
25
#include "cmRange.h"
26
#include "cmSourceFile.h"
27
#include "cmState.h"
28
#include "cmStateTypes.h"
29
#include "cmStringAlgorithms.h"
30
#include "cmSystemTools.h"
31
#include "cmValue.h"
32
33
cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
34
0
  : GeneratorTarget(gt)
35
0
  , Makefile(gt->Makefile)
36
  , LocalCommonGenerator(
37
0
      static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
38
0
  , GlobalCommonGenerator(static_cast<cmGlobalCommonGenerator*>(
39
0
      gt->LocalGenerator->GetGlobalGenerator()))
40
0
  , ConfigNames(this->LocalCommonGenerator->GetConfigNames())
41
0
{
42
0
}
43
44
0
cmCommonTargetGenerator::~cmCommonTargetGenerator() = default;
45
46
std::vector<std::string> const& cmCommonTargetGenerator::GetConfigNames() const
47
0
{
48
0
  return this->ConfigNames;
49
0
}
50
51
cmValue cmCommonTargetGenerator::GetFeature(std::string const& feature,
52
                                            std::string const& config)
53
0
{
54
0
  return this->GeneratorTarget->GetFeature(feature, config);
55
0
}
56
57
void cmCommonTargetGenerator::AppendFortranFormatFlags(
58
  std::string& flags, cmSourceFile const& source)
59
0
{
60
0
  std::string const srcfmt = source.GetSafeProperty("Fortran_FORMAT");
61
0
  cmOutputConverter::FortranFormat format =
62
0
    cmOutputConverter::GetFortranFormat(srcfmt);
63
0
  if (format == cmOutputConverter::FortranFormatNone) {
64
0
    std::string const& tgtfmt =
65
0
      this->GeneratorTarget->GetSafeProperty("Fortran_FORMAT");
66
0
    format = cmOutputConverter::GetFortranFormat(tgtfmt);
67
0
  }
68
0
  char const* var = nullptr;
69
0
  switch (format) {
70
0
    case cmOutputConverter::FortranFormatFixed:
71
0
      var = "CMAKE_Fortran_FORMAT_FIXED_FLAG";
72
0
      break;
73
0
    case cmOutputConverter::FortranFormatFree:
74
0
      var = "CMAKE_Fortran_FORMAT_FREE_FLAG";
75
0
      break;
76
0
    default:
77
0
      break;
78
0
  }
79
0
  if (var) {
80
0
    this->LocalCommonGenerator->AppendFlags(
81
0
      flags, this->Makefile->GetSafeDefinition(var));
82
0
  }
83
0
}
84
85
void cmCommonTargetGenerator::AppendFortranPreprocessFlags(
86
  std::string& flags, cmSourceFile const& source,
87
  PreprocessFlagsRequired requires_pp)
88
0
{
89
0
  std::string const srcpp = source.GetSafeProperty("Fortran_PREPROCESS");
90
0
  cmOutputConverter::FortranPreprocess preprocess =
91
0
    cmOutputConverter::GetFortranPreprocess(srcpp);
92
0
  if (preprocess == cmOutputConverter::FortranPreprocess::Unset) {
93
0
    std::string const& tgtpp =
94
0
      this->GeneratorTarget->GetSafeProperty("Fortran_PREPROCESS");
95
0
    preprocess = cmOutputConverter::GetFortranPreprocess(tgtpp);
96
0
  }
97
0
  char const* var = nullptr;
98
0
  switch (preprocess) {
99
0
    case cmOutputConverter::FortranPreprocess::Needed:
100
0
      if (requires_pp == PreprocessFlagsRequired::YES) {
101
0
        var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON";
102
0
      }
103
0
      break;
104
0
    case cmOutputConverter::FortranPreprocess::NotNeeded:
105
0
      var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF";
106
0
      break;
107
0
    default:
108
0
      break;
109
0
  }
110
0
  if (var) {
111
0
    this->LocalCommonGenerator->AppendCompileOptions(
112
0
      flags, this->Makefile->GetSafeDefinition(var));
113
0
  }
114
0
}
115
116
std::string cmCommonTargetGenerator::GetFlags(std::string const& l,
117
                                              std::string const& config,
118
                                              std::string const& arch)
119
0
{
120
0
  std::string const key = config + arch;
121
122
0
  auto i = this->Configs[key].FlagsByLanguage.find(l);
123
0
  if (i == this->Configs[key].FlagsByLanguage.end()) {
124
0
    std::string flags;
125
126
0
    this->LocalCommonGenerator->GetTargetCompileFlags(this->GeneratorTarget,
127
0
                                                      config, l, flags, arch);
128
129
0
    ByLanguageMap::value_type entry(l, flags);
130
0
    i = this->Configs[key].FlagsByLanguage.insert(entry).first;
131
0
  }
132
0
  return i->second;
133
0
}
134
135
std::string cmCommonTargetGenerator::GetDefines(std::string const& l,
136
                                                std::string const& config)
137
0
{
138
0
  auto i = this->Configs[config].DefinesByLanguage.find(l);
139
0
  if (i == this->Configs[config].DefinesByLanguage.end()) {
140
0
    std::set<std::string> defines;
141
0
    this->LocalCommonGenerator->GetTargetDefines(this->GeneratorTarget, config,
142
0
                                                 l, defines);
143
144
0
    std::string definesString;
145
0
    this->LocalCommonGenerator->JoinDefines(defines, definesString, l);
146
147
0
    ByLanguageMap::value_type entry(l, definesString);
148
0
    i = this->Configs[config].DefinesByLanguage.insert(entry).first;
149
0
  }
150
0
  return i->second;
151
0
}
152
153
std::string cmCommonTargetGenerator::GetIncludes(std::string const& l,
154
                                                 std::string const& config)
155
0
{
156
0
  auto i = this->Configs[config].IncludesByLanguage.find(l);
157
0
  if (i == this->Configs[config].IncludesByLanguage.end()) {
158
0
    std::string includes;
159
0
    this->AddIncludeFlags(includes, l, config);
160
0
    ByLanguageMap::value_type entry(l, includes);
161
0
    i = this->Configs[config].IncludesByLanguage.insert(entry).first;
162
0
  }
163
0
  return i->second;
164
0
}
165
166
cmCommonTargetGenerator::LinkedTargetDirs
167
cmCommonTargetGenerator::GetLinkedTargetDirectories(
168
  std::string const& lang, std::string const& config) const
169
0
{
170
0
  LinkedTargetDirs dirs;
171
0
  std::set<cmGeneratorTarget const*> forward_emitted;
172
0
  std::set<cmGeneratorTarget const*> direct_emitted;
173
0
  cmGlobalCommonGenerator* const gg = this->GlobalCommonGenerator;
174
175
0
  enum class Forwarding
176
0
  {
177
0
    Yes,
178
0
    No
179
0
  };
180
181
0
  if (cmComputeLinkInformation* cli =
182
0
        this->GeneratorTarget->GetLinkInformation(config)) {
183
184
0
    auto findSyntheticTarget =
185
0
      [this,
186
0
       &config](cmGeneratorTarget const* linkee) -> cmGeneratorTarget const* {
187
0
      if (!linkee) {
188
0
        return nullptr;
189
0
      }
190
191
      // Check the map of direct synthetic dependencies for a substitute
192
0
      auto const& synthDeps = this->GeneratorTarget->GetSyntheticDeps(config);
193
0
      auto it = synthDeps.find(linkee);
194
0
      if (it != synthDeps.end() && !it->second.empty()) {
195
0
        return it->second.front();
196
0
      }
197
198
      // Check linked targets to finding synthetic targets for transitive deps
199
0
      std::vector<cmGeneratorTarget const*> pending;
200
0
      std::set<cmGeneratorTarget const*> visited;
201
0
      for (auto const& dep : synthDeps) {
202
0
        for (auto const* synth : dep.second) {
203
0
          if (synth && visited.insert(synth).second) {
204
0
            pending.push_back(synth);
205
0
          }
206
0
        }
207
0
      }
208
209
0
      while (!pending.empty()) {
210
0
        auto const* current = pending.back();
211
0
        pending.pop_back();
212
0
        auto const& transitiveSynthDeps = current->GetSyntheticDeps(config);
213
0
        auto itLinkeeSynth = transitiveSynthDeps.find(linkee);
214
0
        if (itLinkeeSynth != transitiveSynthDeps.end() &&
215
0
            !itLinkeeSynth->second.empty()) {
216
0
          return itLinkeeSynth->second.front();
217
0
        }
218
0
        for (auto const& entry : transitiveSynthDeps) {
219
0
          for (auto const* synth : entry.second) {
220
0
            if (synth && visited.insert(synth).second) {
221
0
              pending.push_back(synth);
222
0
            }
223
0
          }
224
0
        }
225
0
      }
226
227
0
      return nullptr;
228
0
    };
229
230
0
    auto addLinkedTarget = [this, &lang, &config, &dirs, &direct_emitted,
231
0
                            &forward_emitted, &findSyntheticTarget,
232
0
                            gg](cmGeneratorTarget const* linkee,
233
0
                                Forwarding forward) {
234
      // Check if the linkee has a synthetic target to use for importing
235
0
      cmGeneratorTarget const* mappedLinkee = linkee;
236
0
      if (auto const* synth = findSyntheticTarget(linkee)) {
237
0
        mappedLinkee = synth;
238
0
      }
239
240
0
      if (mappedLinkee &&
241
0
          !mappedLinkee->IsImported()
242
          // Skip targets that build after this one in a static lib cycle.
243
0
          && gg->TargetOrderIndexLess(mappedLinkee, this->GeneratorTarget)
244
          // We can ignore the INTERFACE_LIBRARY items because
245
          // Target->GetLinkInformation already processed their
246
          // link interface and they don't have any output themselves.
247
0
          && (mappedLinkee->GetType() != cmStateEnums::INTERFACE_LIBRARY
248
              // Synthesized targets may have relevant rules.
249
0
              || mappedLinkee->IsSynthetic()) &&
250
0
          ((lang == "CXX"_s && mappedLinkee->HaveCxx20ModuleSources()) ||
251
0
           (lang == "Fortran"_s &&
252
0
            mappedLinkee->HaveFortranSources(config)))) {
253
0
        cmLocalGenerator* lg = mappedLinkee->GetLocalGenerator();
254
0
        std::string di = mappedLinkee->GetSupportDirectory();
255
0
        if (lg->GetGlobalGenerator()->IsMultiConfig()) {
256
0
          di = cmStrCat(di, '/', config);
257
0
        }
258
0
        if (forward == Forwarding::Yes &&
259
0
            forward_emitted.insert(mappedLinkee).second) {
260
0
          dirs.Forward.push_back(di);
261
0
        }
262
0
        if (direct_emitted.insert(mappedLinkee).second) {
263
0
          dirs.Direct.emplace_back(di);
264
0
        }
265
0
      }
266
0
    };
267
0
    for (auto const& item : cli->GetItems()) {
268
0
      if (item.Target) {
269
0
        addLinkedTarget(item.Target, Forwarding::No);
270
0
      } else if (item.ObjectSource && lang == "Fortran"_s
271
                 /* Object source files do not have a language associated with
272
                    them. */
273
0
                 /* && item.ObjectSource->GetLanguage() == "Fortran"_s*/) {
274
        // Fortran modules provided by `$<TARGET_OBJECTS>` as linked items
275
        // should be collated for use in this target.
276
0
        addLinkedTarget(this->LocalCommonGenerator->FindGeneratorTargetToUse(
277
0
                          item.ObjectSource->GetObjectLibrary()),
278
0
                        Forwarding::Yes);
279
0
      }
280
0
    }
281
0
    for (cmGeneratorTarget const* target : cli->GetExternalObjectTargets()) {
282
0
      addLinkedTarget(target, Forwarding::No);
283
0
    }
284
0
    if (lang == "Fortran"_s) {
285
      // Fortran modules provided by `$<TARGET_OBJECTS>` as sources should be
286
      // collated for use in this target.
287
0
      for (cmGeneratorTarget const* target :
288
0
           this->GeneratorTarget->GetSourceObjectLibraries(config)) {
289
0
        addLinkedTarget(target, Forwarding::Yes);
290
0
      }
291
0
    }
292
0
  }
293
0
  return dirs;
294
0
}
295
296
std::string cmCommonTargetGenerator::ComputeTargetCompilePDB(
297
  std::string const& config) const
298
0
{
299
0
  std::string compilePdbPath;
300
0
  if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) {
301
0
    return compilePdbPath;
302
0
  }
303
304
0
  compilePdbPath = this->GeneratorTarget->GetCompilePDBPath(config);
305
0
  if (compilePdbPath.empty()) {
306
    // Match VS default: `$(IntDir)vc$(PlatformToolsetVersion).pdb`.
307
    // A trailing slash tells the toolchain to add its default file name.
308
0
    compilePdbPath = this->GeneratorTarget->GetSupportDirectory();
309
0
    if (this->GlobalCommonGenerator->IsMultiConfig()) {
310
0
      compilePdbPath += "/";
311
0
      compilePdbPath += config;
312
0
    }
313
0
    compilePdbPath += "/";
314
0
    if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
315
      // Match VS default for static libs: `$(IntDir)$(ProjectName).pdb`.
316
0
      compilePdbPath += this->GeneratorTarget->GetName();
317
0
      compilePdbPath += ".pdb";
318
0
    }
319
0
  }
320
321
0
  return compilePdbPath;
322
0
}
323
324
std::string cmCommonTargetGenerator::GetManifests(std::string const& config)
325
0
{
326
0
  std::vector<cmSourceFile const*> manifest_srcs;
327
0
  this->GeneratorTarget->GetManifests(manifest_srcs, config);
328
329
0
  std::vector<std::string> manifests;
330
0
  manifests.reserve(manifest_srcs.size());
331
332
0
  std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
333
0
  std::string manifestFlag = this->Makefile->GetDefinition(
334
0
    cmStrCat("CMAKE_", lang, "_LINKER_MANIFEST_FLAG"));
335
0
  for (cmSourceFile const* manifest_src : manifest_srcs) {
336
0
    manifests.push_back(manifestFlag +
337
0
                        this->LocalCommonGenerator->ConvertToOutputFormat(
338
0
                          this->LocalCommonGenerator->MaybeRelativeToWorkDir(
339
0
                            manifest_src->GetFullPath()),
340
0
                          cmOutputConverter::SHELL));
341
0
  }
342
343
0
  return cmJoin(manifests, " ");
344
0
}
345
346
std::string cmCommonTargetGenerator::GetAIXExports(std::string const&)
347
0
{
348
0
  std::string aixExports;
349
0
  if (this->GeneratorTarget->IsAIX()) {
350
0
    if (cmValue exportAll =
351
0
          this->GeneratorTarget->GetProperty("AIX_EXPORT_ALL_SYMBOLS")) {
352
0
      if (exportAll.IsOff()) {
353
0
        aixExports = "-n";
354
0
      }
355
0
    }
356
0
  }
357
0
  return aixExports;
358
0
}
359
360
void cmCommonTargetGenerator::AppendOSXVerFlag(std::string& flags,
361
                                               std::string const& lang,
362
                                               char const* name, bool so)
363
0
{
364
  // Lookup the flag to specify the version.
365
0
  std::string fvar = cmStrCat("CMAKE_", lang, "_OSX_", name, "_VERSION_FLAG");
366
0
  cmValue flag = this->Makefile->GetDefinition(fvar);
367
368
  // Skip if no such flag.
369
0
  if (!flag) {
370
0
    return;
371
0
  }
372
373
  // Lookup the target version information.
374
0
  int major;
375
0
  int minor;
376
0
  int patch;
377
0
  std::string prop = cmStrCat("MACHO_", name, "_VERSION");
378
0
  std::string fallback_prop = so ? "SOVERSION" : "VERSION";
379
0
  this->GeneratorTarget->GetTargetVersionFallback(prop, fallback_prop, major,
380
0
                                                  minor, patch);
381
0
  if (major > 0 || minor > 0 || patch > 0) {
382
    // Append the flag since a non-zero version is specified.
383
0
    std::ostringstream vflag;
384
0
    vflag << *flag << major << "." << minor << "." << patch;
385
0
    this->LocalCommonGenerator->AppendFlags(flags, vflag.str());
386
0
  }
387
0
}
388
389
std::string cmCommonTargetGenerator::GetCompilerLauncher(
390
  std::string const& lang, std::string const& config)
391
0
{
392
0
  std::string compilerLauncher;
393
0
  if (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" ||
394
0
      lang == "HIP" || lang == "ISPC" || lang == "OBJC" || lang == "OBJCXX") {
395
0
    std::string const clauncher_prop = cmStrCat(lang, "_COMPILER_LAUNCHER");
396
0
    cmValue clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
397
0
    std::string const evaluatedClauncher = cmGeneratorExpression::Evaluate(
398
0
      *clauncher, this->GeneratorTarget->GetLocalGenerator(), config,
399
0
      this->GeneratorTarget, nullptr, this->GeneratorTarget, lang);
400
0
    if (!evaluatedClauncher.empty()) {
401
0
      compilerLauncher = evaluatedClauncher;
402
0
    }
403
0
  }
404
0
  return compilerLauncher;
405
0
}
406
407
std::string cmCommonTargetGenerator::GenerateCodeCheckRules(
408
  cmSourceFile const& source, std::string& compilerLauncher,
409
  std::string const& cmakeCmd, std::string const& config,
410
  std::function<std::string(std::string const&)> const& pathConverter)
411
0
{
412
0
  auto const lang = source.GetLanguage();
413
0
  std::string tidy;
414
0
  std::string iwyu;
415
0
  std::string cpplint;
416
0
  std::string cppcheck;
417
0
  std::string icstat;
418
0
  std::string pvs;
419
420
0
  auto evaluateProp = [&](std::string const& prop) -> std::string {
421
0
    auto const value = this->GeneratorTarget->GetProperty(prop);
422
0
    if (!value) {
423
0
      return std::string{};
424
0
    }
425
0
    auto evaluatedProp = cmGeneratorExpression::Evaluate(
426
0
      *value, this->GeneratorTarget->GetLocalGenerator(), config,
427
0
      this->GeneratorTarget, nullptr, this->GeneratorTarget, lang);
428
0
    return evaluatedProp;
429
0
  };
430
0
  std::string const tidy_prop = cmStrCat(lang, "_CLANG_TIDY");
431
0
  tidy = evaluateProp(tidy_prop);
432
433
0
  if (lang == "C" || lang == "CXX") {
434
0
    std::string const iwyu_prop = cmStrCat(lang, "_INCLUDE_WHAT_YOU_USE");
435
0
    iwyu = evaluateProp(iwyu_prop);
436
437
0
    std::string const cpplint_prop = cmStrCat(lang, "_CPPLINT");
438
0
    cpplint = evaluateProp(cpplint_prop);
439
440
0
    std::string const cppcheck_prop = cmStrCat(lang, "_CPPCHECK");
441
0
    cppcheck = evaluateProp(cppcheck_prop);
442
443
0
    std::string const icstat_prop = cmStrCat(lang, "_ICSTAT");
444
0
    icstat = evaluateProp(icstat_prop);
445
446
0
    std::string const pvs_prop = cmStrCat(lang, "_PVS_STUDIO");
447
0
    pvs = evaluateProp(pvs_prop);
448
0
  }
449
450
0
  if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
451
0
      cmNonempty(cppcheck) || cmNonempty(icstat) || cmNonempty(pvs)) {
452
0
    std::string code_check = cmakeCmd + " -E __run_co_compile";
453
0
    if (!compilerLauncher.empty()) {
454
      // In __run_co_compile case the launcher command is supplied
455
      // via --launcher=<maybe-list> and consumed
456
0
      code_check =
457
0
        cmStrCat(std::move(code_check), " --launcher=",
458
0
                 this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
459
0
                   compilerLauncher));
460
0
      compilerLauncher.clear();
461
0
    }
462
0
    if (cmNonempty(iwyu)) {
463
0
      code_check += " --iwyu=";
464
465
      // Only add --driver-mode if it is not already specified, as adding
466
      // it unconditionally might override a user-specified driver-mode
467
0
      if (iwyu.find("--driver-mode=") == std::string::npos) {
468
0
        cmValue const p = this->Makefile->GetDefinition(
469
0
          cmStrCat("CMAKE_", lang, "_INCLUDE_WHAT_YOU_USE_DRIVER_MODE"));
470
0
        std::string driverMode;
471
472
0
        if (cmNonempty(p)) {
473
0
          driverMode = *p;
474
0
        } else {
475
0
          driverMode = lang == "C" ? "gcc" : "g++";
476
0
        }
477
478
0
        code_check +=
479
0
          this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
480
0
            cmStrCat(iwyu, ";--driver-mode=", driverMode));
481
0
      } else {
482
0
        code_check +=
483
0
          this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(iwyu);
484
0
      }
485
0
    }
486
0
    if (cmNonempty(tidy)) {
487
0
      code_check += " --tidy=";
488
0
      cmValue const p = this->Makefile->GetDefinition(
489
0
        cmStrCat("CMAKE_", lang, "_CLANG_TIDY_DRIVER_MODE"));
490
0
      std::string driverMode;
491
0
      if (cmNonempty(p)) {
492
0
        driverMode = *p;
493
0
      } else {
494
0
        driverMode = lang == "C" ? "gcc" : "g++";
495
0
      }
496
497
0
      auto const generatorName = this->GeneratorTarget->GetLocalGenerator()
498
0
                                   ->GetGlobalGenerator()
499
0
                                   ->GetName();
500
0
      auto const clangTidyExportFixedDir =
501
0
        this->GeneratorTarget->GetClangTidyExportFixesDirectory(lang);
502
0
      auto fixesFile = this->GetClangTidyReplacementsFilePath(
503
0
        clangTidyExportFixedDir, source, config);
504
0
      std::string exportFixes;
505
0
      if (!clangTidyExportFixedDir.empty()) {
506
0
        this->GlobalCommonGenerator->AddClangTidyExportFixesDir(
507
0
          clangTidyExportFixedDir);
508
0
      }
509
0
      if (generatorName.find("Make") != std::string::npos) {
510
0
        if (!clangTidyExportFixedDir.empty()) {
511
0
          this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
512
0
          cmSystemTools::MakeDirectory(
513
0
            cmSystemTools::GetFilenamePath(fixesFile));
514
0
          fixesFile = this->GeneratorTarget->GetLocalGenerator()
515
0
                        ->MaybeRelativeToCurBinDir(fixesFile);
516
0
          exportFixes = cmStrCat(";--export-fixes=", fixesFile);
517
0
        }
518
0
        code_check +=
519
0
          this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
520
0
            cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode,
521
0
                     exportFixes));
522
0
      } else if (generatorName.find("Ninja") != std::string::npos ||
523
0
                 generatorName.find("FASTBuild") != std::string::npos) {
524
0
        if (!clangTidyExportFixedDir.empty()) {
525
0
          this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
526
0
          cmSystemTools::MakeDirectory(
527
0
            cmSystemTools::GetFilenamePath(fixesFile));
528
0
          if (pathConverter) {
529
0
            fixesFile = pathConverter(fixesFile);
530
0
          }
531
0
          exportFixes = cmStrCat(";--export-fixes=", fixesFile);
532
0
        }
533
0
        code_check +=
534
0
          this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
535
0
            cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode,
536
0
                     exportFixes));
537
0
      }
538
0
    }
539
0
    if (cmNonempty(pvs)) {
540
0
      cmMakefile* mf =
541
0
        this->GeneratorTarget->GetLocalGenerator()->GetMakefile();
542
0
      std::string extraPvsArgs;
543
0
      if (lang == "CXX") {
544
0
        extraPvsArgs +=
545
0
          cmStrCat(";--cxx;", mf->GetDefinition("CMAKE_CXX_COMPILER"));
546
0
      } else if (lang == "C") {
547
0
        extraPvsArgs +=
548
0
          cmStrCat(";--cc;", mf->GetDefinition("CMAKE_C_COMPILER"));
549
0
      }
550
      // cocompile args
551
0
      code_check += " --pvs-studio=";
552
0
      code_check += this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
553
0
        cmStrCat(pvs, extraPvsArgs));
554
0
      code_check += " --object=";
555
0
      code_check +=
556
0
        this->GeneratorTarget->GetLocalGenerator()->ConvertToOutputFormat(
557
0
          cmSystemTools::CollapseFullPath(
558
0
            cmStrCat(this->GeneratorTarget->GetObjectDirectory(config), '/',
559
0
                     this->GeneratorTarget->GetObjectName(&source))),
560
0
          cmOutputConverter::SHELL);
561
0
    }
562
0
    if (cmNonempty(cpplint)) {
563
0
      code_check += " --cpplint=";
564
0
      code_check +=
565
0
        this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(cpplint);
566
0
    }
567
0
    if (cmNonempty(cppcheck)) {
568
0
      code_check += " --cppcheck=";
569
0
      code_check +=
570
0
        this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(cppcheck);
571
0
    }
572
0
    if (cmNonempty(icstat)) {
573
0
      code_check += " --icstat=";
574
0
      std::string checksParam{};
575
0
      std::string dbParam{};
576
      // Set default values for mandatory parameters
577
0
      std::string checksFile{ "cstat_sel_checks.txt" };
578
0
      std::string dbFile{ "cstat.db" };
579
      // Populate the command line with C-STAT
580
      // mandatory parameters unless specified
581
0
      if (icstat.find("--checks=") == std::string::npos) {
582
0
        checksParam = cmStrCat(";--checks=", checksFile);
583
0
      }
584
0
      if (icstat.find("--db=") == std::string::npos) {
585
0
        dbParam = cmStrCat(";--db=", dbFile);
586
0
      }
587
0
      code_check += this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
588
0
        cmStrCat(icstat, checksParam, dbParam));
589
0
    }
590
0
    if (cmNonempty(tidy) || (cmNonempty(cpplint)) || (cmNonempty(cppcheck)) ||
591
0
        cmNonempty(pvs)) {
592
0
      code_check += " --source=";
593
0
      code_check +=
594
0
        this->GeneratorTarget->GetLocalGenerator()->ConvertToOutputFormat(
595
0
          source.GetFullPath(), cmOutputConverter::SHELL);
596
0
    }
597
0
    code_check += " -- ";
598
0
    return code_check;
599
0
  }
600
0
  return "";
601
0
}
602
603
std::string cmCommonTargetGenerator::GetLinkerLauncher(
604
  std::string const& config)
605
0
{
606
0
  std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
607
0
  std::string propName = lang + "_LINKER_LAUNCHER";
608
0
  cmValue launcherProp = this->GeneratorTarget->GetProperty(propName);
609
0
  if (cmNonempty(launcherProp)) {
610
0
    cm::GenEx::Context context(this->LocalCommonGenerator, config, lang);
611
0
    cmGeneratorExpressionDAGChecker dagChecker{ this->GeneratorTarget,
612
0
                                                propName, nullptr, nullptr,
613
0
                                                context };
614
0
    std::string evaluatedLinklauncher = cmGeneratorExpression::Evaluate(
615
0
      *launcherProp, context.LG, context.Config, this->GeneratorTarget,
616
0
      &dagChecker, this->GeneratorTarget, context.Language);
617
    // Convert ;-delimited list to single string
618
0
    cmList args{ evaluatedLinklauncher, cmList::EmptyElements::Yes };
619
0
    if (!args.empty()) {
620
0
      args[0] = this->LocalCommonGenerator->ConvertToOutputFormat(
621
0
        args[0], cmOutputConverter::SHELL);
622
0
      for (std::string& i : cmMakeRange(args.begin() + 1, args.end())) {
623
0
        i = this->LocalCommonGenerator->EscapeForShell(i);
624
0
      }
625
0
      return cmJoin(args, " ");
626
0
    }
627
0
  }
628
0
  return std::string();
629
0
}
630
631
bool cmCommonTargetGenerator::HaveRequiredLanguages(
632
  std::vector<cmSourceFile const*> const& sources,
633
  std::set<std::string>& languagesNeeded) const
634
0
{
635
0
  for (cmSourceFile const* sf : sources) {
636
0
    languagesNeeded.insert(sf->GetLanguage());
637
0
  }
638
639
0
  auto* makefile = this->Makefile;
640
0
  auto* state = makefile->GetState();
641
0
  auto unary = [&state, &makefile](std::string const& lang) -> bool {
642
0
    bool const valid = state->GetLanguageEnabled(lang);
643
0
    if (!valid) {
644
0
      makefile->IssueMessage(
645
0
        MessageType::FATAL_ERROR,
646
0
        cmStrCat("The language ", lang,
647
0
                 " was requested for compilation but was not enabled."
648
0
                 " To enable a language it needs to be specified in a"
649
0
                 " 'project' or 'enable_language' command in the root"
650
0
                 " CMakeLists.txt"));
651
0
    }
652
0
    return valid;
653
0
  };
654
0
  return std::all_of(languagesNeeded.cbegin(), languagesNeeded.cend(), unary);
655
0
}