Invoking IAR binary utilities - iarsystems/cmake-tutorial GitHub Wiki
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.
Helpful resources
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
Converting the ELF executable to binary
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
)
Checksumming a firmware image
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. In CMake, passing these parameters as quoted strings while escaping the semicolon becomes a portable solution:
add_custom_target(checksummed ALL
DEPENDS myTarget
COMMAND ${CMAKE_IAR_ELFTOOL}
--silent
--fill="0xFF\;0x0800'0000-0x0800'FFFF"
--checksum="__checksum:4,crc32:Li,0xFFFFFFFF\;0x0800'0000-0x0800'FFFB"
$<TARGET_FILE:myTarget>
$<TARGET_FILE:myTarget>
)
Note that the ticks (
') used for separating nibbles in addresses are supported byielftooland entirely optional.