Adding "-march=" to flags breaks determining compiler ID when cross-compiling with Clang
Recent versions of Clang raise an error when passed a -march=
option that doesn't correspond to the current target triple. Unfortunately, CMake doesn't pass the target triple when determining the compiler ID (because it doesn't know how yet), but it does pass along user-specified flags.
When -march=
is added to flags before the compiler ID is determined, such as on the command-line or in a toolchain file, this causes the compiler ID determination to fail, which then causes all other compiles to fail (since it doesn't know how to pass along the target triple).
I've thought of a couple options:
- Don't pass user-specified flags in CMAKE_DETERMINE_COMPILER_ID. I can't think of any concrete ways this would cause breakage, but I'm sure someone is clever enough to break it.
- Add Clang to
CMAKE_{LANG}_COMPILER_ID_VENDORS
. Works for COMPILER_ID, not for COMPILER_VERSION. - Check with and without user-specified flags in CMAKE_DETERMINE_COMPILER_ID. Behavior should be backwards-compatible, makes code a bit messier.