Does anyone have an example CMake toolchain file for ARM Cortex M4 using ARM compiler 6 (armclang) for Windows please?
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:
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.
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 …)
@PlatonCM Thanks again for your CMakeLists.txt, that helped me a lot.
My CMake cache generation is failing (on Windows):
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?
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
Thanks for your reply. I’m working on Windows. I found the following very helpful and it’s working now:
That’s an excellent resource. It’s actually where I started. I should have pointed that out…
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