我试图在Visual Studio 2017中使用CMake,但它没有找到Boost。我认为这是正常的,但之前我使用CMake GUI来指定BOOST_ROOT。我在哪里可以指定Visual Studio 2017中的位置而不编辑CMake文件本身(它们存储在源代码控制中,因此不应该编辑)?
答案 0 :(得分:3)
如果您转到CMake->更改CMake设置 - > CMakeLists.txt,则会打开CMakeSettings.json。你应该看到这样的东西:
{
"configurations": [
{
"name": "x86-Debug",
"generator": "Visual Studio 15 2017",
"configurationType": "Debug",
"buildRoot": "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "\"-m -v:minimal\"."
},
您可以通过添加变量来添加自定义:
{
"configurations": [
{
"name": "x86-Debug",
"generator": "Visual Studio 15 2017",
"configurationType": "Debug",
"buildRoot": "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "\"-m -v:minimal\".",
"variables": [
{
"name": "BOOST_ROOT",
"value": "C:\\boost_1_63_0"
}
]
},
保存此文件时,Visual Studio将自动重新运行CMake,或选择CMake-> Generate Cache。
我不想拥有每个构建变量,所以这似乎有效:
{
"variables": [
{
"name": "BOOST_ROOT",
"value": "C:\\boost_1_63_0"
}
],
"configurations": [
{
"name": "x86-Debug",
"generator": "Visual Studio 15 2017",
"configurationType": "Debug",
"buildRoot": "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "\"-m -v:minimal\"."
},
请点击此处了解更多详情: https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/#configure-cmake