diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 2aa6c0cb5..c67f88471 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -87,9 +87,24 @@ char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key, } return this->EmptyVariable; } + if ( strcmp(key, "CACHE") == 0 ) + { + if(const char* c = this->Makefile->GetCacheManager()->GetCacheValue(var)) + { + if(this->EscapeQuotes) + { + return this->AddString(cmSystemTools::EscapeQuotes(c).c_str()); + } + else + { + return this->AddString(c); + } + } + return this->EmptyVariable; + } cmOStringStream e; e << "Syntax $" << key << "{} is not supported. " - << "Only ${} and ENV{} are allowed."; + << "Only ${}, $ENV{}, and $CACHE{} are allowed."; this->SetError(e.str()); return 0; } diff --git a/Tests/Unset/CMakeLists.txt b/Tests/Unset/CMakeLists.txt index 05a7e03d8..bacb6d21f 100644 --- a/Tests/Unset/CMakeLists.txt +++ b/Tests/Unset/CMakeLists.txt @@ -32,6 +32,20 @@ if(NOT DEFINED BAR) message(FATAL_ERROR "BAR not defined") endif(NOT DEFINED BAR) +# Test interaction of cache entries with variables. +set(BAR "test-var") +if(NOT "$CACHE{BAR}" STREQUAL "test") + message(FATAL_ERROR "\$CACHE{BAR} changed by variable BAR") +endif(NOT "$CACHE{BAR}" STREQUAL "test") +if(NOT "${BAR}" STREQUAL "test-var") + message(FATAL_ERROR "\${BAR} not separate from \$CACHE{BAR}") +endif(NOT "${BAR}" STREQUAL "test-var") +unset(BAR) +if(NOT "${BAR}" STREQUAL "test") + message(FATAL_ERROR "\${BAR} does not fall through to \$CACHE{BAR}") +endif(NOT "${BAR}" STREQUAL "test") + +# Test unsetting of CACHE entry. unset(BAR CACHE) if(DEFINED BAR) message(FATAL_ERROR "BAR still defined")