Coverage Report

Created: 2026-03-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmGeneratorFileSets.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 "cmGeneratorFileSets.h"
4
5
#include <algorithm>
6
#include <iterator>
7
#include <map>
8
#include <utility>
9
#include <vector>
10
11
#include <cm/memory>
12
13
#include "cmGenExContext.h"
14
#include "cmGeneratorFileSet.h"
15
#include "cmGeneratorTarget.h"
16
#include "cmSourceFile.h"
17
#include "cmSystemTools.h"
18
#include "cmTarget.h"
19
20
cmGeneratorFileSets::cmGeneratorFileSets(cmGeneratorTarget* target,
21
                                         cmLocalGenerator* lg)
22
0
  : Target(target)
23
0
  , LocalGenerator(lg)
24
0
{
25
0
  for (auto const& name : target->Target->GetAllFileSetNames()) {
26
0
    auto entry = this->FileSets.emplace(
27
0
      name,
28
0
      cm::make_unique<cmGeneratorFileSet>(target->Target->GetFileSet(name)));
29
30
0
    auto const* fileSet = entry.first->second.get();
31
0
    this->AllFileSets.push_back(fileSet);
32
0
    if (fileSet->IsForSelf()) {
33
0
      this->SelfFileSets[fileSet->GetType()].push_back(fileSet);
34
0
    }
35
0
    if (fileSet->IsForInterface()) {
36
0
      this->InterfaceFileSets[fileSet->GetType()].push_back(fileSet);
37
0
    }
38
0
  }
39
0
}
40
0
cmGeneratorFileSets::~cmGeneratorFileSets() = default;
41
42
std::vector<cmGeneratorFileSet const*> const&
43
cmGeneratorFileSets::GetAllFileSets() const
44
0
{
45
0
  return this->AllFileSets;
46
0
}
47
48
namespace {
49
std::vector<cmGeneratorFileSet const*> NoFileSets;
50
}
51
52
std::vector<cmGeneratorFileSet const*> const& cmGeneratorFileSets::GetFileSets(
53
  cm::string_view type) const
54
0
{
55
0
  auto it = this->SelfFileSets.find(type);
56
0
  if (it != this->SelfFileSets.end()) {
57
0
    return it->second;
58
0
  }
59
0
  return NoFileSets;
60
0
}
61
std::vector<cmGeneratorFileSet const*> const&
62
cmGeneratorFileSets::GetInterfaceFileSets(cm::string_view type) const
63
0
{
64
0
  auto it = this->InterfaceFileSets.find(type);
65
0
  if (it != this->InterfaceFileSets.end()) {
66
0
    return it->second;
67
0
  }
68
0
  return NoFileSets;
69
0
}
70
71
cmGeneratorFileSet const* cmGeneratorFileSets::GetFileSet(
72
  std::string const& name) const
73
0
{
74
0
  auto const it = this->FileSets.find(name);
75
0
  if (it != this->FileSets.end()) {
76
0
    return it->second.get();
77
0
  }
78
0
  return nullptr;
79
0
}
80
81
cmGeneratorFileSet const* cmGeneratorFileSets::GetFileSetForSource(
82
  std::string const& config, std::string const& path) const
83
0
{
84
0
  this->BuildInfoCache(config);
85
86
0
  auto const& info = this->Configs[config];
87
88
0
  auto const it = info.FileSetCache.find(path);
89
0
  if (it == info.FileSetCache.end()) {
90
0
    return nullptr;
91
0
  }
92
0
  return it->second;
93
0
}
94
cmGeneratorFileSet const* cmGeneratorFileSets::GetFileSetForSource(
95
  std::string const& config, cmSourceFile const* sf) const
96
0
{
97
0
  return this->GetFileSetForSource(config, sf->GetFullPath());
98
0
}
99
100
std::vector<std::unique_ptr<cm::TargetPropertyEntry>>
101
cmGeneratorFileSets::GetSources(
102
  cm::GenEx::Context const& context, cmGeneratorTarget const* target,
103
  cmGeneratorExpressionDAGChecker* dagChecker) const
104
0
{
105
0
  std::vector<std::unique_ptr<TargetPropertyEntry>> entries;
106
107
0
  for (auto const& entry : this->FileSets) {
108
0
    auto const* fileSet = entry.second.get();
109
0
    if (fileSet->IsForSelf()) {
110
0
      auto sources = fileSet->GetSources(context, target, dagChecker);
111
0
      std::move(sources.begin(), sources.end(), std::back_inserter(entries));
112
0
    }
113
0
  }
114
115
0
  return entries;
116
0
}
117
118
std::vector<std::unique_ptr<cm::TargetPropertyEntry>>
119
cmGeneratorFileSets::GetSources(
120
  std::string type, cm::GenEx::Context const& context,
121
  cmGeneratorTarget const* target,
122
  cmGeneratorExpressionDAGChecker* dagChecker) const
123
0
{
124
0
  std::vector<std::unique_ptr<TargetPropertyEntry>> entries;
125
126
0
  for (auto const& entry : this->FileSets) {
127
0
    auto const* fileSet = entry.second.get();
128
0
    if (!fileSet->IsForSelf() && fileSet->GetType() == type) {
129
0
      auto sources = fileSet->GetSources(context, target, dagChecker);
130
0
      std::move(sources.begin(), sources.end(), std::back_inserter(entries));
131
0
    }
132
0
  }
133
134
0
  return entries;
135
0
}
136
137
void cmGeneratorFileSets::BuildInfoCache(std::string const& config) const
138
0
{
139
0
  auto& info = this->Configs[config];
140
141
0
  if (info.BuiltCache) {
142
0
    return;
143
0
  }
144
145
0
  for (auto const& item : this->FileSets) {
146
0
    cm::GenEx::Context context(this->LocalGenerator, config);
147
0
    auto const* file_set = item.second.get();
148
149
0
    auto files = file_set->GetFiles(context, this->Target);
150
151
0
    for (auto const& it : files.first) {
152
0
      for (auto const& filename : it.second) {
153
0
        auto collapsedFile = cmSystemTools::CollapseFullPath(filename);
154
0
        info.FileSetCache[collapsedFile] = file_set;
155
0
      }
156
0
    }
157
0
  }
158
159
0
  info.BuiltCache = true;
160
0
}