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:
clang-15: error: unknown argument: '-gcc-toolchain'
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
Thank you for your attention.
It seems to be spelled that way if the Clang in use is older than 3.4. What version does CMake think you have for Clang?
@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
A trace through the code which selects the flag would be useful. Dumping out variables used in that logic at that time would also be handy I think.
Hm, I get. Actually the build failed during an ASM file compilation (from libunwind):
./bin/clang -target riscv64-unknown-linux-gnu -gcc-toolchain /usr/riscv64-suse-linux --sysroot=/usr/riscv64-suse-linux/sys-root ... -c lvm-project/libunwind/src/UnwindRegistersSave.S
Because I set the
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: