【问题标题】:How to run INSTALL with Visual Studio's CMake support?如何使用 Visual Studio 的 CMake 支持运行 INSTALL?
【发布时间】:2018-01-27 01:04:08
【问题描述】:

使用 CMake support in Visual Studio,我如何运行 INSTALL 构建?

在顶部工具栏中的 CMake 菜单中,我没有看到任何运行 INSTALL 项目的选项。

编辑:vre 建议的最低设置有效,安装选项出现在工具栏菜单中:

  • CMakeLists.txt

    # 3.9.2 is the current version the newest VS is using
    cmake_minimum_required(VERSION 3.9.2)
    project(test2017)
    add_executable(hello hello.cpp)
    install(TARGETS hello DESTINATION hello/bin)
    
  • hello.cpp

但是当我将hello.cpp 移动到子文件夹时,该选项消失了:

  • CMakeLists.txt

    cmake_minimum_required(VERSION 3.9.2)
    project(test2017)
    add_subdirectory("src")
    
  • src/CMakeLists.txt

    add_executable(hello hello.cpp)
    install(TARGETS hello DESTINATION "hello/bin")
    
  • src/hello.cpp

【问题讨论】:

  • 可以添加CMakeSettings.json和CMakeLists.txt的内容吗?我尝试使用带有以下 CMakeLists.txt cmake_minimum_required(VERSION 2.8.12) project(test2017) add_executable(hello hello.cpp) install(TARGETS hello DESTINATION hello/bin) 的 VS2017 15.5.5,安装选项显示在工具栏菜单和 CMakeLists.txt 的上下文菜单中。
  • 也许 VS2017 15.2 中的这个 bug (developercommunity.visualstudio.com/content/problem/46744/…) 对你有影响?
  • @vre 我按照您的建议添加了一个 CMakeLists 示例。当我将 cpp 文件移动到另一个文件夹时,安装选项消失了。

标签: visual-studio cmake visual-studio-2017


【解决方案1】:

使用子文件夹时似乎有一个bug,但在当前的 VS 15.5.5 中仍未修复。

一种解决方法是在CMakeSettings.json 文件中将install 参数添加到buildCommandArgs。示例:

{
  "configurations": [
    {
      "name": "x86-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": [ "msvc_x86" ],
      "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v install",
      "ctestCommandArgs": ""
    }
  ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多