Windows is in the unique position of having two drivers, clang-cl and normal GNU clang, depending on whether a GNU or MSVC target is used. The current implementation with the USE_TOOLCHAIN argument assumes that when CMAKE_SYSTEM_NAME is set to Windows that clang-cl should be used, which is the incorrect choice when targeting a GNU environment.
This patch solves the following:
- If the host is MinGW and USE_TOOLCHAIN is passed as an argument, the GNU style drivers should be selected instead of clang-cl
- If one of CMAKE_(C|ASM|CXX)_COMPILER_TARGET has been passed as cmake arguments it checks whether a windows-gnu or windows-msvc target has been requested and selects accordingly
I discovered these issues when trying to do builds of the runtimes using LLVM_ENABLE_RUNTIMES while having a MinGW target as one of the LLVM_RUNTIME_TARGETS.
Technically, you can have triples in other forms too, like x86_64-win32; win32 is an alias for windows, and if the -msvc suffix is omitted it defaults to the msvc variant.
If this only deals with canonicalized triples it should be fine. And for other cases, I guess it might be fine as well (as you'd get proper results if you pass triples in the expected form at least and we can't expect to mimic all the quirks handled by the llvm internal triple parser).