Silent propagation of variable into function scope
I have the following code
function(g)
message(STATUS "_DEPS=${_DEPS}")
endfunction()
function(f)
set(_DEPS "_DEPS in f")
g()
endfunction()
f()
This would print
-- _DEPS=_DEPS in f
The problem is that _DEPS
silently propagates into the child scope from f
to g
.
In https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#variables it is said
Note CMake reserves identifiers that:
begin with CMAKE_ (upper-, lower-, or mixed-case), or
begin with CMAKE (upper-, lower-, or mixed-case), or
begin with _ followed by the name of any CMake Command.
But DEPS
is not a CMake command. Since in the future anything can become a CMake command then it makes sense to reserve all identifiers prefixed with _
.
The variable should not silently propagate into the child scope. At least it should give an error.
This is present in CMake version 3.20.5.