如何在cmake中将变量从父项传递到子项目

时间:2018-05-03 16:32:15

标签: cmake

我有一个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

0 个答案:

没有答案
相关问题