如何使用CMake + msbuild构建所有配置 [英] How to build all configurations with CMake + msbuild

查看:623
本文介绍了如何使用CMake + msbuild构建所有配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CMake文件,该文件生成VS2015解决方案文件MyApp.sln.对于每种配置,我分别使用以下命令构建MyApp.sln:

I have a CMake file that generates VS2015 solution file MyApp.sln. I build MyApp.sln with the following commands separately for each configuration:

msbuild MyApp.sln /property:Configuration=Debug
msbuild MyApp.sln /property:Configuration=RelWithDebInfo
msbuild MyApp.sln /property:Configuration=Release

我想知道是否有人知道如何使用单个msbuild命令来构建所有配置.例如,也许CMake可以生成一些全部"配置?

I wonder if anyone knows how to build all the configurations with a single msbuild command. Probably CMake can generate some 'All' configuration, for example?

我的问题与 ,因为我没有手动修改MyApp.sln文件,但是它是由CMake生成的,因此如何在命令行中使用MSBuild来构建所有文件,因此我需要CMake中的某个选项来创建全部"目标或以建立所有配置的方式调用msbuild.

My question is a bit different from How can I build all with MSBuild from the command line?, because I do not modify MyApp.sln file manually, but it is generated by CMake, so I need either some option in CMake to create 'all' target or call msbuild in a way it builds all the configurations.

推荐答案

这有点愚蠢,但是您可以向CMake添加自定义目标,从而导致项目自身构建:

This is a bit silly, but you can add a custom target to CMake that causes the project build itself:

add_custom_target(build_all_configs
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ALL_BUILD --config Debug
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ALL_BUILD --config Release
)

您有个主意...请注意,

You get the idea... Note that CMake can build its own projects, so there is no need to resort to MSBuild at all.

虽然这很好,但我宁愿 configure_file 批处理脚本,该脚本对满足您需要的位置执行相同的操作.与上面的自定义命令相比,这肯定会引起更少的注意.

While this works fine, I would rather configure_file a batch script that does the same thing to a location that works for your needs. That will definitely raise fewer eyebrows than the custom command above.

这篇关于如何使用CMake + msbuild构建所有配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆