From fb289dfcd9be3ceb9dcca20b3f51b779d77e01ee Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 24 May 2022 17:19:59 -0400 Subject: cmExperimental: add a mechanism for experimental CMake features --- Source/CMakeLists.txt | 2 ++ Source/cmExperimental.cxx | 56 +++++++++++++++++++++++++++++++++++++++++++++++ Source/cmExperimental.h | 19 ++++++++++++++++ bootstrap | 1 + 4 files changed, 78 insertions(+) create mode 100644 Source/cmExperimental.cxx create mode 100644 Source/cmExperimental.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 95b07cb..e6f7d69 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -543,6 +543,8 @@ set(SRCS cmExecuteProcessCommand.h cmExpandedCommandArgument.cxx cmExpandedCommandArgument.h + cmExperimental.cxx + cmExperimental.h cmExportCommand.cxx cmExportCommand.h cmExportLibraryDependenciesCommand.cxx diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx new file mode 100644 index 0000000..5689714 --- /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 +#include +#include + +#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(cmExperimental::Feature::Sentinel), + "Experimental feature lookup table mismatch"); + +FeatureData& DataForFeature(cmExperimental::Feature f) +{ + assert(f != cmExperimental::Feature::Sentinel); + return LookupTable[static_cast(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; +} diff --git a/Source/cmExperimental.h b/Source/cmExperimental.h new file mode 100644 index 0000000..c2df019 --- /dev/null +++ b/Source/cmExperimental.h @@ -0,0 +1,19 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#pragma once + +#include "cmConfigure.h" // IWYU pragma: keep + +class cmMakefile; + +class cmExperimental +{ +public: + enum class Feature + { + Sentinel, + }; + + static bool HasSupportEnabled(cmMakefile const& mf, Feature f); +}; diff --git a/bootstrap b/bootstrap index 9a87413..fa9f40c 100755 --- a/bootstrap +++ b/bootstrap @@ -337,6 +337,7 @@ CMAKE_CXX_SOURCES="\ cmExecProgramCommand \ cmExecuteProcessCommand \ cmExpandedCommandArgument \ + cmExperimental \ cmExportBuildFileGenerator \ cmExportFileGenerator \ cmExportInstallFileGenerator \ -- cgit v0.12