-
Notifications
You must be signed in to change notification settings - Fork 18
Selecting build types
CMake provides default compiler optimization flags for every default build configuration.
The CMake variable CMAKE_CONFIGURATION_TYPES
provides a list with four default build configurations. The initial options for the IAR C/C++ Compiler in each default configuration are:
Build configuration | Default compiler options | Remarks |
---|---|---|
Debug |
-r |
|
Release |
-Oh -DNDEBUG |
|
RelWithDebInfo |
-Oh -DNDEBUG -r |
|
MinSizeRel |
-Ohz -DNDEBUG |
Disabled by default in "Ninja Multi-Config". See #22266. |
This list can be expanded with user-defined custom build configurations.
The examples below illustrate some relevant differences between configuring a project for the Ninja Multi-Config
and for the Ninja
generators. Note that the generator names are case-sensitive and must be defined at configure-time.
The Ninja Multi-Config generator can be selected at configure-time with -G"Ninja Multi-Config"
:
cmake -Bbuild -G"Ninja Multi-Config" [--toolchain /path/to/your-iar-toolchain-file.cmake]
This command will configure the build system to reside inside the build
directory. For each build configuration, there will be a build/<configuration>
sub-directory containing all the outputs (objects, libraries and executable files). That way, the build
directory can hold all build configuration results at the same time when building the project:
cmake --build build --config debug
cmake --build build --config release
cmake --build build --config relwithdebinfo
cmake --build build --config minsizerel
Note
- At build-time, the configuration name in the
--config <configuration>
parameter is case-insensitive. - Build with
--verbose
for inspecting the command-line details.
The Ninja
generator can be selected at configure-time with -GNinja
. For this generator, the build type for the build system needs to be selected with the CMAKE_BUILD_TYPE
variable. Note that specifying the build-type here is case-sensitive. Example:
cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug [--toolchain /path/to/your-iar-toolchain-file.cmake]
This command will configure the build system for the "Debug" configuration to reside inside the build
directory which will contain all the outputs (objects, libraries and executable files). When building the project:
cmake --build build --verbose
For switching from one build configuration to another there are essentially two options: a) erase build
and reconfigure the build system with a different CMAKE_BUILD_TYPE
, or, b) use a different -B<build-directory>
.
Note
- Build with
--verbose
for inspecting the command-line details.
Which generator should one to use? While we tend to recommend "Ninja Multi-Config" for its simplicity when switching from one build configuration to another. Ultimately both generators are capable and immediately selectable at configure-time, without even touching the CMakeLists.txt project file.
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