如何正确检查CMake中是否定义了宏?
macro(foo)
message("foo")
endmacro()
if(<what goes here?>)
foo()
endif()
答案 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)