[cmake-developers] Language generator expressions
Stephen Kelly
steveire at gmail.com
Fri May 17 09:33:17 EDT 2013
Brad King wrote:
> On 05/16/2013 04:43 PM, Stephen Kelly wrote:
>> I've pushed the language-generator-expressions branch to my clone, and
>> the target-COMPILE_OPTIONS branch which depends on it, which should be
>> the implementation of
>>
>> http://public.kitware.com/Bug/view.php?id=6493
>>
>> I hit a problem with the xcode and visual studio generators in that the
>> APIs of them do not provide a source file to use to determine the
>> compiler language at the point where I try to evaluate the compile flags,
>> defines and includes.
>>
>> Is that a limitation of those IDEs? Or just of the generators? Can
>> someone familiar with those generators implement the porting to new APIs
>> I implemented in my branch?
>
> The IDEs do not have per-language settings on a per-target basis.
> C and C++ are treated equally at that level and it is only at the
> per-source-file level that one can distinguish them.
Yes, that is the level I'm missing. I have two types of language genex - one
for the COMPILE_LANGUAGE, and another for the LINK_LANGUAGE.
The LINK_LANGUAGE is always available as target->GetLinkLanguage(config). In
my patch to the makefile and ninja generators so far, the compile language
comes from the source file being compiled, because the cmSourceFile happens
to be available in the method where I need it already. I'm not familiar with
those ide generators, but I'll assume for now that the cmSourceFile can be
passed along to where I need it for the purpose of determining the compile
language.
That way, given this:
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.
I have not added a way to determine if a language is enabled, and I don't
know if such a thing would be useful.
Do you think this is the right direction otherwise?
Thanks,
Steve.
More information about the cmake-developers
mailing list