-
Notifications
You must be signed in to change notification settings - Fork 18
Creating custom build configurations
CMake brings a number of standard build configurations (Debug, Release, RelWithDebInfo and MinSizeRel). However there are cases in which the optimization objective is towards the maximum possible speed. In that case, it is necessary to create a custom build configuration. While this interactive example was tailored to work with the IAR C/C++ Compiler for Arm, it can easily ported to other architectures.
A CMake project example is provided at examples/custom:
| Project files |
|---|
CMakeLists.txt |
iar-cspysim.cmake |
iar-custom.cmake |
sqrt.c |
sqrtf.c |
systick.mac |
The goal of this interactive example is to use 2 custom build configurations created in iar-custom.cmake, configure the project, build the project using different configurations and finally execute simulated tests for multiple configurations.
- Perform the following tasks (click to show/hide answers):
TODO 1: Include the CMake modules to the project
On the CMakeLists.txt project file:
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include(iar-cspysim)
include(iar-custom)- Save the file.
NOTES
- The
iar-custom.cmakemodule creates two new custom build configurations for the CMake project:HighSpeedandMaxSpeed. Inspect the contents of the module for details on their configuration flags.
TODO 2: Configure the project
- Configure the project for using the "Ninja Multi-Config" generator:
cmake -Bbuild -G"Ninja Multi-Config" [--toolchain /path/to/iar-toolchain-file.cmake]NOTES
- CMake uses the host platform's default compiler. When cross-compiling embedded applications, the compiler must be specified (e.g., through environment variables or a toolchain file). See Enabling the IAR Compiler in the cmake-tutorial for other alternatives.
TODO 3: Build all configurations
- With the project configured, build each existing build configuration:
cmake --build build --config Debug
cmake --build build --config Release
cmake --build build --config RelWithDebInfo
cmake --build build --config MinSizeRel
cmake --build build --config HighSpeed
cmake --build build --config MaxSpeedNOTES
- You can, instead build with
--verbosein case you want to see details about the command lines CMake generated for each build configuration.
TODO 4: Test each configuration
- With all build configurations built, you can test them with CTest:
ctest --test-dir build -C debug --verbose
ctest --test-dir build -C maxspeed --verboseNOTES
- The C-SPY simulator provides sampled rough estimates and should not replace actual hardware for cycle-accurate measurements.
This interactive example covered the basics on how to create custom build configurations in CMake. Now you can make use of the *.cmake modules on your projects whenever they require custom configurations, not covered by CMake's defaults.
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