Skip to content

Invoking IAR binary utilities

Felipe Torrezan edited this page Jul 20, 2026 · 17 revisions

CMake can automatically detect the IAR Build Tools and provide internal variables for them, allowing you to invoke their accompanying binary utilities directly from a CMake project.

Description

The following table describes CMake internal variables that are specific to IAR and return the full path to the executables for the toolchain in use:

cmake_minimum_required() Tool CMake internal variable
3.28 IAR Archive Tool CMAKE_AR
3.31 IAR ELF Dumper CMAKE_IAR_ELFDUMP
3.31 IAR ELF Tool CMAKE_IAR_ELFTOOL
3.31 IAR ELF Exe to Object Tool CMAKE_IAR_EXE2OBJ
3.31 IAR Object File Manipulator CMAKE_IAR_OBJMANIP
3.31 IAR Absolute Symbol Exporter CMAKE_IAR_SYMEXPORT
4.1 IAR C-STAT Command Line Interface CMAKE_IAR_CSTAT
4.1 IAR C-STAT Checks Manifest Handler CMAKE_IAR_CHECKS
4.1 IAR C-STAT Report Generator CMAKE_IAR_REPORT

Important

Please note that these references expect their respective tools to be available in the installed toolchain.

Examples

In the example below, the IAR ELF Tool is used at the post-build stage for converting the executable output from myTarget to its binary form, in the Intel Extended format (*.hex):

add_custom_command(TARGET myTarget 
  POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} 
    --silent 
    --ihex 
    $<TARGET_FILE:myTarget> 
    $<TARGET_FILE_DIR:myTarget>/myTarget.hex
)

In the example below, the IAR ELF Tool is used at the post-build stage for checksumming an application within an explicit range. Please note that the --fill and --checksum options require semicolon within its parameters which clash with certain shell rules. A portable solution is to pass those parameters as quoted strings while escaping the semicolon:

add_custom_command(TARGET myTarget 
  POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} 
    --verbose
    --fill="0xFF\;0x0800'0000-0x0800'FFFF"
    --checksum="__checksum:4,crc32:Li,0xFFFFFFFF\;0x0800'0000-0x0800'FFFF"
    $<TARGET_FILE:myTarget>
    $<TARGET_FILE:myTarget>
)

Note that the ticks (') used for separating nibbles in addresses are supported by ielftool and entirely optional.


Related resources

Clone this wiki locally