使用已安装的CMake代替Visual Studio 2017中的嵌入式CMake [英] Use installed CMake instead of embedded one in Visual Studio 2017

查看:253
本文介绍了使用已安装的CMake代替Visual Studio 2017中的嵌入式CMake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CMake项目。它使用实际安装的CMake版本(3.11.0 rc2)支持的最新版本的Boost(1.66.0),但以前版本(3.10.0)不支持。



如果我从命令行使用CMake构建它,一切正常,但是如果我在Visual Studio 2017中打开该文件夹,则会收到一条错误消息,因为Visual Studio使用的不是我的CMake安装,而是与其安装一起嵌入的安装:在输出面板中,完整的cmake命令路径为 C:\PROGRAM FILES(X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\ \CMAKE\CMake\bin\cmake.exe ,这不是我已安装的版本,它也是以前的版本(3.10.0),因此项目无法编译。 / p>

有没有办法告诉Visual Studio使用我的CMake安装而不是它的安装?

解决方案

否(下面显示的技巧除外),您只能在执行使用CMake在Linux上进行Visual C ++开发带有 CMakeSettings.json 的远程计算机,像这样:


  {
name: Linux-Debug,
generator: Unix Makefiles,
remoteMachineName: $ {defaultRemoteMachineName},
configurationType: Debug,
remoteCMakeListsRoot: / var / tmp / src / $ {workspaceHash} / $ {name},
cmakeExecutable: / usr / local / bin / cmake,
buildRoot: $ {env.LOCALAPPDATA} \\CMakeBuilds\\ $ {workspaceHash} \\build\\ $ {name},
remoteBuildRoot: / var / tmp / build / $ {workspaceHash} / build / $ {name},
remoteCopySources:true,
remoteCopySourcesOutputVerbosity:普通,
remoteCopySourcesConcurrentCopies: 10,
cmakeCommandArgs:,
buildCommandArgs:,
ctest CommandArgs:,
inheritEnvironments:[ linux-x64]
}


但是您可以更普遍地使用 cmakeExecutable 属性来支持功能请求:





一些背景信息



与@ usr1234567的答案一样,Visual Studio 2017使用-自版本15.6.1起-它是CMake的分支:





该版本随Visual Studio 2017一起提供不是官方的版本,您可以看到正在调用:

 >  C:\Program Files(x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\binmakemake --version 
cmake版本3.10.18011902-MSVC_2

所以我不确定是否正式发布了CMake可以很好地/完全地集成到Visual Studio 2017中。但是已经有将Microsoft特定更改合并回CMake主分支的请求:





编辑:可能的解决方法



A简短的测试表明,我可以通过对Visual Studio的CMake文件夹进行简单重命名并将其替换为系统安装的CMake版本的符号链接(从 cmd 具有管理权限的提示):

 > ren C:\Program Files(x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake _CMake 
...
> mklink / d C:\Program Files(x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake C:\Program Files akeCMake
...

警告:您在更新Visual Studio 2017之前必须先撤消此操作。否则VS2017 udpate进程将替换/覆盖原始的CMake安装。


I've a CMake project. It uses the last version of Boost (1.66.0) that are supported in actual installed CMake version (3.11.0 rc2) but not in previous one (3.10.0).

If I build it with CMake from command line, everything is ok, but if I open the folder in Visual Studio 2017, I obtain an error because Visual Studio uses a CMake installation that's not mine, but is the one embededed with its installation: in the output panel the full cmake command path is C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe, that's not the version that I've installed and it is also the previous version (3.10.0) so project it does not compile.

Is there a way to tell to Visual Studio to use my CMake installation instead of its one?

解决方案

No (with the exception of the trick shown below), you can only use your own CMake version when doing Visual C++ for Linux Development with CMake on a remote machine with a CMakeSettings.json like this:

{
      "name": "Linux-Debug",
      "generator": "Unix Makefiles",
      "remoteMachineName": "${defaultRemoteMachineName}",
      "configurationType": "Debug",
      "remoteCMakeListsRoot": "/var/tmp/src/${workspaceHash}/${name}",
      "cmakeExecutable": "/usr/local/bin/cmake",
      "buildRoot": "${env.LOCALAPPDATA}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "remoteBuildRoot": "/var/tmp/build/${workspaceHash}/build/${name}",
      "remoteCopySources": true,
      "remoteCopySourcesOutputVerbosity": "Normal",
      "remoteCopySourcesConcurrentCopies": "10",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "linux-x64" ]
}

But you can give support to a feature request utilizing the cmakeExecutable property more generally:

Some Background Information

As with @usr1234567's answer Visual Studio 2017 uses - as of Version 15.6.1 - it's own branch of CMake:

That the version shipped with Visual Studio 2017 is not an official build you can see be calling:

> "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake" --version
cmake version 3.10.18011902-MSVC_2

So I'm not sure if a official CMake release would nicely/fully integrate into Visual Studio 2017. But there is already a request to merge the Microsoft specific changes back to CMake's main branch:

EDIT: Possible Workaround

A short test has shown that I could trick Visual Studio into taking your installed version by doing a simple renaming of Visual Studio's CMake folder and replacing it a symbolic link to your systems installed CMake version (from a cmd prompt with a administrative rights):

> ren "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake" _CMake
...
> mklink /d "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake" "C:\Program Files\CMake"
...

Warning: You have to undo this with before you update Visual Studio 2017. Otherwise the VS2017 udpate process will replace/overwrite your original CMake installation.

这篇关于使用已安装的CMake代替Visual Studio 2017中的嵌入式CMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆