/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 "cmDiagnostics.h" |
11 | | #include "cmGlobalGenerator.h" |
12 | | #include "cmMakefile.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 | | // MappedPackageInfo |
33 | | { "MappedPackageInfo", |
34 | | "ababa1b5-7099-495f-a9cd-e22d38f274f2", |
35 | | "CMAKE_EXPERIMENTAL_MAPPED_PACKAGE_INFO", |
36 | | "CMake's support for generating package information in the Common Package " |
37 | | "Specification format from CMake script exports is experimental. It is " |
38 | | "meant only for experimentation and feedback to CMake developers.", |
39 | | {}, |
40 | | cmExperimental::TryCompileCondition::Always }, |
41 | | // ExportBuildDatabase |
42 | | { "ExportBuildDatabase", |
43 | | "70ef007e-b743-492d-9407-e35eeac03a40", |
44 | | "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE", |
45 | | "CMake's support for exporting build databases is experimental. It is " |
46 | | "meant only for experimentation and feedback to CMake developers.", |
47 | | {}, |
48 | | cmExperimental::TryCompileCondition::Never }, |
49 | | // Rust support |
50 | | { "Rust", |
51 | | "628f8f9f-d7dc-4a06-9aaf-d4ede4426ddf", |
52 | | "CMAKE_EXPERIMENTAL_RUST", |
53 | | "CMake's support for the Rust programming language is experimental. " |
54 | | "It is meant only for experimentation and feedback to CMake developers.", |
55 | | {}, |
56 | | cmExperimental::TryCompileCondition::Never }, |
57 | | // SYCL support |
58 | | { "SYCL", |
59 | | "c0d1fb10-2ece-420e-9d29-7d7f2b300f25", |
60 | | "CMAKE_EXPERIMENTAL_SYCL", |
61 | | "CMake's support for the SYCL programming language is experimental. " |
62 | | "It is meant only for experimentation and feedback to CMake developers.", |
63 | | {}, |
64 | | cmExperimental::TryCompileCondition::Never }, |
65 | | }; |
66 | | static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) == |
67 | | static_cast<size_t>(cmExperimental::Feature::Sentinel), |
68 | | "Experimental feature lookup table mismatch"); |
69 | | |
70 | | cmExperimental::FeatureData const& DataForFeature(cmExperimental::Feature f) |
71 | 0 | { |
72 | 0 | assert(f != cmExperimental::Feature::Sentinel); |
73 | 0 | return LookupTable[static_cast<size_t>(f)]; |
74 | 0 | } |
75 | | } |
76 | | |
77 | | cmExperimental::FeatureData const& cmExperimental::DataForFeature(Feature f) |
78 | 0 | { |
79 | 0 | return ::DataForFeature(f); |
80 | 0 | } |
81 | | |
82 | | cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName( |
83 | | std::string const& name) |
84 | 0 | { |
85 | 0 | size_t idx = 0; |
86 | 0 | for (auto const& feature : LookupTable) { |
87 | 0 | if (feature.Name == name) { |
88 | 0 | return static_cast<Feature>(idx); |
89 | 0 | } |
90 | 0 | ++idx; |
91 | 0 | } |
92 | | |
93 | 0 | return {}; |
94 | 0 | } |
95 | | |
96 | | bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f) |
97 | 0 | { |
98 | 0 | bool enabled = false; |
99 | 0 | FeatureData const& data = cmExperimental::DataForFeature(f); |
100 | |
|
101 | 0 | if (cmValue value = mf.GetDefinition(data.Variable)) { |
102 | 0 | enabled = *value == data.Uuid; |
103 | |
|
104 | 0 | if (mf.GetGlobalGenerator()->ShouldWarnExperimental(data.Name, *value)) { |
105 | 0 | if (enabled) { |
106 | 0 | mf.IssueDiagnostic(cmDiagnostics::CMD_EXPERIMENTAL, data.Description); |
107 | 0 | } else { |
108 | 0 | mf.IssueDiagnostic( |
109 | 0 | cmDiagnostics::CMD_EXPERIMENTAL, |
110 | 0 | cmStrCat( |
111 | 0 | data.Variable, " is set to incorrect value\n ", value, |
112 | 0 | "\n" |
113 | 0 | "See 'Help/dev/experimental.rst' in the source tree of this " |
114 | 0 | "version of CMake for documentation of the experimental feature " |
115 | 0 | "and the corresponding activation value. This project's code " |
116 | 0 | "may require changes to work with this CMake's version of the " |
117 | 0 | "feature.")); |
118 | 0 | } |
119 | 0 | } |
120 | 0 | } |
121 | |
|
122 | 0 | return enabled; |
123 | 0 | } |