【问题标题】:How to build all configurations with CMake + msbuild如何使用 CMake + msbuild 构建所有配置
【发布时间】:2017-09-05 09:35:56
【问题描述】:

我有一个生成 VS2015 解决方案文件 MyApp.sln 的 CMake 文件。我为每个配置分别使用以下命令构建 MyApp.sln:

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

我想知道是否有人知道如何使用单个 msbuild 命令构建所有配置。例如,CMake 可能会生成一些“全部”配置?

我的问题与How can I build all with MSBuild from the command line? 有点不同,因为我没有手动修改 MyApp.sln 文件,但它是由 CMake 生成的,所以我需要 CMake 中的一些选项来创建“全部”目标或调用 msbuild一种构建所有配置的方式。

【问题讨论】:

  • 可能我的问题有点不同,因为我使用的是 CMake
  • CMake 用于生成解决方案,但您使用 msbuild 构建它。
  • 您是否已经尝试过msbuild MyApp.sln /t:ALL_BUILD /Configuration:"Debug;Release;RelWithDebInfo"
  • 使用命令 msbuild LinesGameQt.sln /t:ALL_BUILD /p:Configuration="Debug;Release;RelWithDebInfo" 我得到 'error MSB4126: The specified solution configuration "Debug;Release;RelW ithDebInfo|Win32 “ 是无效的。请使用配置和平台属性指定有效的解决方案配置(例如 MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU")'

标签: cmake msbuild


【解决方案1】:

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

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
)

你明白了...注意CMake can build its own projects,所以根本不需要求助于MSBuild。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 2011-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多