Does
$<COMPILER_CXX_ID:Clang>
will return 1
for Clang
and AppleClang
According to the doc I would say yes but I'm not sure...
1
if the CMake-id of the CXX compiler matches comp, otherwise0
src: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
src: https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
TLDR: When using $<CXX_COMPILER_ID:Clang>
and having CMP0025
to NEW
then AppleClang
won't match it.
First I suppose the policy CMP0025 is set to NEW
to get AppleClang
on MacOS with clang
provided by Xcode
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()
To match both compilers with CMP0025
set to NEW
you have two options
first create a variable:
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(USING_CLANG ON)
else()
set(USING_CLANG OFF)
endif()
note: notice the use of MATCHES
instead of EQUALS
Then you can use it in your generator expression:
target_compile_definition(target PUBLIC
$<$<BOOL:${USING_CLANG}>:-DUSE_CLANG>)
You may also use:
target_compile_definition(target PUBLIC
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-DUSE_CLANG>
You can find a working example at https://github.com/Mizux/cmp0025
note: Don't hesitate to look at the Travis-CI log (by clicking on the build badge)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With