1.7 切换构建类型
具体实施
cmake_minimum_required(VERSION 3.5 FATAL_ERROR) project(recipe-07 LANGUAGES C CXX)if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) endif() message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")message(STATUS "C flags, Debug configuration: ${CMAKE_C_FLAGS_DEBUG}") message(STATUS "C flags, Release configuration: ${CMAKE_C_FLAGS_RELEASE}") message(STATUS "C flags, Release configuration with Debug info: ${CMAKE_C_FLAGS_RELWITHDEBINFO}") message(STATUS "C flags, minimal Release configuration: ${CMAKE_C_FLAGS_MINSIZEREL}") message(STATUS "C++ flags, Debug configuration: ${CMAKE_CXX_FLAGS_DEBUG}") message(STATUS "C++ flags, Release configuration: ${CMAKE_CXX_FLAGS_RELEASE}") message(STATUS "C++ flags, Release configuration with Debug info: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") message(STATUS "C++ flags, minimal Release configuration: ${CMAKE_CXX_FLAGS_MINSIZEREL}")$ mkdir -p build $ cd build $ cmake .. ... -- Build type: Release -- C flags, Debug configuration: -g -- C flags, Release configuration: -O3 -DNDEBUG -- C flags, Release configuration with Debug info: -O2 -g -DNDEBUG -- C flags, minimal Release configuration: -Os -DNDEBUG -- C++ flags, Debug configuration: -g -- C++ flags, Release configuration: -O3 -DNDEBUG -- C++ flags, Release configuration with Debug info: -O2 -g -DNDEBUG -- C++ flags, minimal Release configuration: -Os -DNDEBUG$ cmake -D CMAKE_BUILD_TYPE=Debug .. -- Build type: Debug -- C flags, Debug configuration: -g -- C flags, Release configuration: -O3 -DNDEBUG -- C flags, Release configuration with Debug info: -O2 -g -DNDEBUG -- C flags, minimal Release configuration: -Os -DNDEBUG -- C++ flags, Debug configuration: -g -- C++ flags, Release configuration: -O3 -DNDEBUG -- C++ flags, Release configuration with Debug info: -O2 -g -DNDEBUG -- C++ flags, minimal Release configuration: -Os -DNDEBUG
工作原理
更多信息
Last updated