Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake add_definitions and COMPILE_DEFINITIONS, how to see them

Tags:

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.

like image 610
edA-qa mort-ora-y Avatar asked Mar 23 '11 10:03

edA-qa mort-ora-y


People also ask

What does Add_definitions do in CMake?

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.

What is Target_compile_definitions?

Add compile definitions to a target.


1 Answers

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.

like image 94
André Avatar answered Sep 23 '22 13:09

André