如何为特定配置生成Visual Studio项目? [英] How can I generate Visual Studio projects for a specific configuration?
问题描述
使用CMake的ExternalProject_Add
,我可以自动构建依赖关系.但是,即使我按照BUILD_SHARED_LIBS
,我构建的配置最终还是不匹配.教程中的php"rel =" nofollow> .
Using CMake's ExternalProject_Add
, I automate builds of my dependencies. However, I build configurations don't match in the end even though I pass CMAKE_BUILD_TYPE
and BUILD_SHARED_LIBS
as described in the Tutorial.
# SFML
include(ExternalProject)
set(SFML_PREFIX ${CMAKE_SOURCE_DIR}/SFML)
# Download, configure, build and install.
ExternalProject_Add(SFML
# DEPENDS
PREFIX ${SFML_PREFIX}
TMP_DIR ${SFML_PREFIX}/temp
STAMP_DIR ${SFML_PREFIX}/stamp
#--Download step--------------
GIT_REPOSITORY https://github.com/LaurentGomila/SFML.git
GIT_TAG e2c378e9d1
#--Update/Patch step----------
UPDATE_COMMAND ""
#--Configure step-------------
SOURCE_DIR ${SFML_PREFIX}/source
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SFML_PREFIX}/install
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
#--Build step-----------------
BINARY_DIR ${SFML_PREFIX}/build
#--Install step---------------
INSTALL_DIR ${SFML_PREFIX}/install
)
# Set root so that find module knows where to look.
set(SFML_ROOT ${SFML_PREFIX}/install)
如何生成一个生成发行版本的Visual Studio项目,而不是不提供任何命令行参数而退回到调试模式?甚至有什么方法可以生成使用一个msbuild Project.sln
构建发布版本和调试版本的项目?
How can I generate a Visual Studio project that builds release versions, instead of falling back to debug mode with no command line arguments provided? Is there even a way to generate a project that builds both release and debug versions with one msbuild Project.sln
?
推荐答案
对于多配置生成器(例如Visual Studio),在构建项目时会指定实际的构建配置(调试或发行版).在配置时设置CMAKE_BUILD_TYPE
无效.
For multi-configuration generators (e.g., Visual Studio), the actual build configuration (Debug or Release) is specified upon building the project. Setting the CMAKE_BUILD_TYPE
at configuration time does not have an effect.
使用Visual Studio生成器时,ExternalProject_Add
命令设置外部项目的生成过程,以便该项目使用IDE中当前选择的生成配置.用CMake术语来说,这意味着执行以下代码:
When a Visual Studio generator is used, the ExternalProject_Add
command sets up the build process of the external project so that the project uses the build configuration currently selected in the IDE. In CMake terms that means the following code is executed:
cmake --build <BINARY_DIR> --config ${CMAKE_CFG_INTDIR}
对于Visual Studio 10,在构建时将${CMAKE_CFG_INTDIR}
替换为$(Configuration)
.
For Visual Studio 10 ${CMAKE_CFG_INTDIR}
is replaced with $(Configuration)
at build time.
要始终执行发布版本,您必须使用自定义步骤替换ExternalProject_Add
默认构建步骤:
To always do a Release build, you have to replace the ExternalProject_Add
default build step with a custom one:
ExternalProject_Add(SFML
...
#--Build step-----------------
BINARY_DIR ${SFML_PREFIX}/build
BUILD_COMMAND
${CMAKE_COMMAND} --build <BINARY_DIR> --config Release
...
)
要同时构建发行版和调试版,请添加另一个cmake调用:
To build both the Release and Debug versions, add another cmake invocation:
ExternalProject_Add(SFML
...
#--Build step-----------------
BINARY_DIR ${SFML_PREFIX}/build
BUILD_COMMAND
${CMAKE_COMMAND} --build <BINARY_DIR> --config Release
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config Debug
...
)
这篇关于如何为特定配置生成Visual Studio项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!