foreach loop variable still defined but emtpy after scope
Variables declared as loop variables in other languages are typically only available within the loop scope. However CMake has a strange mixed behavior. The variable is empty but defined after the loop.
macro(print)
message("var: ${var}")
if(DEFINED var)
message("is set")
else()
message("is not set")
endif()
if("${var}" STREQUAL "")
message("is empty")
else()
message("is not empty")
endif()
endmacro()
foreach(var IN ITEMS a b c)
print()
endforeach()
print()
Output:
var: a
is set
is not empty
var: b
is set
is not empty
var: c
is set
is not empty
var:
is set
is empty
Expected:
- that last 'is set' should not be