-
Notifications
You must be signed in to change notification settings - Fork 19
Using IAR Build Tools with CMake Presets
This article brings a configuration approach that enables developers to integrate the IAR C/C++ Compiler toolchain with CMake's preset system.
CMakePresets.json, introduced in CMake 3.19, is an optional file that should be located at the top-level of your project and allows for reproducible and shareable build configurations without relying on environment variables or command-line arguments. This integration is particularly useful for cross-compilation to architectures like ARM Cortex-M, RISC-V, RL78, and RX, leveraging IAR's high-performance compilers while maintaining CMake's flexibility.
CMake Presets contain information how to configure, buil and test a project. Below you can see an outline of how it looks like:
{
"configurePresets": [
{
// ...
}
],
"buildPresets": [
{
// ...
}
],
"testPresets": [
{
// ...
}
]
}Before entering CMake Presets, make sure your compiler is working properly as in the example below (for arm):
echo "int main(){}" | /path/to/iccarm --output /tmp/test.o -The template below comes pre-configured to work with cxarm-9.70.1 on Linux:
{
"version": 10,
"configurePresets": [
{
"name": "default",
"hidden": true,
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS":true
},
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/build"
},
{
"name": "cxarm-linux",
"displayName": "CXARM",
"description": "Configure project for CXARM",
"inherits": "default",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"environment": {
"CC": "/opt/iar/cxarm/arm/bin/iccarm",
"CXX": "/opt/iar/cxarm/arm/bin/iccarm",
"ASM": "/opt/iar/cxarm/arm/bin/iasmarm"
}
}
],
"buildPresets": [
{
"name": "debug",
"displayName": "Debug",
"description": "Disable optimizations - include debug information.",
"configurePreset": "cxarm-linux",
"configuration": "Debug"
},
{
"name": "release",
"displayName": "Release",
"description": "Optimize for speed - exclude debug information.",
"configurePreset": "cxarm-linux",
"configuration": "Release"
},
{
"name": "relwithdebinfo",
"displayName": "RelWithDebInfo",
"description": "Optimize for speed - include debug information.",
"configurePreset": "cxarm-linux",
"configuration": "RelWithDebInfo"
},
{
"name": "minsizerel",
"displayName": "MinSizeRel",
"description": "Optimize for smallest binary size - exclude debug information.",
"configurePreset": "cxarm-linux",
"configuration": "MinSizeRel"
}
]
}Amongst the many ways of building a CMake project with IAR, it is possible to use CMake Presets. The project comes with a preset for cxarm which generates its default build scripts. Below you will find some simple sequence of commands:
# Configure the project (Debug, Release, RelWithDebInfo, MinSizeRel)
$ cmake --preset cxarm
# Build the Debug configuration
$ cmake --build --preset debugIn addition, the CMakePresets.json file is also consumed by the CMake Tools VS Code Extension and integrates well with the lightweight IDE and a more complete example can be seen in modern-workflow.
CMake presets are a great way to programmatically setup the underlying host environment for use within cross-platform scenarios, even if it is not mandatory for any CMake project per se (e.g., using a toolchain file). The proposed template can be used as an starting point, checked into version control, and extended as needed.
This is the cmake-tutorial wiki. Back to Wiki Home
- IAR Compiler options in a CMake project
- IAR ILINK options in a CMake project
- Language-specific target options
- Selecting build types
- Using Ninja Multi-Config
- Filing a build log
- Multi-file compilation
- Invoking IAR binary utilities
- Use the IAR ELF Tool to convert executable targets to their binary formats
- Using IAR Build Tools with CMake Presets