[CMake] compiler defines for sub projects

Olaf Peter ope-devel at gmx.de
Fri Apr 5 13:58:26 EDT 2013


Hello,

is it possible to inherit compiler defines for sub projects in sub 
directories?

I have a library project which can be configured at compile time using 
preprocessor defines (cmake option)

option(FOO_OPTION "enable foo" OFF)
option(BAR_OPTION "enable bar" OFF)


if(FOO_OPTION)
     set_target_properties(my_lib PROPERTIES COMPILE_DEFINITIONS "FOO_X" )
elseif(BAR_OPTION)
     set_target_properties(my_lib PROPERTIES COMPILE_DEFINITIONS "FOO_Y")
else()
     set_target_properties(my_lib PROPERTIES COMPILE_DEFINITIONS "OTHER" )
endif()

now, in the sub of this I have unit tests which need to know about this 
compile defs, hence I have the same if/else again.

Is there an easy way for this?

Thanks,
Olaf


More information about the CMake mailing list