unset: Add PARENT_SCOPE option
Add an unset() command option to remove a variable from the calling scope, just like the set() command's PARENT_SCOPE option. Teach the Unset test to cover such cases.
This commit is contained in:
parent
1d9af198a8
commit
261c248254
|
@ -49,7 +49,13 @@ bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
|
||||||
this->Makefile->RemoveCacheDefinition(variable);
|
this->Makefile->RemoveCacheDefinition(variable);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// ERROR: second argument isn't CACHE
|
// unset(VAR PARENT_SCOPE)
|
||||||
|
else if ((args.size() == 2) && (args[1] == "PARENT_SCOPE"))
|
||||||
|
{
|
||||||
|
this->Makefile->RaiseScope(variable, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// ERROR: second argument isn't CACHE or PARENT_SCOPE
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->SetError("called with an invalid second argument");
|
this->SetError("called with an invalid second argument");
|
||||||
|
|
|
@ -61,10 +61,13 @@ public:
|
||||||
virtual const char* GetFullDocumentation() const
|
virtual const char* GetFullDocumentation() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
" unset(<variable> [CACHE])\n"
|
" unset(<variable> [CACHE | PARENT_SCOPE])\n"
|
||||||
"Removes the specified variable causing it to become undefined. "
|
"Removes the specified variable causing it to become undefined. "
|
||||||
"If CACHE is present then the variable is removed from the cache "
|
"If CACHE is present then the variable is removed from the cache "
|
||||||
"instead of the current scope.\n"
|
"instead of the current scope.\n"
|
||||||
|
"If PARENT_SCOPE is present then the variable is removed from the "
|
||||||
|
"scope above the current scope. See the same option in the set() "
|
||||||
|
"command for further details.\n"
|
||||||
"<variable> can be an environment variable such as:\n"
|
"<variable> can be an environment variable such as:\n"
|
||||||
" unset(ENV{LD_LIBRARY_PATH})\n"
|
" unset(ENV{LD_LIBRARY_PATH})\n"
|
||||||
"in which case the variable will be removed from the current "
|
"in which case the variable will be removed from the current "
|
||||||
|
|
|
@ -51,5 +51,32 @@ if(DEFINED BAR)
|
||||||
message(FATAL_ERROR "BAR still defined")
|
message(FATAL_ERROR "BAR still defined")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Test unset(... PARENT_SCOPE)
|
||||||
|
function(unset_zots)
|
||||||
|
if(NOT DEFINED ZOT1)
|
||||||
|
message(FATAL_ERROR "ZOT1 is not defined inside function")
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED ZOT2)
|
||||||
|
message(FATAL_ERROR "ZOT2 is not defined inside function")
|
||||||
|
endif()
|
||||||
|
unset(ZOT1)
|
||||||
|
unset(ZOT2 PARENT_SCOPE)
|
||||||
|
if(DEFINED ZOT1)
|
||||||
|
message(FATAL_ERROR "ZOT1 is defined inside function after unset")
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED ZOT2)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"ZOT2 is not defined inside function after unset(... PARENT_SCOPE)")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
set(ZOT1 1)
|
||||||
|
set(ZOT2 2)
|
||||||
|
unset_zots()
|
||||||
|
if(NOT DEFINED ZOT1)
|
||||||
|
message(FATAL_ERROR "ZOT1 is not still defined after function")
|
||||||
|
endif()
|
||||||
|
if(DEFINED ZOT2)
|
||||||
|
message(FATAL_ERROR "ZOT2 is still defined after function unset PARENT_SCOPE")
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(Unset unset.c)
|
add_executable(Unset unset.c)
|
||||||
|
|
Loading…
Reference in New Issue