Adding features

This section covers adding common features to your CMake project. You’ll learn how to add a variety of options commonly needed in C++ projects, like C++11 support, as well as how to support IDEs and more.

Default build type

CMake normally does a “non-release, non debug” empty build type; if you prefer to set the default build type yourself, you can follow this recipe for the default build type modified from the Kitware blog:

  1. set(default_build_type "Release")
  2. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  3. message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
  4. set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
  5. STRING "Choose the type of build." FORCE)
  6. # Set the possible values of build type for cmake-gui
  7. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  8. "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  9. endif()