Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmFileSetMetadata.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 "cmFileSetMetadata.h"
4
5
#include <map>
6
#include <string>
7
#include <utility>
8
9
#include <cmext/algorithm>
10
#include <cmext/string_view>
11
12
#include "cmsys/RegularExpression.hxx"
13
14
#include "cmMakefile.h"
15
#include "cmMessageType.h"
16
#include "cmStringAlgorithms.h"
17
#include "cmSystemTools.h"
18
19
namespace cm {
20
namespace FileSetMetadata {
21
cm::string_view VisibilityToName(Visibility vis)
22
0
{
23
0
  switch (vis) {
24
0
    case Visibility::Interface:
25
0
      return "INTERFACE"_s;
26
0
    case Visibility::Public:
27
0
      return "PUBLIC"_s;
28
0
    case Visibility::Private:
29
0
      return "PRIVATE"_s;
30
0
  }
31
0
  return ""_s;
32
0
}
33
34
Visibility VisibilityFromName(cm::string_view name, cmMakefile* mf)
35
5.92k
{
36
5.92k
  if (name == "INTERFACE"_s) {
37
5.92k
    return Visibility::Interface;
38
5.92k
  }
39
0
  if (name == "PUBLIC"_s) {
40
0
    return Visibility::Public;
41
0
  }
42
0
  if (name == "PRIVATE"_s) {
43
0
    return Visibility::Private;
44
0
  }
45
0
  auto msg = cmStrCat("File set visibility \"", name, "\" is not valid.");
46
0
  if (mf) {
47
0
    mf->IssueMessage(MessageType::FATAL_ERROR, msg);
48
0
  } else {
49
0
    cmSystemTools::Error(msg);
50
0
  }
51
0
  return Visibility::Private;
52
0
}
53
54
bool VisibilityIsForSelf(Visibility vis)
55
30.6k
{
56
30.6k
  switch (vis) {
57
30.6k
    case Visibility::Interface:
58
30.6k
      return false;
59
0
    case Visibility::Public:
60
0
    case Visibility::Private:
61
0
      return true;
62
30.6k
  }
63
0
  return false;
64
30.6k
}
65
66
bool VisibilityIsForInterface(Visibility vis)
67
18.7k
{
68
18.7k
  switch (vis) {
69
18.7k
    case Visibility::Interface:
70
18.7k
    case Visibility::Public:
71
18.7k
      return true;
72
0
    case Visibility::Private:
73
0
      return false;
74
18.7k
  }
75
0
  return false;
76
18.7k
}
77
78
cm::string_view const HEADERS = "HEADERS"_s;
79
cm::string_view const SOURCES = "SOURCES"_s;
80
cm::string_view const SYCL = "SYCL"_s;
81
cm::string_view const SYCL_HEADERS = "SYCL_HEADERS"_s;
82
cm::string_view const CXX_MODULES = "CXX_MODULES"_s;
83
84
namespace {
85
std::map<cm::string_view, FileSetDescriptor> const FileSetDescriptors{
86
  { cm::FileSetMetadata::HEADERS,
87
    { cm::FileSetMetadata::HEADERS,
88
      cm::FileSetMetadata::FileSetLookup::Target,
89
      { DependencyMode ::Includables },
90
      DependencyMode ::Includables,
91
      { cm::FileSetMetadata::FileSetAttributes::FilesInMultipleFileSets } } },
92
  { cm::FileSetMetadata::SOURCES,
93
    { cm::FileSetMetadata::SOURCES,
94
      cm::FileSetMetadata::FileSetLookup::Dependencies,
95
      { DependencyMode ::IndependentFiles, DependencyMode ::Includables },
96
      DependencyMode ::Includables,
97
      { cm::FileSetMetadata::FileSetAttributes::FrameworkCompatible,
98
        cm::FileSetMetadata::FileSetAttributes::UnityBuild } } },
99
  { cm::FileSetMetadata::SYCL,
100
    { cm::FileSetMetadata::SOURCES,
101
      cm::FileSetMetadata::FileSetLookup::Dependencies,
102
      { DependencyMode ::IndependentFiles, DependencyMode ::Includables },
103
      DependencyMode ::Includables,
104
      { cm::FileSetMetadata::FileSetAttributes::FrameworkCompatible,
105
        cm::FileSetMetadata::FileSetAttributes::UnityBuild } } },
106
  { cm::FileSetMetadata::SYCL_HEADERS,
107
    { cm::FileSetMetadata::HEADERS,
108
      cm::FileSetMetadata::FileSetLookup::Target,
109
      { DependencyMode ::Includables },
110
      DependencyMode ::Includables,
111
      { cm::FileSetMetadata::FileSetAttributes::FilesInMultipleFileSets } } },
112
  { cm::FileSetMetadata::CXX_MODULES,
113
    { cm::FileSetMetadata::CXX_MODULES,
114
      cm::FileSetMetadata::FileSetLookup::Target,
115
      { DependencyMode ::IndependentFiles },
116
      DependencyMode ::IndependentFiles,
117
      {} } },
118
};
119
120
std::vector<cm::string_view> KnownTypes{ HEADERS, SOURCES, SYCL, SYCL_HEADERS,
121
                                         CXX_MODULES };
122
123
cmsys::RegularExpression const ValidNameRegex("^[a-z0-9][a-zA-Z0-9_]*$");
124
}
125
126
cm::optional<FileSetDescriptor> GetFileSetDescriptor(cm::string_view type)
127
25.5k
{
128
25.5k
  auto it = FileSetDescriptors.find(type);
129
25.5k
  if (it != FileSetDescriptors.end()) {
130
25.5k
    return it->second;
131
25.5k
  }
132
0
  return cm::nullopt;
133
25.5k
}
134
135
DependencyMode GetDependencyMode(cm::string_view type)
136
0
{
137
0
  auto descriptor = GetFileSetDescriptor(type);
138
0
  if (descriptor) {
139
0
    return descriptor->DefaultDependency;
140
0
  }
141
0
  return DependencyMode::Includables;
142
0
}
143
DependencyMode GetDependencyMode(cm::string_view type,
144
                                 DependencyMode requestedMode)
145
0
{
146
0
  auto descriptor = GetFileSetDescriptor(type);
147
0
  if (descriptor) {
148
    // Select the requested mode or the next-weakest mode that is supported by
149
    // the file set type
150
0
    auto mode = descriptor->SupportedDependencies.lower_bound(requestedMode);
151
0
    return mode == descriptor->SupportedDependencies.end()
152
0
      ? descriptor->DefaultDependency
153
0
      : *mode;
154
0
  }
155
0
  return DependencyMode::Includables;
156
0
}
157
158
AttributeSet GetAttributes(cm::string_view type)
159
0
{
160
0
  auto descriptor = GetFileSetDescriptor(type);
161
0
  if (descriptor) {
162
0
    return descriptor->Attributes;
163
0
  }
164
0
  return {};
165
0
}
166
bool IsFrameworkSupported(cm::string_view type)
167
0
{
168
0
  return GetAttributes(type).contains(FileSetAttributes::FrameworkCompatible);
169
0
}
170
171
std::vector<cm::string_view> const& GetKnownTypes()
172
30.2k
{
173
30.2k
  return KnownTypes;
174
30.2k
}
175
176
bool IsKnownType(cm::string_view type)
177
27.5k
{
178
27.5k
  return cm::contains(GetKnownTypes(), type);
179
27.5k
}
180
181
bool IsValidName(cm::string_view name)
182
0
{
183
0
  cmsys::RegularExpressionMatch match;
184
0
  return ValidNameRegex.find(name.data(), match);
185
0
}
186
}
187
}