Selecting build types - iarsystems/cmake-tutorial GitHub Wiki
Introduction
The IAR driver built into CMake provides different compiler optimization flags depending on the selected build type.
Helpful Resources
Description
The CMake variable CMAKE_CONFIGURATION_TYPES provides four build configurations and also allows user custom build configurations.
As per CMake 3.28.1, the default build configuration types and their differences are:
Build configuration | Initial options for the IAR compiler |
---|---|
Debug |
-r |
Release |
-Oh -DNDEBUG |
RelWithDebInfo |
-Oh -DNDEBUG -r |
MinSizeRel |
-Ohz -DNDEBUG |
Tasks
- Select the desired CMAKE_BUILD_TYPE at configure-time. For example, for building using high optimization for minimal binary size:
mkdir build-MinSizeRel
cd build-MinSizeRel
cmake .. -G Ninja --toolchain /path/to/your-iar-toolchain-file.cmake -DCMAKE_BUILD_TYPE=MinSizeRel
[!NOTE] When the project is built, the compiler will initially get the selected optimization flags (
-Ohz -DNDEBUG
).