I declared a MMACRO
in the main CmakeList.txt
, using add_definitions( -DMMACRO )
. Then when I check at CMakeList
in a subfolder, where I use
if(COMMAND MMACRO)
#something here
endif()
It is not working. Does anyone know what should I do? Thanks.
copt the answer from the below link cmake: how to check if preprocessor is defined
This is to complete the answer by arrowd.
I also tried the COMPILE_DEFINITIONS option as mentioned above by arrowd unsuccessfully.
Following the documentation of CMake, at least for version 3.x, it turns out that when you call add_definitions() in CMake, it adds the definitions to the COMPILE_DEFINITIONS directory property.
Therefore, lets say you are defining the following as per your code:
add_definitions(-DOS=LINUX) To retrieve the string with the definitions added into the variable "MYDEFS" you can use the following lines in CMake:
get_directory_property(MYDEFS COMPILE_DEFINITIONS) MESSAGE( STATUS "Compile defs contain: " ${MYDEFS} ) Then you can check if in ${MYDEFS} the define you are looking for exists or not. For instance