[CMake] Source List Compilation Depending on Configuration
Jörg Kreuzberger
j.kreuzberger at procitec.de
Mon Jul 21 08:29:41 EDT 2014
Hm, following your suggestion i replace lines
if( "${CMAKE_BUILD_TYPE}" STREQUAL "Release")
add_definitions( -DNDEBUG )
endif()
with
set_directory_properties( PROPERTIES COMPILE_DEFINITIONS_RELEASE "${COMPILE_DEFINITIONS_RELEASE};NDEBUG" )
it didnt worked. ( inspecting e.q. flags.make and compilation )
if i set COMPILE_DEFINITIONS (without config) it worked. This is the point i stuct like above again.
-----Ursprüngliche Nachricht-----
Von: Nils Gladitz <nilsgladitz at gmail.com>
Gesendet: Mo 21.07.2014 12:13
Betreff: Re: [CMake] Source List Compilation Depending on Configuration
An: Jörg Kreuzberger <j.kreuzberger at procitec.de>; cmake at cmake.org;
> On 07/21/2014 11:46 AM, Jörg Kreuzberger wrote:
> > Hi!
> >
> > if i want to add sources to list of compilation i can rely on
> CMAKE_BUILD_TYPE.
> > E.g if i want to add a source file only for release, i append it to list of
> source files only then.
> >
> > BUT: how can i do this for multi configuration like vs?
> > So i want to add it to the sources, so that it appears in vs, but only want
> to compile it in release build?
> >
> > Is there an easy way to handle this?
>
> I don't think CMake supports configuration specific source files (I
> assume this might not be supported by all target build systems?).
>
> It should be possible to use the preprocessor (with configuration
> specific defines through the COMPILE_DEFINITIONS_<CONFIG> property) to
> work around it.
>
> E.g. either guard the source file's content itself with
> #ifdef CONFIG_SPECIFIC_DEFINE
> <source file content>
> #endif
>
> or add a wrapper source file that does something like
>
> #ifdef CONFIG_SPECIFIC_DEFINE
> #include "config1.cpp"
> #endif
>
> or even
>
> #ifdef CONFIG_SPECIFIC_DEFINE
> #include "config1.cpp"
> #else
> #include "config2.cpp"
> #endif
>
> Nils
>
>
>
Mannheim HRB 504702
Geschäftsführer: Dipl.-Ing. (FH) Michael Brenk (Vorsitzender), Dipl.-Ing. (FH) Dipl.-Inf. (FH) Jens Heyen
This e-mail may contain confidential and/or legally protected information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this email is strictly forbidden.
Thank you!
More information about the CMake
mailing list