Skip to content

Toolchain file template

Felipe Torrezan edited this page Nov 5, 2025 · 5 revisions

This article explains how to use CMake Toolchain Files with the IAR tools.

Description

<toolchain-file>.cmake is an optional file that allows setting up CMake for cross-compiling scenarios. It will tell CMake which compilers to invoke. Its main purpose is to isolate these settings from the project, making it easy to switch between toolchains. The tutorial itself brings some ready made toolchain files.

Template

Before entering CMake, make sure your compiler is working properly as in the example below (for arm):

echo "main(){}" | /path/to/iccarm --output /tmp/test.o -

Template: IAR Build Tools for Arm (Cloud)

The template below comes pre-configured to work with cxarm-9.70.1 on Linux or Windows:

# Toolchain file for the IAR C/C++ Compiler for Arm
# Filename: cxarm.cmake
if (UNIX)
    set(CMAKE_C_COMPILER   "/opt/iar/cxarm/arm/bin/iccarm")
    set(CMAKE_CXX_COMPILER "/opt/iar/cxarm/arm/bin/iccarm")
    set(CMAKE_ASM_COMPILER "/opt/iar/cxarm/arm/bin/iasmarm")
else()
    set(CMAKE_C_COMPILER   "C:/iar/cxarm-9.70.1/arm/bin/iccarm.exe")
    set(CMAKE_CXX_COMPILER "C:/iar/cxarm-9.70.1/arm/bin/iccarm.exe")
    set(CMAKE_ASM_COMPILER "C:/iar/cxarm-9.70.1/arm/bin/iasmarm.exe")
endif()

Template: IAR Build Tools for Arm

The template below comes pre-configured to work with bxarm-9.70.1 on Linux or Windows:

# Toolchain file for the IAR C/C++ Compiler for Arm
# Filename: bxarm.cmake
if (UNIX)
    set(CMAKE_C_COMPILER   "/opt/iarsystems/bxarm/arm/bin/iccarm")
    set(CMAKE_CXX_COMPILER "/opt/iarsystems/bxarm/arm/bin/iccarm")
    set(CMAKE_ASM_COMPILER "/opt/iarsystems/bxarm/arm/bin/iasmarm")
else()
    set(CMAKE_C_COMPILER   "C:/iar/bxarm-9.70.1/arm/bin/iccarm.exe")
    set(CMAKE_CXX_COMPILER "C:/iar/bxarm-9.70.1/arm/bin/iccarm.exe")
    set(CMAKE_ASM_COMPILER "C:/iar/bxarm-9.70.1/arm/bin/iasmarm.exe")
endif()

Template: IAR Embedded Workbench for Arm

The template below comes pre-configured to work with ewarm-9.70.1 on Windows:

# Toolchain file for the IAR C/C++ Compiler for Arm
# Filename: ewarm.cmake
set(CMAKE_C_COMPILER   "C:/iar/ewarm-9.70.1/arm/bin/iccarm.exe")
set(CMAKE_CXX_COMPILER "C:/iar/ewarm-9.70.1/arm/bin/iccarm.exe")
set(CMAKE_ASM_COMPILER "C:/iar/ewarm-9.70.1/arm/bin/iasmarm.exe")

Building a Project with a CMake Toolchain File

Below you will find an exemplary sequence of commands on how to build a project using the cxarm.cmake toolchain file template:

# Configure the project
$ cmake -Bbuild -G"Ninja Multi-Config" --toolchain cxarm.cmake

# Build specifying configurations
$ cmake --build build --config Debug --verbose
$ cmake --build build --config Release --verbose

Summary

CMake toolchain files are a convenient way to file toolchain configurations. They become specially handy when dealing with a number of different toolchain versions, architectures and such. The proposed templates can be used as an starting point, checked into version control, and extended as needed.

Related Resources

Clone this wiki locally