/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 | | // CxxImportStd |
33 | | { "CxxImportStd", |
34 | | "451f2fe2-a8a2-47c3-bc32-94786d8fc91b", |
35 | | "CMAKE_EXPERIMENTAL_CXX_IMPORT_STD", |
36 | | "CMake's support for `import std;` in C++23 and newer is experimental. It " |
37 | | "is meant only for experimentation and feedback to CMake developers.", |
38 | | {}, |
39 | | cmExperimental::TryCompileCondition::Always }, |
40 | | // MappedPackageInfo |
41 | | { "MappedPackageInfo", |
42 | | "ababa1b5-7099-495f-a9cd-e22d38f274f2", |
43 | | "CMAKE_EXPERIMENTAL_MAPPED_PACKAGE_INFO", |
44 | | "CMake's support for generating package information in the Common Package " |
45 | | "Specification format from CMake script exports is experimental. It is " |
46 | | "meant only for experimentation and feedback to CMake developers.", |
47 | | {}, |
48 | | cmExperimental::TryCompileCondition::Always }, |
49 | | // ExportBuildDatabase |
50 | | { "ExportBuildDatabase", |
51 | | "73194a1d-c0b5-41b9-9190-a4512925e192", |
52 | | "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE", |
53 | | "CMake's support for exporting build databases is experimental. It is " |
54 | | "meant only for experimentation and feedback to CMake developers.", |
55 | | {}, |
56 | | cmExperimental::TryCompileCondition::Never }, |
57 | | { "GenerateSbom", |
58 | | "ca494ed3-b261-4205-a01f-603c95e4cae0", |
59 | | "CMAKE_EXPERIMENTAL_GENERATE_SBOM", |
60 | | "CMake's support for generating software bill of materials (Sbom) " |
61 | | "information in SPDX format is experimental. It is meant only for " |
62 | | "experimentation and feedback to CMake developers.", |
63 | | {}, |
64 | | cmExperimental::TryCompileCondition::Never }, |
65 | | // Rust support |
66 | | { "Rust", |
67 | | "3cc9b32c-47d3-4056-8953-d74e69fc0d6c", |
68 | | "CMAKE_EXPERIMENTAL_RUST", |
69 | | "CMake's support for the Rust programming language is experimental. " |
70 | | "It is meant only for experimentation and feedback to CMake developers.", |
71 | | {}, |
72 | | cmExperimental::TryCompileCondition::Never }, |
73 | | }; |
74 | | static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) == |
75 | | static_cast<size_t>(cmExperimental::Feature::Sentinel), |
76 | | "Experimental feature lookup table mismatch"); |
77 | | |
78 | | cmExperimental::FeatureData const& DataForFeature(cmExperimental::Feature f) |
79 | 0 | { |
80 | 0 | assert(f != cmExperimental::Feature::Sentinel); |
81 | 0 | return LookupTable[static_cast<size_t>(f)]; |
82 | 0 | } |
83 | | } |
84 | | |
85 | | cmExperimental::FeatureData const& cmExperimental::DataForFeature(Feature f) |
86 | 0 | { |
87 | 0 | return ::DataForFeature(f); |
88 | 0 | } |
89 | | |
90 | | cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName( |
91 | | std::string const& name) |
92 | 0 | { |
93 | 0 | size_t idx = 0; |
94 | 0 | for (auto const& feature : LookupTable) { |
95 | 0 | if (feature.Name == name) { |
96 | 0 | return static_cast<Feature>(idx); |
97 | 0 | } |
98 | 0 | ++idx; |
99 | 0 | } |
100 | | |
101 | 0 | return {}; |
102 | 0 | } |
103 | | |
104 | | bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f) |
105 | 0 | { |
106 | 0 | bool enabled = false; |
107 | 0 | FeatureData const& data = cmExperimental::DataForFeature(f); |
108 | |
|
109 | 0 | if (cmValue value = mf.GetDefinition(data.Variable)) { |
110 | 0 | enabled = *value == data.Uuid; |
111 | |
|
112 | 0 | if (mf.GetGlobalGenerator()->ShouldWarnExperimental(data.Name, *value)) { |
113 | 0 | if (enabled) { |
114 | 0 | mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description); |
115 | 0 | } else { |
116 | 0 | mf.IssueMessage( |
117 | 0 | MessageType::AUTHOR_WARNING, |
118 | 0 | cmStrCat( |
119 | 0 | data.Variable, " is set to incorrect value\n ", value, |
120 | 0 | "\n" |
121 | 0 | "See 'Help/dev/experimental.rst' in the source tree of this " |
122 | 0 | "version of CMake for documentation of the experimental feature " |
123 | 0 | "and the corresponding activation value. This project's code " |
124 | 0 | "may require changes to work with this CMake's version of the " |
125 | 0 | "feature.")); |
126 | 0 | } |
127 | 0 | } |
128 | 0 | } |
129 | |
|
130 | 0 | return enabled; |
131 | 0 | } |