Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a macro exists in CMake

Tags:

cmake

How do I correctly check if a macro is defined in CMake?

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

if(<what goes here?>)
    foo()
endif()
like image 856
naderman Avatar asked Dec 03 '12 15:12

naderman


2 Answers

The if command supports a COMMAND clause for that purpose:

if(COMMAND foo)
    foo()
endif()
like image 160
sakra Avatar answered Nov 14 '22 11:11

sakra


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)
like image 41
julp Avatar answered Nov 14 '22 10:11

julp