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