我有一个cmake项目如下
./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()
我希望FOO变量从父范围传递到' a'子项目;可能吗?怎么做?
更新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()
现在使用这个"使用来自Parent"
的Foo谢谢@Tsyvarev