cmakereleasebuildconfiguration

Have a CMake project default to the Release build type


How should I make my CMake project default to configuration for a Release rather than a Debug build?


Solution

  • You could try the following:

    if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
      if (NOT CMAKE_BUILD_TYPE)
        set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
      endif()
    endif()