How do I correctly check if a macro is defined in CMake?
macro(foo)
message("foo")
endmacro()
if(<what goes here?>)
foo()
endif()
The if command supports a COMMAND
clause for that purpose:
if(COMMAND foo)
foo()
endif()
Use MACROS property 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With