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.
Add -D define flags to the compilation of source files. Adds definitions to the compiler command line for targets in the current directory, whether added before or after this command is invoked, and for the ones in sub-directories added after.
Add compile definitions to a target.
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.
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