Does CMake always generate configurations for all possible project configurations?

感情迁移 提交于 2019-11-27 08:25:45

问题


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?


回答1:


As @cplusplusrat has commented, this depends on the generator/build environment:

  • For multi-configuration environments like MSVC or XCode, yes.
  • For single-configuration environments like GCC, no.

And the default for single-configuration environments is neither Debug nor Release (see here or here).

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 


来源:https://stackoverflow.com/questions/38091010/does-cmake-always-generate-configurations-for-all-possible-project-configuration

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