CMake宏从流程中间返回?

时间:2014-12-05 01:51:54

标签: cmake

我可以从CMake macro的中间返回吗?我想到的一个用例如下。

macro (my_macro a b c)
    if (NOT USE_${a})
         # I WANT TO RETURN FROM HERE.
    endif ()
    if (NOT USE_${b})
         # I WANT TO RETURN FROM HERE.
    endif ()
    # Do something to c...
endmacro()

1 个答案:

答案 0 :(得分:3)

CMake中的宏基本上是替换,所以你实际上并没有从中返回。我建议你包装" b"和" c"代码到else()

macro (my_macro a b c)
    if (NOT USE_${a})
         # I WANT TO RETURN FROM HERE.
    else ()
    if (NOT USE_${b})
         # I WANT TO RETURN FROM HERE.
    endif ()
    # Do something to c...
    endif(NOT USE_${a})
endmacro()