Does CMake always generate configurations for all possible project configurations?(CMake 是否总是为所有可能的项目配置生成配置?)
问题描述
我有调试和发布选项的特定配置(MSVC 和 GCC 不同).假设我们通过 cmake ..
生成默认项目.CMake 是否总是为所有可能的项目配置(调试和发布)生成配置,还是总是只获得一组配置选项?
I have specific configuration for debug and release options (diferent for MSVC and for GCC). Say we generate default project via cmake ..
. Does CMake always generate configurations for all possible project configurations (Debug and Release) or one always gets only one set of comfiguration options?
推荐答案
正如@cplusplusrat 所评论的,这取决于生成器/构建环境:
As @cplusplusrat has commented, this depends on the generator/build environment:
- 对于 MSVC 或 XCode 等多配置环境,是的.
- 对于 GCC 等单一配置环境,否.
单配置环境的默认设置既不是 Debug
也不是 Release
(参见 此处 或 此处).
And the default for single-configuration environments is neither Debug
nor Release
(see here or here).
所以我一直定义一个CMAKE_BUILD_TYPE
用于单配置环境作为默认值.你也可以这样做,例如在调用 CMake 的构建脚本中:
So I have always defined one CMAKE_BUILD_TYPE
for single-configuration environments as a default. You could also do this e.g. in build scripts calling 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
这篇关于CMake 是否总是为所有可能的项目配置生成配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CMake 是否总是为所有可能的项目配置生成配置?
基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01