diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 9af59b9ee9..fd9cd225f3 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -7,6 +7,7 @@ #include #include +#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(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(f)]; @@ -118,16 +112,16 @@ cm::optional 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; diff --git a/Source/cmExperimental.h b/Source/cmExperimental.h index f68fa8745d..d812b250d5 100644 --- a/Source/cmExperimental.h +++ b/Source/cmExperimental.h @@ -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 const TryCompileVariables; - TryCompileCondition const ForwardThroughTryCompile; - bool Warned; + std::string Name; + std::string Uuid; + std::string Variable; + std::string Description; + std::vector TryCompileVariables; + TryCompileCondition ForwardThroughTryCompile; }; static FeatureData const& DataForFeature(Feature f); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 4fcb950e08..6ec7e6d21f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -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; +} diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index f6c650f19a..e7b252859d 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -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 CMP0068WarnTargets; + std::unordered_set WarnedExperimental; + mutable std::map> FilenameTargetDepends;