Reputation: 31861
I want to see what the current set of compiler definitions is in my CMake file. Ones automatically specified and the ones I'd added would be great. The COMPILE_DEFINITIONS
macro doesn't appear to contain -- despite what the documentation says.
For example, in the below setup the message never includes GUI_BUILD
add_definitions( -DGUI_BUILD )
message( "COMPILE_DEFINITIONS = ${COMPILE_DEFINITIONS}" )
I don't need to see them in their final form, I just want a quick output to help verify that everything has been configured correctly.
Upvotes: 21
Views: 25593
Reputation: 19337
You want to extract the COMPILE_DEFINITIONS property from the directory. E.g. use the following:
add_definitions( -DDebug )
get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
Then you can simply iterate over them, e.g.:
foreach( d ${DirDefs} )
message( STATUS "Found Define: " ${d} )
endforeach()
message( STATUS "DirDefs: " ${DirDefs} )
Note that definitions may also be associated with targets or source-files instead of directories. And note that they can differ between configurations. Depending on your requirements, you may need to check a large set of different properties.
Upvotes: 28