简体   繁体   English

Cmake 问题:如何使用 vcpkg 自动安装依赖项?

[英]Cmake question: How do I use vcpkg to install dependencies automatically?

I'm working on c++ project on a linux machine and it uses several boost libraries.我正在 linux 机器上研究 c++ 项目,它使用了几个 boost 库。 I've installed them on my system using vcpkg and build it using the toolchain provided by vcpkg.我已经使用 vcpkg 将它们安装在我的系统上,并使用 vcpkg 提供的工具链构建它。 My question is: How do I define the dependencies so that they automatically install on a different system, if they were to build it?我的问题是:如果要构建依赖项,我如何定义依赖项以便它们自动安装在不同的系统上? Conan has a way of doing it by defining the dependencies in conanfile.txt.柯南有办法通过在 conanfile.txt 中定义依赖关系来做到这一点。 How do I do the same with vcpkg?我如何对 vcpkg 做同样的事情?

Edit1: I've found autovcpkg which does the job I'm looking to do but can the same be done natively inside cmakelists.txt or by vcpkg itself? Edit1:我发现autovcpkg可以完成我想要做的工作,但同样可以在 cmakelists.txt 中本地完成还是由 vcpkg 本身完成?

I've found autovcpkg which does the job I'm looking to do but can the same be done natively inside cmakelists.txt or by vcpkg itself?我发现 autovcpkg 可以完成我想要做的工作,但同样可以在 cmakelists.txt 中本地完成还是由 vcpkg 本身完成?

You can write a vcpkg port for your library or executable by providing a CONTROL and portfile.cmake file.您可以通过提供CONTROLportfile.cmake文件来为您的库或可执行文件编写 vcpkg 端口。 In the CONTROL file you define all the dependencies and possible features while the portfile contains the build instruction.在 CONTROL 文件中定义所有依赖项和可能的功能,而 portfile 包含构建指令。 You can use vcpkg create <myport> <url> <filename> to create the CONTROL and portfile.cmake from a template which can be customized to your needs.您可以使用vcpkg create <myport> <url> <filename>从可根据您的需要自定义的模板创建CONTROLportfile.cmake Together with a port-overlay this port can also be used by others without being merged into vcpkg/master与端口叠加一起,此端口也可以被其他人使用,而无需合并到 vcpkg/master

If you have vcpkg as a submodule for your project, define a manifest for the libraries you want vcpkg to build, and are using the vcpkg CMake toolchain - then you will get everything you want.如果您将 vcpkg 作为项目的子模块,请为您希望 vcpkg 构建的库定义清单,并使用 vcpkg CMake 工具链 - 那么您将获得所需的一切。

  1. Adding vcpkg as a submodule means that your users don't need to install it themselves, the CMake toolchain will install it on your behalf.将 vcpkg 添加为子模块意味着您的用户不需要自己安装它,CMake 工具链将代表您安装它。 It also means that you can fix the package versions这也意味着您可以修复 package 版本
  2. Using a manifest file is how you programmatically tell vcpkg which packages to get and build during a CMake configuration phase使用清单文件是您在 CMake 配置阶段以编程方式告诉 vcpkg 要获取和构建哪些包的方式
  3. Using a CMake toolchain file is the only way to tie this into your project's build system使用 CMake 工具链文件是将其绑定到项目构建系统的唯一方法
$ git clone .../my_project
$ cd ./my_project
$ git submodule update --init
$ mkdir ../build
$ cd ../build
$ cmake ../my_project
-- Running vcpkg install
-- Running vcpkg install - done
...

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

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