Have a CMake project default to the Release build type

一世执手 提交于 2019-12-11 11:53:57

问题


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


回答1:


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()



回答2:


I started out with simplistic:

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release")
endif()

but thanks to @RaulLaasner's suggestions, I now do:

if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()

and that seems to be more robust.



来源:https://stackoverflow.com/questions/48832233/have-a-cmake-project-default-to-the-release-build-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!