variable_watch: trigger on variables set via PARENT_SCOPE

Make sure that we also trigger variable watches when a variable
is set in the parent scope.

Fixes: #17827
This commit is contained in:
Matteo Settenvini 2018-04-10 11:16:44 +02:00 committed by Brad King
parent e769e61f99
commit 65198cfd0f
4 changed files with 27 additions and 0 deletions

View File

@ -3838,7 +3838,16 @@ void cmMakefile::RaiseScope(const std::string& var, const char* varDef)
std::ostringstream m;
m << "Cannot set \"" << var << "\": current scope has no parent.";
this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
return;
}
#ifdef CMAKE_BUILD_WITH_CMAKE
cmVariableWatch* vv = this->GetVariableWatch();
if (vv) {
vv->VariableAccessed(var, cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
varDef, this);
}
#endif
}
cmTarget* cmMakefile::AddImportedTarget(const std::string& name,

View File

@ -0,0 +1,2 @@
var MODIFIED_ACCESS a
var MODIFIED_ACCESS b

View File

@ -0,0 +1,15 @@
function(watch variable access value)
message("${variable} ${access} ${value}")
endfunction ()
# --------------
variable_watch(var watch)
set(var "a")
function(f)
set(var "b" PARENT_SCOPE)
endfunction(f)
f()

View File

@ -4,3 +4,4 @@ run_cmake(ModifiedAccess)
run_cmake(NoWatcher)
run_cmake(WatchTwice)
run_cmake(ModifyWatchInCallback)
run_cmake(RaiseInParentScope)