# CMAKE\_\<LANG\>\_COMPILER\_EXTERNAL\_TOOLCHAIN adds -gcc-toolchain not ---gcc-toolchain

**URL:** https://discourse.cmake.org/t/cmake-lang-compiler-external-toolchain-adds-gcc-toolchain-not-gcc-toolchain/5748
**Category:** Usage
**Tags:** comp:gcc, comp:clang
**Created:** [May 27, 2022, 9:01am UTC](https://discourse.cmake.org/t/cmake-lang-compiler-external-toolchain-adds-gcc-toolchain-not-gcc-toolchain/5748 "2022-05-27T09:01:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![samolisov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samolisov/32/2458_2.png) [@samolisov](https://discourse.cmake.org/u/samolisov)
#### Post date: [May 27, 2022, 9:01am UTC](https://discourse.cmake.org/t/cmake-lang-compiler-external-toolchain-adds-gcc-toolchain-not-gcc-toolchain/5748/1 "2022-05-27T09:01:11Z")

</div>

Hello,

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:

```auto
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 `CMAKE_<LANG>_FLAGS` variable.

Thank you for your attention.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 27, 2022, 1:06pm UTC](https://discourse.cmake.org/t/cmake-lang-compiler-external-toolchain-adds-gcc-toolchain-not-gcc-toolchain/5748/2 "2022-05-27T13:06:03Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![samolisov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samolisov/32/2458_2.png) [@samolisov](https://discourse.cmake.org/u/samolisov)
#### Post date: [May 30, 2022, 1:55pm UTC](https://discourse.cmake.org/t/cmake-lang-compiler-external-toolchain-adds-gcc-toolchain-not-gcc-toolchain/5748/3 "2022-05-30T13:55:29Z")

</div>

@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:

```auto
[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).

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 30, 2022, 2:45pm UTC](https://discourse.cmake.org/t/cmake-lang-compiler-external-toolchain-adds-gcc-toolchain-not-gcc-toolchain/5748/4 "2022-05-30T14:45:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![samolisov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samolisov/32/2458_2.png) [@samolisov](https://discourse.cmake.org/u/samolisov)
#### Post date: [June 1, 2022, 10:01am UTC](https://discourse.cmake.org/t/cmake-lang-compiler-external-toolchain-adds-gcc-toolchain-not-gcc-toolchain/5748/5 "2022-06-01T10:01:10Z")

</div>

Hm, I get. Actually the build failed during an ASM file compilation (from libunwind):

```auto
./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_C_COMPILER` and `CMAKE_CXX_COMPILER` variables but not `CMAKE_ASM_COMPILER` and even though CMake is able to find the assembler:

```auto
-- 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`.
