CMake build type default
The default CMAKE_BUILD_TYPE is often desired to be set to Release. CMake environment variable CMAKE_BUILD_TYPE can be a convenient user default.
- Linux add to ~/.profile:
- macOS add to ~/.zshrc:
export CMAKE_BUILD_TYPE=Release
- Windows, set
CMAKE_BUILD_TYPE=Release
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()