Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmExperimental.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 "cmExperimental.h"
5
6
#include <cassert>
7
#include <cstddef>
8
#include <string>
9
10
#include "cmGlobalGenerator.h"
11
#include "cmMakefile.h"
12
#include "cmMessageType.h"
13
#include "cmStringAlgorithms.h"
14
#include "cmValue.h"
15
16
namespace {
17
18
/*
19
 * The `Uuid` fields of these objects should change periodically.
20
 * Search for other instances to keep the documentation and test suite
21
 * up-to-date.
22
 */
23
cmExperimental::FeatureData const LookupTable[] = {
24
  // ExportPackageDependencies
25
  { "ExportPackageDependencies",
26
    "1942b4fa-b2c5-4546-9385-83f254070067",
27
    "CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES",
28
    "CMake's EXPORT_PACKAGE_DEPENDENCIES support is experimental. It is meant "
29
    "only for experimentation and feedback to CMake developers.",
30
    {},
31
    cmExperimental::TryCompileCondition::Always },
32
  // ImportPackageInfo
33
  { "ImportPackageInfo",
34
    "e82e467b-f997-4464-8ace-b00808fff261",
35
    "CMAKE_EXPERIMENTAL_FIND_CPS_PACKAGES",
36
    "CMake's support for importing package information in the Common Package "
37
    "Specification format (via find_package) is experimental. It is meant "
38
    "only for experimentation and feedback to CMake developers.",
39
    {},
40
    cmExperimental::TryCompileCondition::Always },
41
  // ExportPackageInfo
42
  { "ExportPackageInfo",
43
    "7fa7d13b-8308-4dc7-af39-9e450456d68f",
44
    "CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO",
45
    "CMake's support for exporting package information in the Common Package "
46
    "Specification format is experimental. It is meant only for "
47
    "experimentation and feedback to CMake developers.",
48
    {},
49
    cmExperimental::TryCompileCondition::Always },
50
  // MappedPackageInfo
51
  { "MappedPackageInfo",
52
    "ababa1b5-7099-495f-a9cd-e22d38f274f2",
53
    "CMAKE_EXPERIMENTAL_MAPPED_PACKAGE_INFO",
54
    "CMake's support for generating package information in the Common Package "
55
    "Specification format from CMake script exports is experimental. It is "
56
    "meant only for experimentation and feedback to CMake developers.",
57
    {},
58
    cmExperimental::TryCompileCondition::Always },
59
  // ExportBuildDatabase
60
  { "ExportBuildDatabase",
61
    "73194a1d-c0b5-41b9-9190-a4512925e192",
62
    "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE",
63
    "CMake's support for exporting build databases is experimental. It is "
64
    "meant only for experimentation and feedback to CMake developers.",
65
    {},
66
    cmExperimental::TryCompileCondition::Never },
67
  { "GenerateSbom",
68
    "ca494ed3-b261-4205-a01f-603c95e4cae0",
69
    "CMAKE_EXPERIMENTAL_GENERATE_SBOM",
70
    "CMake's support for generating software bill of materials (Sbom) "
71
    "information in SPDX format is experimental. It is meant only for "
72
    "experimentation and feedback to CMake developers.",
73
    {},
74
    cmExperimental::TryCompileCondition::Never },
75
  // Rust support
76
  { "Rust",
77
    "3cc9b32c-47d3-4056-8953-d74e69fc0d6c",
78
    "CMAKE_EXPERIMENTAL_RUST",
79
    "CMake's support for the Rust programming language is experimental. "
80
    "It is meant only for experimentation and feedback to CMake developers.",
81
    {},
82
    cmExperimental::TryCompileCondition::Never },
83
};
84
static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
85
                static_cast<size_t>(cmExperimental::Feature::Sentinel),
86
              "Experimental feature lookup table mismatch");
87
88
cmExperimental::FeatureData const& DataForFeature(cmExperimental::Feature f)
89
0
{
90
0
  assert(f != cmExperimental::Feature::Sentinel);
91
0
  return LookupTable[static_cast<size_t>(f)];
92
0
}
93
}
94
95
cmExperimental::FeatureData const& cmExperimental::DataForFeature(Feature f)
96
0
{
97
0
  return ::DataForFeature(f);
98
0
}
99
100
cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName(
101
  std::string const& name)
102
0
{
103
0
  size_t idx = 0;
104
0
  for (auto const& feature : LookupTable) {
105
0
    if (feature.Name == name) {
106
0
      return static_cast<Feature>(idx);
107
0
    }
108
0
    ++idx;
109
0
  }
110
111
0
  return {};
112
0
}
113
114
bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
115
0
{
116
0
  bool enabled = false;
117
0
  FeatureData const& data = cmExperimental::DataForFeature(f);
118
119
0
  if (cmValue value = mf.GetDefinition(data.Variable)) {
120
0
    enabled = *value == data.Uuid;
121
122
0
    if (mf.GetGlobalGenerator()->ShouldWarnExperimental(data.Name, *value)) {
123
0
      if (enabled) {
124
0
        mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
125
0
      } else {
126
0
        mf.IssueMessage(
127
0
          MessageType::AUTHOR_WARNING,
128
0
          cmStrCat(
129
0
            data.Variable, " is set to incorrect value\n  ", value,
130
0
            "\n"
131
0
            "See 'Help/dev/experimental.rst' in the source tree of this "
132
0
            "version of CMake for documentation of the experimental feature "
133
0
            "and the corresponding activation value.  This project's code "
134
0
            "may require changes to work with this CMake's version of the "
135
0
            "feature."));
136
0
      }
137
0
    }
138
0
  }
139
140
0
  return enabled;
141
0
}