Hi,
I am using an interface library with generator expressions to set specific options that can be consumed by several projects of mine.
As far as I can judge it works as expected, for example:
target_link_options(${target} INTERFACE
$<$<OR:$<LINK_LANG_AND_ID:C,GNU>,$<LINK_LANG_AND_ID:CXX,GNU>>:-Wl,--no-undefined>
$<$<OR:$<LINK_LANG_AND_ID:C,Clang>,$<LINK_LANG_AND_ID:CXX,Clang>>:-Wl,-undefined,error>
)
and
target_compile_options(${target} INTERFACE
-Werror=switch
)
No, I would like to set the C standard for C projects and the C++ standard for C++ projects.
My intention has been to use target_compile_features
for that approach.
target_compile_features(${target} INTERFACE
$<$<COMPILE_LANGUAGE:C>:c_std_17>
)
target_compile_features(${target} INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:cxx_std_17>
)
But this does not work at least for CMake version 3.24.2.
I got this error:
Error evaluating generator expression:
$<COMPILE_LANGUAGE:C>
$<COMPILE_LANGUAGE:...> may only be used to specify include directories,
compile definitions, compile options, and to evaluate components of the
file(GENERATE) command.
I can workaround the error using target_compile_options
target_compile_options(${target} INTERFACE
$<$<COMPILE_LANGUAGE:C>:-std=c17>
)
target_compile_options(${target} INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
)
But I assume I will have to use also the compiler ID some time to handle different ways (arguments) to use the compiler specific way to set the standard.
Can you explain me why target_compile_features
is not working or what I am doing wrong?