[cmake-developers] Language generator expressions
Brad King
brad.king at kitware.com
Fri May 17 09:41:16 EDT 2013
On 05/17/2013 09:33 AM, Stephen Kelly wrote:
> add_library(foo a.c b.cpp c.c d.cpp)
> target_compile_definitions(foo
> PRIVATE
> $<$<COMPILE_LANGUAGE:C>:C_ONLY>
> $<$<COMPILE_LANGUAGE:CXX>:CXX_ONLY>
> $<$<LINK_LANGUAGE:CXX>:LINK_AS_CXX>
> )
>
> a.c and c.c get compiled with -DC_ONLY, b.cpp and d.cpp get compiled with
> CXX_ONLY, and all get compiled with LINK_AS_CXX.
In order to implement that in the IDE generators you will need to generate
per-source flags for every source file with the corresponding target-wide
per-language flags.
* VS: Once you have per-source flags then VS can no longer invoke the
"cl" compiler with multiple sources on the command line so compile
times will significantly suffer.
* Xcode: There is no way to express per-source per-config flags
(or at least there wasn't last time I checked a few years ago)
We already gloss over the difference between CMAKE_C_FLAGS and
CMAKE_CXX_FLAGS in the IDE generators by using the one corresponding
to the target link language IIRC.
-Brad
More information about the cmake-developers
mailing list