diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-06-29 11:36:28 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2021-06-29 11:36:28 (GMT) |
commit | 16208ac1132b5624743c3ea534f610541d90ab8f (patch) | |
tree | 8353fc636dc18ad199666d18067ed23944ce26f2 /Source | |
parent | 480bd71b1655e84c1197c6c48bb606c18669548f (diff) | |
download | CMake-16208ac1132b5624743c3ea534f610541d90ab8f.zip CMake-16208ac1132b5624743c3ea534f610541d90ab8f.tar.gz CMake-16208ac1132b5624743c3ea534f610541d90ab8f.tar.bz2 |
CMP0126: Add control for warnings
Fixes: #22353
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmMakefile.cxx | 23 | ||||
-rw-r--r-- | Source/cmProjectCommand.cxx | 4 |
2 files changed, 22 insertions, 5 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d2d34f9..c970abe 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1962,9 +1962,26 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, } } this->GetCMakeInstance()->AddCacheEntry(name, value, doc, type); - if (this->GetPolicyStatus(cmPolicies::CMP0126) != cmPolicies::NEW) { - // if there was a definition then remove it - this->StateSnapshot.RemoveDefinition(name); + switch (this->GetPolicyStatus(cmPolicies::CMP0126)) { + case cmPolicies::WARN: + if (this->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0126") && + this->IsNormalDefinitionSet(name)) { + this->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0126), + "\nFor compatibility with older versions of CMake, normal " + "variable \"", + name, "\" will be removed from the current scope.")); + } + CM_FALLTHROUGH; + case cmPolicies::OLD: + // if there was a definition then remove it + this->StateSnapshot.RemoveDefinition(name); + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + break; } } diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index acdb09f..6950c19 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -71,7 +71,7 @@ bool cmProjectCommand(std::vector<std::string> const& args, // CMAKE_PROJECT_NAME will match PROJECT_NAME, and cmake --build // will work. if (!mf.GetDefinition("CMAKE_PROJECT_NAME") || mf.IsRootMakefile()) { - mf.AddDefinition("CMAKE_PROJECT_NAME", projectName); + mf.RemoveDefinition("CMAKE_PROJECT_NAME"); mf.AddCacheDefinition("CMAKE_PROJECT_NAME", projectName, "Value Computed by CMake", cmStateEnums::STATIC); } @@ -395,7 +395,7 @@ static void TopLevelCMakeVarCondSet(cmMakefile& mf, std::string const& name, // in the same CMakeLists.txt file, and it is the top level // CMakeLists.txt file, then go with the last one. if (!mf.GetDefinition(name) || mf.IsRootMakefile()) { - mf.AddDefinition(name, value); + mf.RemoveDefinition(name); mf.AddCacheDefinition(name, value, "Value Computed by CMake", cmStateEnums::STATIC); } |