thanks for your answer.

I've forgot to mention in the hurry yesterday, that inisde the lib project generator exist which must not compiled with these defines.

if(FOO_OPTION OR BAR_OPTION)

  add_executable(generator_target ...)
  set_target_properties(generator_target ... COMPILE_DEFINITIONS ...)
endif()

This is the reason for set_target_properties(my_lib ...)

So this solution with add_definitions won't work. Possible it could work if I removed those defs from target.

Thanks,
Olaf

> If you want to have all of the sub directories to have the defines present, you could use ADD_DEFINITIONS().
>
> option(FOO_OPTION "enable foo" OFF)
> option(BAR_OPTION "enable bar" OFF)
>
> if(FOO_OPTION)
>       add_definitions("-DFOO_X" )
> elseif(BAR_OPTION)
>       add_definitions("-DFOO_Y")
> else()
>       add_definitions("-DOTHER")
> endif()
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Olaf Peter
> Sent: Friday, April 05, 2013 12:58 PM
> To: [email protected]
> Subject: [CMake] compiler defines for sub projects
>
> 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
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to