variable_watch() not triggered when using set() in PARENT_SCOPE
There seem to be a bug which prevents variable_watch()
to catch instances of set()
writing a variable when using PARENT_SCOPE
.
The following MWE exposes the problem:
cmake_minimum_required(VERSION 3.9)
variable_watch(var)
set(var "a")
function(f)
set(var "b" PARENT_SCOPE)
endfunction(f)
f()
message(STATUS "${var}")
I would expect to see two "MODIFIED_ACCESS" log messages, instead I see only one.
Looking at the source, it seems that cmStateSnapshot::RaiseScope(std::string const& var, const char* varDef)
is not calling cmMakefile::AddDefinition(const std::string& name, bool value)
, which would then trigger the variable watch behavior. Instead it goes through cmStateSnapshot
.