VS 打開 CMake 項目


VS 在項目目錄下會創建 CMakeSettings.json 文件:

 

參考配置文件,variables 數組用來設置 CMake 的變量,比如添加 Qt 的安裝目錄到 CMAKE_INSTALL_PREFIX 中以便運行 Qt 項目:

{

  "configurations": [
    {
      "name": "x64-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": [
        "msvc_x64_x64"
      ],
      "buildRoot": "D:\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "installRoot": "D:\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "variables": [
        {
          "name": "CMAKE_INSTALL_PREFIX",
          "value": "${env.QtDir};${CMAKE_INSTALL_PREFIX};"
        }
      ]
    },
    {
      "name": "x64-Release",
      "generator": "Ninja",
      "configurationType": "Release",
      "inheritEnvironments": [
        "msvc_x64_x64"
      ],
      "buildRoot": "D:\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "installRoot": "D:\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "variables": [
        {
          "name": "CMAKE_INSTALL_PREFIX",
          "value": "${env.QtDir};${CMAKE_INSTALL_PREFIX};"
        }
      ]
    }
  ]
}

 

配置項目運行環境:

右鍵 CMake 子項目, `Debug And Launch Setting` ,打開 launch.vs.json

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "env": "PATH=${env.QtDir}\\\\bin;D:\\OpenCV2.2\\bin;${env.Path};",
      "project": "CMakeLists.txt",
      "projectTarget": "Compass.exe",
      "name": "Compass.exe"
    }
  ]
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM