diff options
author | Brad King <brad.king@kitware.com> | 2009-09-10 20:59:45 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-09-10 20:59:45 (GMT) |
commit | ee2b446c953f278eefff44f964f6e39cdc0fff78 (patch) | |
tree | 0f4213c3893cd8f6e30c6c878230b4c8680e33c5 /Source/cmMakefile.cxx | |
parent | afbe0883094afddb7cbaedcb8d89031ef503ed3b (diff) | |
download | CMake-ee2b446c953f278eefff44f964f6e39cdc0fff78.zip CMake-ee2b446c953f278eefff44f964f6e39cdc0fff78.tar.gz CMake-ee2b446c953f278eefff44f964f6e39cdc0fff78.tar.bz2 |
Create CMake Policy CMP0015 to fix set(CACHE)
The set(CACHE) and option() commands should always expose the cache
value. Previously we failed to expose the value when it was already set
if a local variable definition hid it. When set to NEW, this policy
tells the commands to always remove the local variable definition to
expose the cache value. See issue #9008.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6732eec..8233fef 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1662,6 +1662,57 @@ void cmMakefile::AddDefinition(const char* name, const char* value) #endif } +//---------------------------------------------------------------------------- +void cmMakefile::UseCacheDefinition(cmCacheManager::CacheIterator const& it) +{ + // Check for a local definition that might hide the cache value. + const char* name = it.GetName(); + const char* def = this->Internal->VarStack.top().Get(name); + if(!def) + { + return; + } + + // If the visible value will change then check policy CMP0015. + const char* cache = it.GetValue(); + if(strcmp(def, cache) != 0) + { + cmOStringStream e; + switch (this->GetPolicyStatus(cmPolicies::CMP0015)) + { + case cmPolicies::WARN: + e << "Local variable \"" << name << "\" is set to\n" + << " " << def << "\n" + << "but the CACHE entry of the same name is set to\n" + << " " << cache << "\n" + << "The local variable is hiding the cache value." + << "\n" + << this->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0015); + this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + case cmPolicies::OLD: + // OLD behavior is to leave local definition. + return; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + e << "Local variable \"" << name << "\" is set to\n" + << " " << def << "\n" + << "but the CACHE entry of the same name is set to\n" + << " " << cache << "\n" + << "This command is removing the local variable to expose " + << "the cache value." + << "\n" + << this->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0015); + this->IssueMessage(cmake::FATAL_ERROR, e.str()); + case cmPolicies::NEW: + // NEW behavior is to remove local definition (done below). + break; + } + } + + // Remove the local definition to make the cache value visible. + this->RemoveDefinition(name); +} + void cmMakefile::AddCacheDefinition(const char* name, const char* value, const char* doc, |