CMake Ninja Multi-Config generator

We generally recommend using Ninja with CMake, especially for large projects. Ninja speeds up rebuild times significantly and avoids erratic problems with slower GNU Make. CMake also has the Ninja Multi-Config generator

cmake -G "Ninja Multi-Config"

that allows building Debug and Release builds or even cross builds without regenerating build*.ninja files for each build type.

Ninja Multi-Config generator options may be used transparently with older CMake and different generators. The default CMake generator can be set with environment variable:

CMAKE_GENERATOR="Ninja Multi-Config"

To make the default multi-config build “Release” while making Debug config also available, add to CMakeLists.txt:

set(CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "Build type selections" FORCE)

Because Release is listed first, the default build type is Release. With those settings, one can quickly build Debug and Release and test like:

cmake -B build

# Release default per above settings
cmake --build build

ctest --test-dir build -C Release

Then update and test Debug by:

cmake --build build --config Debug

ctest --test-dir build -C Debug