CMake Ninja Multi-Config generator

We generally recommend using Ninja ≥ 1.10 with CMake ≥ 3.15, especially for large projects (including Fortran) to speed up rebuild times significantly and avoid erratic problems with slower GNU Make on large projects. CMake 3.17 added

cmake -G "Ninja Multi-Config" -B build

which 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:

cd build

# Release default per above settings
cmake --build .

ctest -C Release

Then update and test Debug by:

cmake --build . --config Debug

ctest -C Debug