GenEx: How to transparently distinguish clang GNU from clang-cl adapter?
We have dedicated options line for common compiler's options,
set(GNUC_CXX "$<OR:$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang,GNU>,$<COMPILE_LANG_AND_ID:C,Clang,AppleClang,GNU>>")
...
# options for clang/gcc c and c++
target_compile_options (lextra INTERFACE $<${GNUC_CXX}:-D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -Wall>)
That works suitable and reliable on all affected compilers - gcc, clang, apple clang. (MSVC version has it's own flags, that is not important now)
Some time ago we tried to set up build on Windows with clang. Compiler was identified as clang, so common line for gcc/clang was used.
The problem is that actually it wasn't clang, but clang-cl adapter, and that common line is not suitable in this case, because it expects MSVC options, but this line provides pure clang. Most prominent and cruel confusion here is -Wall
flag, which in context of clang is just -Wall
, but in context of clang-cl became -Weverything
with quite... surprising effect.
Yes, I know, we can prefix every raw clang option with /clang:
when passing it to clang-cl, but it looks quite nasty and non-scalable to walk over whole project configuration and do such fixture to every meet of clang options.
So, does some easy and dev-blessed solution to distinguish between just 'clang' and 'clang-cl' adapter exists?
I've looked to list of variables and see CMAKE_CXX_SIMULATE_ID
, it doesn't has comprehensive documentation, but looks like the one which might help in such situation, don't it? (If so, I expect that $<STREQUAL:${CMAKE_CXX_SIMULATE_ID},"MSVC">
in addition to COMPILE_LANG_AND_ID would help)
Ideally it would be nice to avoid changing stable generator expressions, but in this case clang-cl should not be identified as 'clang' for compile options in generator expressions (but, instead, say 'clangcl', similar as 'AppleClang' distinguished). Or, provide kind of single final cb to transform (prefix) all collected options with /clang:
or whatever.