我有调试和发布选项的特定配置(不同于MSVC和GCC)。假设我们通过cmake ..
生成默认项目。 CMake是否始终为所有可能的项目配置(调试和发布)生成配置,或者总是只获得一组配置选项?
答案 0 :(得分:3)
正如@cplusplusrat评论的那样,这取决于生成器/构建环境:
单配置环境的默认设置既不是Debug
也不是Release
(请参阅here或here)。
因此,我始终为单配置环境定义一个CMAKE_BUILD_TYPE
作为默认值。你也可以这样做,例如在构建脚本中调用CMake:
<强> mingw_build.cmd 强>
@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
:: usage:
:: mingw_build.cmd <target> <config>
:: <target> - target to be built (default: all)
:: <config> - configuration to be used for build (default: Debug)
if NOT "%1" == "" (set CMAKE_TARGET=%1) else (set CMAKE_TARGET=all)
if NOT "%2" == "" (set CMAKE_BUILD_TYPE=%2) else (set CMAKE_BUILD_TYPE=Debug)
SET CMAKE_BINARY_DIR=%CMAKE_BUILD_TYPE%
IF NOT EXIST "%CMAKE_BINARY_DIR%\Makefile" (
cmake -H"." -B"%CMAKE_BINARY_DIR%" -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -G"MinGW Makefiles"
)
cmake --build %CMAKE_BINARY_DIR% --target %CMAKE_TARGET%
ENDLOCAL
<强> vs_x64_build.cmd 强>
@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
:: usage:
:: vs_x64_build.cmd <target> <config>
:: <target> - target to be built (default: ALL_BUILD)
:: <config> - configuration to be used for build (default: Debug)
if NOT "%1" == "" (SET CMAKE_TARGET=%1) else (SET CMAKE_TARGET=ALL_BUILD)
if NOT "%2" == "" (set CMAKE_BUILD_TYPE=%2) else (set CMAKE_BUILD_TYPE=Debug)
SET CMAKE_BINARY_DIR=x64
IF NOT EXIST "%CMAKE_BINARY_DIR%\*.sln" (
cmake -H"." -B"%CMAKE_BINARY_DIR%" -G"Visual Studio 14 2015 Win64"
)
cmake --build "%CMAKE_BINARY_DIR%" --target "%CMAKE_TARGET%" --config "%CMAKE_BUILD_TYPE%"
ENDLOCAL