summaryrefslogtreecommitdiff
path: root/Source/cmExperimental.cxx
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2022-05-24 17:19:59 -0400
committerBen Boeckel <ben.boeckel@kitware.com>2022-06-14 19:27:30 -0400
commitfb289dfcd9be3ceb9dcca20b3f51b779d77e01ee (patch)
tree0b0ed52ebbc25b4e19b8b3717c2b7e71416553b7 /Source/cmExperimental.cxx
parentfffc7813a42b9a2256981b575ef7e1a9799d1adf (diff)
downloadcmake-fb289dfcd9be3ceb9dcca20b3f51b779d77e01ee.tar.gz
cmExperimental: add a mechanism for experimental CMake features
Diffstat (limited to 'Source/cmExperimental.cxx')
-rw-r--r--Source/cmExperimental.cxx56
1 files changed, 56 insertions, 0 deletions
diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx
new file mode 100644
index 0000000000..5689714f1f
--- /dev/null
+++ b/Source/cmExperimental.cxx
@@ -0,0 +1,56 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+
+#include "cmExperimental.h"
+
+#include <cassert>
+#include <cstddef>
+#include <string>
+
+#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmValue.h"
+
+namespace {
+
+/*
+ * The `Uuid` fields of these objects should change periodically.
+ * Search for other instances to keep the documentation and test suite
+ * up-to-date.
+ */
+
+struct FeatureData
+{
+ std::string const Uuid;
+ std::string const Variable;
+ std::string const Description;
+ bool Warned;
+} LookupTable[] = {};
+static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
+ static_cast<size_t>(cmExperimental::Feature::Sentinel),
+ "Experimental feature lookup table mismatch");
+
+FeatureData& DataForFeature(cmExperimental::Feature f)
+{
+ assert(f != cmExperimental::Feature::Sentinel);
+ return LookupTable[static_cast<size_t>(f)];
+}
+}
+
+bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
+{
+ bool enabled = false;
+ auto& data = DataForFeature(f);
+
+ auto value = mf.GetDefinition(data.Variable);
+ if (value == data.Uuid) {
+ enabled = true;
+ }
+
+ if (enabled && !data.Warned) {
+ mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
+ data.Warned = true;
+ }
+
+ return enabled;
+}