I’m trying to cross-compile a project using clang as a compiler and pass the --gcc-toolchain command line argument to the compiler. As I get, the preferable way for this is to use the CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN CMake variable. Unfortunately, CMake (3.23.1, OpenSUSE Linux) passes the parameter’s value in the -gcc-toolchain command line argument (one minus) not in the deserved --gcc-toolchain (two minuses) and clang doesn’t accept the parameter:
Does CMake work as it is expected and there are compilers which accept -gcc-toolchain (with one minus)? If so the only workaround I know is to pass --gcc-toolchain in the CMAKE_<LANG>_FLAGS variable.
@ben.boeckel Thank you for the reply. I tried with a minimum CMake-based project with and without using an ExternalProject and in this situation everything worked as expected: CMake adds the --gcc-toolchain parameter. But when I’m building LLVM with its runtimes (libc++, libc++abi, compiler-rt, etc.) for the RISCV architecture I get what I described in the question: CMake adds the -gcc-toolchain (one minus). An excerpt from the CMake log:
[18/22] Performing configure step for 'runtimes-riscv64-unknown-linux-gnu'
-- The C compiler identification is Clang 15.0.0
-- The CXX compiler identification is Clang 15.0.0
...
-- Compiler version: 15.0.0
(“Compiler version” here means the CMAKE_CXX_COMPILER_VERSION variable).
Because I set the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER variables but not CMAKE_ASM_COMPILER and even though CMake is able to find the assembler:
-- The ASM compiler identification is Clang with GNU-like command-line
Unfortunately, it doesn’t deduce it’s version. CMAKE_ASM_COMPILER_VERSION returns nothing. Even when I set the ASM environment variable to the path to clang, CMake is able to define the CMAKE_ASM_COMPILER:FILEPATH variable in the cache but doesn’t deduce the version of the assembler.
The workaround I’ve found is to set the CMAKE_ASM_COMPILER_VERSION variable manually during the configuration phase: -DRUNTIMES_riscv64-unknown-linux-gnu_CMAKE_ASM_COMPILER_VERSION=15.0.0.