如何检查CMake中是否存在宏

时间:2012-12-03 15:20:34

标签: cmake

如何正确检查CMake中是否定义了宏?

macro(foo)
    message("foo")
endmacro()

if(<what goes here?>)
    foo()
endif()

2 个答案:

答案 0 :(得分:19)

if command为此目的支持COMMAND子句:

if(COMMAND foo)
    foo()
endif()

答案 1 :(得分:2)

使用MACROS属性for a given directory

get_directory_property(DEFINED_MACROS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} MACROS)
list(FIND DEFINED_MACROS "foo" MACRO_INDEX)
if(MACRO_INDEX EQUAL -1)
    # macro foo does not exist
else(MACRO_INDEX EQUAL -1)
    # macro foo exists
endif(MACRO_INDEX EQUAL -1)