简体   繁体   English

带有 CMake 的 Visual Studio

[英]Visual Studio with CMake

Is there any way in visual studio to allow your projects CMakeLists.txt files to control everything and not have VS override values?在 Visual Studio 中有什么方法可以让您的项目CMakeLists.txt文件控制所有内容并且没有 VS 覆盖值?

Meaning that if I set CMAKE_INSTALL_PREFIX in my CMakeLists.txt file visual studio overrides this value.这意味着如果我在我的CMakeLists.txt文件中设置CMAKE_INSTALL_PREFIX ,visual studio 会覆盖这个值。 I know I can set CMakeSettings.json in visual studio to the location I would like it but I would like to control my entire build system in cmake and not have to maintain cmake and visual studio.我知道我可以将 Visual Studio 中的CMakeSettings.json设置为我想要的位置,但我想在 cmake 中控制我的整个构建系统,而不必维护 cmake 和 Visual Studio。

NOTE: I am using VS 17.注意:我使用的是 VS 17。

You could create a "Open Existing Cache" configuration in the CMakeSettings.json.您可以在 CMakeSettings.json 中创建“打开现有缓存”配置。 Visual Studio will only allow you to build or install, but it will not generate or alter the CMake cache in any way. Visual Studio 只允许您构建或安装,但不会以任何方式生成或更改 CMake 缓存。

This is available in Visual Studio 2019 Preview only.这仅在 Visual Studio 2019 预览版中可用。

To leverage this you feature can either:要利用此功能,您可以:

  • Use the menu item File -> Open -> CMake and select the CMakeCache.txt file of the build directory you want to work on.使用菜单项File -> Open -> CMake并选择要处理的构建目录的 CMakeCache.txt 文件。 Remember that Visual Studio will automatically open the source directory specified in the CMakeCache.txt file.请记住,Visual Studio 将自动打开 CMakeCache.txt 文件中指定的源目录。

  • Create a new "Existing Cache" configuraiton by right clicking on the JSON text editor when editing CMakeSettings.json, or by adding a new configuration on the CMake Settings UI editor.通过在编辑 CMakeSettings.json 时右键单击 JSON 文本编辑器,或通过在 CMake 设置 UI 编辑器上添加新配置来创建新的“现有缓存”配置。 There are two configuration templates:有两种配置模板:

    • Open Existing cache: use this template when you build/debug on your Windows box;打开现有缓存:在 Windows 机器上构建/调试时使用此模板;
    • Remote Open Existing cache: use this when you build/debug on a remote Unix machine;远程打开现有缓存:在远程 Unix 机器上构建/调试时使用它;

Prior to VS 2017, you would generate the visual studio solutions from the CMakeLists.txt using cmake .在 VS 2017 之前,您将使用cmakeCMakeLists.txt生成 Visual Studio 解决方案。 See Using CMake to generate Visual Studio C++ project files .请参阅使用 CMake 生成 Visual Studio C++ 项目文件

In this workflow, VS would not overwrite anything, as it was a loose coupling between CMake and VS.在这个工作流程中,VS 不会覆盖任何东西,因为它是 CMake 和 VS 之间的松散耦合。 You can still do the same with newer versions of VS and get the full benefits of both CMake and VS.您仍然可以对较新版本的 VS 执行相同操作,并获得 CMake 和 VS 的全部优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM