# CMake toolchain file for ARM Compiler 6 ?

**URL:** https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221
**Category:** Usage
**Created:** [October 7, 2021, 10:06am UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221 "2021-10-07T10:06:33Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [October 7, 2021, 10:06am UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/1 "2021-10-07T10:06:33Z")

</div>

Does anyone have an example CMake toolchain file for ARM Cortex M4 using ARM compiler 6 (armclang) for Windows please?

---

<div class="post-metadata">

### Author: ![PlatonCM](https://discourse.cmake.org/user_avatar/discourse.cmake.org/platoncm/32/1910_2.png) [@PlatonCM](https://discourse.cmake.org/u/PlatonCM)
#### Post date: [October 28, 2021, 11:46am UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/2 "2021-10-28T11:46:38Z")

</div>

I’ve just made a toolchain file for ARM Cortex M4 using ARM compiler **5 (armcc)** and will have to address armclang in the future. I expect it to be similar though.  
The toolchain files for armclang, that ship with CMake (\<CMAKE\_ROOT\>/Modules/Compiler/ARMClang.cmake and friends) should handle most of it. In my case, I only had to set the paths to my local executables. My toolchain file looks like this:

```auto
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION "5")
set(CMAKE_SYSTEM_PROCESSOR ARM)

set(TOOLCHAIN_PATH C:/Keil_v5/ARM/ARMCC)
find_program(ARM_CC NAMES armcc PATHS ${TOOLCHAIN_PATH}/bin REQUIRED NO_DEFAULT_PATH)
find_program(ARM_CXX NAMES armcc PATHS ${TOOLCHAIN_PATH}/bin REQUIRED NO_DEFAULT_PATH)
find_program(ARM_ASM NAMES armasm PATHS ${TOOLCHAIN_PATH}/bin REQUIRED NO_DEFAULT_PATH)
find_program(ARM_AR NAMES armar PATHS ${TOOLCHAIN_PATH}/bin REQUIRED NO_DEFAULT_PATH)
find_program(ARM_LINK NAMES armlink PATHS ${TOOLCHAIN_PATH}/bin REQUIRED NO_DEFAULT_PATH)
find_program(ARM_FROMELF NAMES fromelf PATHS ${TOOLCHAIN_PATH}/bin REQUIRED NO_DEFAULT_PATH)

set(CMAKE_C_COMPILER ${ARM_CC} CACHE STRING "")
set(CMAKE_CXX_COMPILER ${ARM_CXX} CACHE STRING "")
set(CMAKE_ASM_COMPILER ${ARM_ASM} CACHE STRING "")
set(CMAKE_LINKER ${ARM_LINK} CACHE STRING "")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PATH})

```

Perhaps, this will get you started.  
I deliberatly did not include anything specifi to the M4 in the toolchain file because we use the same compiler with the M0 and M7 as well.

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 11, 2021, 9:57am UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/3 "2021-11-11T09:57:17Z")

</div>

@PlatonCM Thank you for this. If you update for armclang in the future, please share it.

---

<div class="post-metadata">

### Author: ![PlatonCM](https://discourse.cmake.org/user_avatar/discourse.cmake.org/platoncm/32/1910_2.png) [@PlatonCM](https://discourse.cmake.org/u/PlatonCM)
#### Post date: [November 11, 2021, 10:10am UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/4 "2021-11-11T10:10:02Z")

</div>

Essentially, only the name of the compiler and the path will change:

set(TOOLCHAIN\_PATH C:/Keil\_v5/ARM/ARMCC → C:/Keil\_v5/ARM/ARMCLANG)  
find\_program(ARM\_CC NAMES armcc → armclang …)

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 11, 2021, 10:11am UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/5 "2021-11-11T10:11:53Z")

</div>

@PlatonCM Thanks

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [December 22, 2021, 11:19am UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/6 "2021-12-22T11:19:29Z")

</div>

@PlatonCM Thanks again for your CMakeLists.txt, that helped me a lot.

My CMake cache generation is failing (on Windows):

```auto
d>cmake .. -G "Unix Makefiles"
In toolchain file CMAKE_C_COMPILER = ''
In CMAKE_CXX_COMPILER = ''
-- The CXX compiler identification is GNU 10.3.1
-- The C compiler identification is GNU 10.3.1
-- Detecting CXX compiler ABI info
CMake Error: Generator: execution of make failed. Make command was: -f Makefile cmTC_9b4ae/fast &&
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-g++.exe
CMake Error: Generator: execution of make failed. Make command was: -f Makefile cmTC_b6b9d/fast &&
-- Check for working CXX compiler: C:/Program Files (x86)/GNU Arm Embedd┌────────────────────────────┐m-none-eabi-g++.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.20/Modules/CMakeTest│Enter char to copy up to: │:
  The C++ compiler └────────────────────────────┘

    "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-g++.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/<snip>/build/CMakeFiles/CMakeTmp

    Run Build Command(s): -f Makefile cmTC_b6b9d/fast && The parameter is incorrect
    Generator: execution of make failed. Make command was: -f Makefile cmTC_b6b9d/fast &&

  CMake will not be able to correctly generate this project.

```

Did you see anything similar?

---

<div class="post-metadata">

### Author: ![PlatonCM](https://discourse.cmake.org/user_avatar/discourse.cmake.org/platoncm/32/1910_2.png) [@PlatonCM](https://discourse.cmake.org/u/PlatonCM)
#### Post date: [December 22, 2021, 12:57pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/7 "2021-12-22T12:57:16Z")

</div>

I am using Ninja and haven’t seen that kind of output.  
For what it’s worth, running a configuration in VS code yields:  
`[main] Configuring folder: BuildSystem [proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -Wdev --check-system-vars -DNDEBUG:STRING=1 -DEX1_ARCH:STRING=M4 -DEX1_SYSTEM:STRING=LoMa -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../CMake/toolchain/arm-keil.cmake -Hd:/Projects/Misc/BuildSystem/Source -Bd:/Projects/Misc/BuildSystem/Build -G "Ninja Multi-Config" [cmake] Not searching for unused variables given on the command line. [cmake] Also check system files when warning about unused and uninitialized variables. [cmake] Beginning of D:/Projects/Misc/BuildSystem/Source/CMakeLists.txt. [cmake] Processing arm-keil.cmake... [cmake] Processed arm-keil.cmake. [cmake] Processing arm-keil.cmake... [cmake] Processed arm-keil.cmake. [cmake] -- The C compiler identification is ARMCC 5.6.960 [cmake] -- The CXX compiler identification is ARMCC 5.6.960 [cmake] -- The ASM compiler identification is ARMCC [cmake] -- Found assembler: C:/Keil_v5/ARM/ARMCC/bin/armasm.exe [cmake] -- Detecting C compiler ABI info [cmake] Processing arm-keil.cmake... [cmake] Processed arm-keil.cmake. [cmake] -- Detecting C compiler ABI info - done [cmake] -- Check for working C compiler: C:/Keil_v5/ARM/ARMCC/bin/armcc.exe - skipped [cmake] -- Detecting CXX compiler ABI info [cmake] Processing arm-keil.cmake... [cmake] Processed arm-keil.cmake. [cmake] -- Detecting CXX compiler ABI info - done [cmake] -- Check for working CXX compiler: C:/Keil_v5/ARM/ARMCC/bin/armcc.exe - skipped [cmake] Cortex-M4 set. [cmake] Beginning of D:/Projects/Misc/BuildSystem/Source/HC-Q/CMakeLists.txt. [cmake] End of D:/Projects/Misc/BuildSystem/Source/HC-Q/CMakeLists.txt. [cmake] End of D:/Projects/Misc/BuildSystem/Source/CMakeLists.txt. [cmake] -- Configuring done [cmake] -- Generating done [cmake] -- Build files have been written to: D:/Projects/Misc/BuildSystem/Build`

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [December 22, 2021, 6:50pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/8 "2021-12-22T18:50:17Z")

</div>

Thanks for your reply. I’m working on Windows. I found the following very helpful and it’s working now:

[CMake Part 4 – Windows 10 Host](https://blog.feabhas.com/2021/09/cmake-part-4-windows-10-host/)

---

<div class="post-metadata">

### Author: ![PlatonCM](https://discourse.cmake.org/user_avatar/discourse.cmake.org/platoncm/32/1910_2.png) [@PlatonCM](https://discourse.cmake.org/u/PlatonCM)
#### Post date: [December 22, 2021, 6:56pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/9 "2021-12-22T18:56:03Z")

</div>

That’s an excellent resource. It’s actually where I started. I should have pointed that out…

---

<div class="post-metadata">

### Author: ![SadE](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sade/32/848_2.png) [@SadE](https://discourse.cmake.org/u/SadE)
#### Post date: [September 16, 2022, 3:03pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-for-arm-compiler-6/4221/10 "2022-09-16T15:03:38Z")

</div>

Hi ,

Did you have some problem with the linking part with armcc 5 ? The flag generated by cmake for ninja was not the good one in my case when armclink is used .  
Here’s the link to the problem : [Link libraries with armcc/armlink](https://discourse.cmake.org/t/link-libraries-with-armcc-armlink/1928)
