Skip to content

Creating custom build configurations

Felipe Torrezan edited this page Oct 6, 2025 · 8 revisions

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.

Helpful Resources

Interactive example

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.

Tasks

  • 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.cmake module creates two new custom build configurations for the CMake project: HighSpeed and MaxSpeed. 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"
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 MaxSpeed

NOTES

  • You can, instead build with --verbose in 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 --verbose

NOTES

  • The C-SPY simulator provides sampled rough estimates and should not replace actual hardware for cycle-accurate measurements.

Summary

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.

Related Articles

Clone this wiki locally