mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Experimental: Avoid mutating statically allocated data
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmMessageType.h"
|
||||
#include "cmValue.h"
|
||||
@@ -18,7 +19,7 @@ namespace {
|
||||
* Search for other instances to keep the documentation and test suite
|
||||
* up-to-date.
|
||||
*/
|
||||
cmExperimental::FeatureData LookupTable[] = {
|
||||
cmExperimental::FeatureData const LookupTable[] = {
|
||||
// ExportPackageDependencies
|
||||
{ "ExportPackageDependencies",
|
||||
"1942b4fa-b2c5-4546-9385-83f254070067",
|
||||
@@ -26,8 +27,7 @@ cmExperimental::FeatureData LookupTable[] = {
|
||||
"CMake's EXPORT_PACKAGE_DEPENDENCIES support is experimental. It is meant "
|
||||
"only for experimentation and feedback to CMake developers.",
|
||||
{},
|
||||
cmExperimental::TryCompileCondition::Always,
|
||||
false },
|
||||
cmExperimental::TryCompileCondition::Always },
|
||||
// WindowsKernelModeDriver
|
||||
{ "WindowsKernelModeDriver",
|
||||
"9157bf90-2313-44d6-aefa-67cd83c8be7c",
|
||||
@@ -35,8 +35,7 @@ cmExperimental::FeatureData LookupTable[] = {
|
||||
"CMake's Windows kernel-mode driver support is experimental. It is meant "
|
||||
"only for experimentation and feedback to CMake developers.",
|
||||
{},
|
||||
cmExperimental::TryCompileCondition::Always,
|
||||
false },
|
||||
cmExperimental::TryCompileCondition::Always },
|
||||
// CxxImportStd
|
||||
{ "CxxImportStd",
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444",
|
||||
@@ -44,8 +43,7 @@ cmExperimental::FeatureData LookupTable[] = {
|
||||
"CMake's support for `import std;` in C++23 and newer is experimental. It "
|
||||
"is meant only for experimentation and feedback to CMake developers.",
|
||||
{},
|
||||
cmExperimental::TryCompileCondition::Always,
|
||||
false },
|
||||
cmExperimental::TryCompileCondition::Always },
|
||||
// ImportPackageInfo
|
||||
{ "ImportPackageInfo",
|
||||
"e82e467b-f997-4464-8ace-b00808fff261",
|
||||
@@ -54,8 +52,7 @@ cmExperimental::FeatureData LookupTable[] = {
|
||||
"Specification format (via find_package) is experimental. It is meant "
|
||||
"only for experimentation and feedback to CMake developers.",
|
||||
{},
|
||||
cmExperimental::TryCompileCondition::Always,
|
||||
false },
|
||||
cmExperimental::TryCompileCondition::Always },
|
||||
// ExportPackageInfo
|
||||
{ "ExportPackageInfo",
|
||||
"b80be207-778e-46ba-8080-b23bba22639e",
|
||||
@@ -64,8 +61,7 @@ cmExperimental::FeatureData LookupTable[] = {
|
||||
"Specification format is experimental. It is meant only for "
|
||||
"experimentation and feedback to CMake developers.",
|
||||
{},
|
||||
cmExperimental::TryCompileCondition::Always,
|
||||
false },
|
||||
cmExperimental::TryCompileCondition::Always },
|
||||
// ExportBuildDatabase
|
||||
{ "ExportBuildDatabase",
|
||||
"73194a1d-c0b5-41b9-9190-a4512925e192",
|
||||
@@ -73,8 +69,7 @@ cmExperimental::FeatureData LookupTable[] = {
|
||||
"CMake's support for exporting build databases is experimental. It is "
|
||||
"meant only for experimentation and feedback to CMake developers.",
|
||||
{},
|
||||
cmExperimental::TryCompileCondition::Never,
|
||||
false },
|
||||
cmExperimental::TryCompileCondition::Never },
|
||||
// Instrumentation
|
||||
{ "Instrumentation",
|
||||
"a37d1069-1972-4901-b9c9-f194aaf2b6e0",
|
||||
@@ -82,14 +77,13 @@ cmExperimental::FeatureData LookupTable[] = {
|
||||
"CMake's support for collecting instrumentation data is experimental. It "
|
||||
"is meant only for experimentation and feedback to CMake developers.",
|
||||
{},
|
||||
cmExperimental::TryCompileCondition::Never,
|
||||
false },
|
||||
cmExperimental::TryCompileCondition::Never },
|
||||
};
|
||||
static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
|
||||
static_cast<size_t>(cmExperimental::Feature::Sentinel),
|
||||
"Experimental feature lookup table mismatch");
|
||||
|
||||
cmExperimental::FeatureData& DataForFeature(cmExperimental::Feature f)
|
||||
cmExperimental::FeatureData const& DataForFeature(cmExperimental::Feature f)
|
||||
{
|
||||
assert(f != cmExperimental::Feature::Sentinel);
|
||||
return LookupTable[static_cast<size_t>(f)];
|
||||
@@ -118,16 +112,16 @@ cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName(
|
||||
bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
|
||||
{
|
||||
bool enabled = false;
|
||||
auto& data = ::DataForFeature(f);
|
||||
FeatureData const& data = cmExperimental::DataForFeature(f);
|
||||
|
||||
auto value = mf.GetDefinition(data.Variable);
|
||||
if (value == data.Uuid) {
|
||||
enabled = true;
|
||||
}
|
||||
if (cmValue value = mf.GetDefinition(data.Variable)) {
|
||||
enabled = *value == data.Uuid;
|
||||
|
||||
if (enabled && !data.Warned) {
|
||||
mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
|
||||
data.Warned = true;
|
||||
if (mf.GetGlobalGenerator()->ShouldWarnExperimental(data.Name, *value)) {
|
||||
if (enabled) {
|
||||
mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return enabled;
|
||||
|
@@ -37,13 +37,12 @@ public:
|
||||
|
||||
struct FeatureData
|
||||
{
|
||||
std::string const Name;
|
||||
std::string const Uuid;
|
||||
std::string const Variable;
|
||||
std::string const Description;
|
||||
std::vector<std::string> const TryCompileVariables;
|
||||
TryCompileCondition const ForwardThroughTryCompile;
|
||||
bool Warned;
|
||||
std::string Name;
|
||||
std::string Uuid;
|
||||
std::string Variable;
|
||||
std::string Description;
|
||||
std::vector<std::string> TryCompileVariables;
|
||||
TryCompileCondition ForwardThroughTryCompile;
|
||||
};
|
||||
|
||||
static FeatureData const& DataForFeature(Feature f);
|
||||
|
@@ -2003,6 +2003,7 @@ void cmGlobalGenerator::ClearGeneratorMembers()
|
||||
this->GeneratedFiles.clear();
|
||||
this->RuntimeDependencySets.clear();
|
||||
this->RuntimeDependencySetsByName.clear();
|
||||
this->WarnedExperimental.clear();
|
||||
}
|
||||
|
||||
void cmGlobalGenerator::ComputeTargetObjectDirectory(
|
||||
@@ -3914,3 +3915,11 @@ void cmGlobalGenerator::AddCMakeFilesToRebuild(
|
||||
this->InstallScripts.end());
|
||||
files.insert(files.end(), this->TestFiles.begin(), this->TestFiles.end());
|
||||
}
|
||||
|
||||
bool cmGlobalGenerator::ShouldWarnExperimental(cm::string_view featureName,
|
||||
cm::string_view featureUuid)
|
||||
{
|
||||
return this->WarnedExperimental
|
||||
.emplace(cmStrCat(featureName, '-', featureUuid))
|
||||
.second;
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <cm/optional>
|
||||
#include <cm/string_view>
|
||||
#include <cmext/algorithm>
|
||||
#include <cmext/string_view>
|
||||
|
||||
@@ -681,6 +682,9 @@ public:
|
||||
return configs;
|
||||
}
|
||||
|
||||
bool ShouldWarnExperimental(cm::string_view featureName,
|
||||
cm::string_view featureUuid);
|
||||
|
||||
protected:
|
||||
// for a project collect all its targets by following depend
|
||||
// information, and also collect all the targets
|
||||
@@ -908,6 +912,8 @@ private:
|
||||
// track targets to issue CMP0068 warning for.
|
||||
std::set<std::string> CMP0068WarnTargets;
|
||||
|
||||
std::unordered_set<std::string> WarnedExperimental;
|
||||
|
||||
mutable std::map<cmSourceFile*, std::set<cmGeneratorTarget const*>>
|
||||
FilenameTargetDepends;
|
||||
|
||||
|
Reference in New Issue
Block a user