Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmLocalGhsMultiGenerator.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 "cmLocalGhsMultiGenerator.h"
4
5
#include <map>
6
#include <utility>
7
#include <vector>
8
9
#include <cm/optional>
10
11
#include "cmGeneratorTarget.h"
12
#include "cmGhsMultiTargetGenerator.h"
13
#include "cmGlobalGenerator.h"
14
#include "cmObjectLocation.h"
15
#include "cmSourceFile.h"
16
#include "cmStringAlgorithms.h"
17
#include "cmSystemTools.h"
18
19
cmLocalGhsMultiGenerator::cmLocalGhsMultiGenerator(cmGlobalGenerator* gg,
20
                                                   cmMakefile* mf)
21
0
  : cmLocalGenerator(gg, mf)
22
0
{
23
0
}
24
25
0
cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() = default;
26
27
std::string cmLocalGhsMultiGenerator::GetTargetDirectory(
28
  cmGeneratorTarget const* target,
29
  cmStateEnums::IntermediateDirKind /*kind*/) const
30
0
{
31
0
  std::string dir = cmStrCat(target->GetName(), ".dir");
32
0
  return dir;
33
0
}
34
35
void cmLocalGhsMultiGenerator::Generate()
36
0
{
37
0
  for (cmGeneratorTarget* gt :
38
0
       this->GlobalGenerator->GetLocalGeneratorTargetsInOrder(this)) {
39
0
    if (!gt->IsInBuildSystem()) {
40
0
      continue;
41
0
    }
42
43
0
    cmGhsMultiTargetGenerator tg(gt);
44
0
    tg.Generate();
45
0
  }
46
0
}
47
48
void cmLocalGhsMultiGenerator::ComputeObjectFilenames(
49
  std::map<cmSourceFile const*, cmObjectLocations>& mapping,
50
  std::string const& config, cmGeneratorTarget const* gt)
51
0
{
52
0
  std::string dir_max = cmStrCat(gt->GetSupportDirectory(), '/');
53
54
  // Count the number of object files with each name.  Note that
55
  // filesystem may not be case sensitive.
56
0
  std::map<std::string, int> counts;
57
58
0
  for (auto const& si : mapping) {
59
0
    cmSourceFile const* sf = si.first;
60
0
    std::string objectName;
61
0
    auto customObjectName = this->GetCustomObjectFileName(*sf);
62
0
    if (customObjectName.empty()) {
63
0
      objectName =
64
0
        cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
65
0
    } else {
66
0
      objectName = std::move(customObjectName);
67
0
    }
68
0
    objectName += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
69
0
    std::string objectNameLower = cmSystemTools::LowerCase(objectName);
70
0
    counts[objectNameLower] += 1;
71
0
  }
72
73
  // For all source files producing duplicate names we need unique
74
  // object name computation.
75
0
  for (auto& si : mapping) {
76
0
    cmSourceFile const* sf = si.first;
77
0
    bool forceShortObjectName = true;
78
0
    std::string shortObjectName = this->GetObjectFileNameWithoutTarget(
79
0
      *sf, dir_max, nullptr, nullptr, &forceShortObjectName);
80
0
    std::string longObjectName;
81
0
    auto customObjectName = this->GetCustomObjectFileName(*sf);
82
0
    if (customObjectName.empty()) {
83
0
      longObjectName =
84
0
        cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
85
0
    } else {
86
0
      longObjectName = std::move(customObjectName);
87
0
      const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
88
0
    }
89
0
    longObjectName += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
90
91
0
    if (counts[cmSystemTools::LowerCase(longObjectName)] > 1) {
92
0
      const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
93
0
      forceShortObjectName = false;
94
0
      longObjectName = this->GetObjectFileNameWithoutTarget(
95
0
        *sf, dir_max, nullptr, nullptr, &forceShortObjectName);
96
0
      cmsys::SystemTools::ReplaceString(longObjectName, "/", "_");
97
0
    }
98
0
    si.second.ShortLoc.emplace(shortObjectName);
99
0
    si.second.LongLoc.Update(longObjectName);
100
0
    this->FillCustomInstallObjectLocations(*sf, config, nullptr,
101
0
                                           si.second.InstallLongLoc);
102
0
  }
103
0
}