I have a cmake project as below
./CMakeList.txt
...
option( FOO "foo var" "MyFoo")
add_subproject( a )
./a/CMakeList.txt
...
if("${FOO}" STREQUAL "MyFoo")
message("Using Foo from Parent")
else()
message("Foo not passed from Parent")
endif()
I want the FOO variable to be passed from the parent scope to the 'a' sub project; Is it possible? How to do it?
Update 1
./CMakeList.txt
...
unset(FOO_VAR CACHE)
set( FOO_VAR ${FOO} CACHE STRING "foo variable")
add_subproject( a )
./a/CMakeList.txt
...
string(COMPARE EQUAL "${FOO_VAR}" "MyFoo" result)
if(result)
message("Using Foo from Parent")
else()
message("Foo not passed from Parent")
endif()
using this now I am getting "Using Foo from Parent"
Thanks @Tsyvarev