如何使用Visual Studio的CMake支持运行INSTALL?

时间:2018-01-27 01:04:08

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

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

enter image description here 从顶部工具栏的CMake菜单中,我没有看到任何选择来运行INSTALL项目。

编辑:vre建议的最低设置工作,INSTALL选项显示在工具栏菜单中:

  • 的CMakeLists.txt

    error[E0308]: mismatched types
      --> src/main.rs:11:9
       |
    11 |         Some(hello) => {
       |         ^^^^^^^^^^^ expected struct `std::sync::Arc`, found enum `std::option::Option`
       |
       = note: expected type `std::sync::Arc<std::option::Option<std::string::String>>`
                  found type `std::option::Option<_>`
    
    error[E0308]: mismatched types
      --> src/main.rs:14:9
       |
    14 |         None => {}
       |         ^^^^ expected struct `std::sync::Arc`, found enum `std::option::Option`
       |
       = note: expected type `std::sync::Arc<std::option::Option<std::string::String>>`
                  found type `std::option::Option<_>`
    
  • HELLO.CPP

但是当我将# 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) 移动到子文件夹时,选项就消失了:

  • 的CMakeLists.txt

    hello.cpp
  • 的src /的CMakeLists.txt

    cmake_minimum_required(VERSION 3.9.2)
    project(test2017)
    add_subdirectory("src")
    
  • 的src / HELLO.CPP

1 个答案:

答案 0 :(得分:3)

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

解决方法是在install文件中向buildCommandArgs添加CMakeSettings.json参数。例如:

{
  "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": ""
    }
  ]
}