Как проверить, установлена ли переменная в родительской области (в отличие от наследования от бабушки и дедушки) в CMake?
В идеальном мире мне бы хотелось иметь какой-то предикат DEFINED_IN_PARENT_SCOPE
для конструкции if
, поэтому в следующем коде
function(child)
if(DEFINED MYVAR) #First check if the variable is defined in any of the parents
if(DEFINED_IN_PARENT_SCOPE MYVAR)
message("Parent has defined MYVAR")
else()
message("Parent has inherited MYVAR from other function up in the call stack")
endif()
else()
message("No MYVAR defined")
endif()
endfunction()
function(parent1)
set(MYVAR 1)
child()
endfunction()
function(parent2)
child()
endfunction()
function(grandparent1A)
set(MYVAR 1)
parent1()
endfunction()
function(grandparent1B)
parent1()
endfunction()
function(grandparent2A)
set(MYVAR 1)
parent2()
endfunction()
function(grandparent2B)
parent2()
endfunction()
grandparent1A()
grandparent1B()
grandparent2A()
grandparent2B()
даст
Parent has defined MYVAR
Parent has defined MYVAR
Parent has inherited MYVAR from other function up in the call stack
No MYVAR defined
Я мог бы обойти эту проблему, если бы знал, как решить Как записать переменную в родительскую область видимости родителей в CMake? .