Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Source / cmExperimental.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt 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 "cmMakefile.h"
11 #include "cmMessageType.h"
12 #include "cmValue.h"
13
14 namespace {
15
16 /*
17  * The `Uuid` fields of these objects should change periodically.
18  * Search for other instances to keep the documentation and test suite
19  * up-to-date.
20  */
21
22 struct FeatureData
23 {
24   std::string const Uuid;
25   std::string const Variable;
26   std::string const Description;
27   bool Warned;
28 } LookupTable[] = {
29   // CxxModuleCMakeApi
30   { "3c375311-a3c9-4396-a187-3227ef642046",
31     "CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API",
32     "CMake's C++ module support is experimental. It is meant only for "
33     "experimentation and feedback to CMake developers.",
34     false },
35 };
36 static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
37                 static_cast<size_t>(cmExperimental::Feature::Sentinel),
38               "Experimental feature lookup table mismatch");
39
40 FeatureData& DataForFeature(cmExperimental::Feature f)
41 {
42   assert(f != cmExperimental::Feature::Sentinel);
43   return LookupTable[static_cast<size_t>(f)];
44 }
45 }
46
47 bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
48 {
49   bool enabled = false;
50   auto& data = DataForFeature(f);
51
52   auto value = mf.GetDefinition(data.Variable);
53   if (value == data.Uuid) {
54     enabled = true;
55   }
56
57   if (enabled && !data.Warned) {
58     mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
59     data.Warned = true;
60   }
61
62   return enabled;
63 }