Lately, I started developing more on Windows and I now want to determine if I am using clang or clang-cl?
While googling I became aware of CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT. However, I am not finding any documentation about it.
Is it a CMake-internal variable that should not be used by normal developers? Or is it just missing documentation?
If it is internal, is there some other established way to determine with which <mode> value (cl, gcc, g++) for the --driver-mode=<mode> option Clang was called?
Sadly, I realized that CMAKE_<LANG>_SIMULATE_ID is not really helpful.
Whether I use clang or clang-cl it always evaluates to MSVC. CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT on the other hand only evaluates to MSVC if using clang-cl and to GNU for clang.
So what I really need to pass options to Clang with the correct format is CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT.
Is there any reason, why that variable is supposed to be a CMake-internal one?
I would suggest to officially expose it to users and to provide proper documentation to both variables, because the documentation for CMAKE_<LANG>_SIMULATE_ID seems not to reflect what that variable really shows. (It seems more as if CMAKE_<LANG>_SIMULATE_ID determines if I am calling Clang from a Visual Studio prompt but not in what driver-mode it is running.)
You probably could test -? is usable with CheckCompilerFlag.
Or you could see what the default build flags look like to judge which frontend is being used.
If it were me I’d probably just use CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT while checking that it is defined and either MSVC or GNU in case something about CMake changes. You could always propose a patch to document and test the variable.
CMAKE_<LANG>_SIMULATE_ID is telling what kind of ABI compatibility the generated code will have, whereas CMAKE_<LANG>_COMPILER_FONTEND_VARIANT describes what command line options and language extensions the compiler frontend expects.
The clang on Windows you are using has CMAKE_CXX_SIMULATE_ID = MSVC and will generate code that can link with code generated by other MSVC compilers, like Visual Studio. Since, clang's CMAKE_CXX_COMPILER_FRONTEND_VARIANT is GNU it will take the gnu-style command line options.
As you have observed, when CMAKE_CXX_COMPILER_FRONTEND_VARIANT is MSVC the compiler takes the MSVC compatible options.