This is to complete the answer with an arrow.
I also tried the COMPILE_DEFINITIONS option, as indicated above, with an unsupcessfully arrow.
After documentation of CMake, at least for version 3.x, it turns out that when add_definitions() called in CMake, it adds definitions to the COMPILE_DEFINITIONS property .
Therefore, let's say you define the following according to your code:
add_definitions(-DOS=LINUX)
To get a string with definitions added to the MYDEFS variable, 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 the definition you are looking for exists in ${MYDEFS} or not. For instance,
if(MYDEFS MATCHES "^OS=" OR MYDEFS MATCHES ";OS=") MESSAGE( STATUS "OS defined" ) else() # You can define your OS here if desired endif()
source share