CMake build type default

The default CMAKE_BUILD_TYPE is often desired to be set to Release. CMake ≥ 3.22 checks environment variable CMAKE_BUILD_TYPE, which can be a convenient user default

On Linux and MacOS add to ~/.bashrc, ~/.zshrc or similar:

export CMAKE_BUILD_TYPE=Release

On Windows, set this via the user environment variable GUI.

We also generally recommend setting the default CMake generator.


For projects used by a range of users who may or may not know to set a default build type, and where the developers want to ensure users are normally getting the full performance of a Release build, use GENERATOR_IS_MULTI_CONFIG:

get_property(gen_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT gen_multi AND NOT (CMAKE_BUILD_TYPE OR DEFINED ENV{CMAKE_BUILD_TYPE}))
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Release can have faster run time than Debug")
endif()