Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmLocalFastbuildGenerator.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
4
#include "cmLocalFastbuildGenerator.h"
5
6
#include <map>
7
#include <memory>
8
#include <utility>
9
#include <vector>
10
11
#include "cmFastbuildTargetGenerator.h"
12
#include "cmGeneratorExpression.h"
13
#include "cmGeneratorTarget.h"
14
#include "cmGlobalFastbuildGenerator.h"
15
#include "cmList.h"
16
#include "cmLocalCommonGenerator.h"
17
#include "cmMakefile.h"
18
#include "cmObjectLocation.h"
19
#include "cmStringAlgorithms.h"
20
#include "cmSystemTools.h"
21
#include "cmValue.h"
22
#include "cmake.h"
23
24
class cmGlobalGenerator;
25
26
cmLocalFastbuildGenerator::cmLocalFastbuildGenerator(cmGlobalGenerator* gg,
27
                                                     cmMakefile* makefile)
28
0
  : cmLocalCommonGenerator(gg, makefile)
29
0
{
30
0
}
31
32
void cmLocalFastbuildGenerator::Generate()
33
0
{
34
0
  auto const& targets = this->GetGeneratorTargets();
35
0
  for (auto const& target : targets) {
36
0
    if (!target->IsInBuildSystem()) {
37
0
      continue;
38
0
    }
39
0
    for (std::string config : this->GetConfigNames()) {
40
0
      cmFastbuildTargetGenerator* tg =
41
0
        cmFastbuildTargetGenerator::New(target.get(), std::move(config));
42
0
      if (tg) {
43
0
        tg->Generate();
44
0
        delete tg;
45
0
      }
46
      // Directory level.
47
0
      this->AdditionalCleanFiles(config);
48
0
    }
49
0
  }
50
0
}
51
52
cmGlobalFastbuildGenerator const*
53
cmLocalFastbuildGenerator::GetGlobalFastbuildGenerator() const
54
0
{
55
0
  return static_cast<cmGlobalFastbuildGenerator const*>(
56
0
    this->GetGlobalGenerator());
57
0
}
58
59
cmGlobalFastbuildGenerator*
60
cmLocalFastbuildGenerator::GetGlobalFastbuildGenerator()
61
0
{
62
0
  return static_cast<cmGlobalFastbuildGenerator*>(this->GetGlobalGenerator());
63
0
}
64
65
void cmLocalFastbuildGenerator::ComputeObjectFilenames(
66
  std::map<cmSourceFile const*, cmObjectLocations>& mapping,
67
  std::string const& config, cmGeneratorTarget const* gt)
68
0
{
69
0
  char const* customExt = gt->GetCustomObjectExtension();
70
0
  for (auto& si : mapping) {
71
0
    cmSourceFile const* sf = si.first;
72
0
    si.second.LongLoc = this->GetObjectFileNameWithoutTarget(
73
0
      *sf, gt->ObjectDirectory, nullptr, nullptr);
74
0
    this->FillCustomInstallObjectLocations(*sf, config, nullptr,
75
0
                                           si.second.InstallLongLoc);
76
    // FASTBuild always appends output extension to the source file name.
77
    // So if custom ext is ".ptx", then
78
    // "kernelA.cu" will be outputted as "kernelA.cu.ptx",
79
    // that's why we can't just replace ".cu" with ".ptx".
80
    // This is needed to resolve $<TARGET_OBJECTS> genex correctly.
81
    // Tested in "CudaOnly.ExportPTX" test.
82
0
    if (customExt) {
83
0
      si.second.LongLoc.Update(
84
0
        cmStrCat(si.second.LongLoc.GetPath(), customExt));
85
0
    }
86
0
  }
87
0
}
88
89
void cmLocalFastbuildGenerator::AppendFlagEscape(
90
  std::string& flags, std::string const& rawFlag) const
91
0
{
92
0
  std::string escapedFlag = this->EscapeForShell(rawFlag);
93
  // Other make systems will remove the double $ but
94
  // fastbuild uses ^$ to escape it. So switch to that.
95
  // cmSystemTools::ReplaceString(escapedFlag, "$$", "^$");
96
0
  this->AppendFlags(flags, escapedFlag);
97
0
}
98
99
void cmLocalFastbuildGenerator::AdditionalCleanFiles(std::string const& config)
100
0
{
101
0
  if (cmValue prop_value =
102
0
        this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) {
103
0
    cmList cleanFiles{ cmGeneratorExpression::Evaluate(*prop_value, this,
104
0
                                                       config) };
105
0
    std::string const& binaryDir = this->GetCurrentBinaryDirectory();
106
0
    auto* gg = this->GetGlobalFastbuildGenerator();
107
0
    for (auto const& cleanFile : cleanFiles) {
108
      // Support relative paths
109
0
      gg->AddFileToClean(gg->ConvertToFastbuildPath(
110
0
        cmSystemTools::CollapseFullPath(cleanFile, binaryDir)));
111
0
    }
112
0
  }
113
0
}
114
115
std::string cmLocalFastbuildGenerator::ConvertToIncludeReference(
116
  std::string const& path, cmOutputConverter::OutputFormat format)
117
0
{
118
0
  std::string converted = this->ConvertToOutputForExisting(path, format);
119
0
  cmGlobalFastbuildGenerator const* GG = this->GetGlobalFastbuildGenerator();
120
0
  if (GG->UsingRelativePaths && cmSystemTools::FileIsFullPath(path)) {
121
0
    std::string const binDir = this->ConvertToOutputFormat(
122
0
      GG->GetCMakeInstance()->GetHomeOutputDirectory(), OutputFormat::SHELL);
123
0
    if (binDir == converted) {
124
0
      return ".";
125
0
    }
126
0
    return cmSystemTools::RelativePath(binDir, converted);
127
0
  }
128
0
  return converted;
129
0
}