cmExperimental: add a mechanism for experimental CMake features
This commit is contained in:
parent
fffc7813a4
commit
fb289dfcd9
@ -543,6 +543,8 @@ set(SRCS
|
||||
cmExecuteProcessCommand.h
|
||||
cmExpandedCommandArgument.cxx
|
||||
cmExpandedCommandArgument.h
|
||||
cmExperimental.cxx
|
||||
cmExperimental.h
|
||||
cmExportCommand.cxx
|
||||
cmExportCommand.h
|
||||
cmExportLibraryDependenciesCommand.cxx
|
||||
|
56
Source/cmExperimental.cxx
Normal file
56
Source/cmExperimental.cxx
Normal file
@ -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;
|
||||
}
|
19
Source/cmExperimental.h
Normal file
19
Source/cmExperimental.h
Normal file
@ -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);
|
||||
};
|
Loading…
Reference in New Issue
Block a user