Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何正确检查 CMake 中是否定义了宏?
macro(foo) message("foo") endmacro() if(<what goes here?>) foo() endif()
if 命令COMMAND为此目的支持一个子句:
COMMAND
if(COMMAND foo) foo() endif()
使用给定目录的MACROS属性。
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)