3

I'm working on c++ project on a linux machine and it uses several boost libraries. I've installed them on my system using vcpkg and build it using the toolchain provided by 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. How do I do the same with 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?

aks
  • 51
  • 1
  • 4
  • AFAIK there is no "built in" way to do this via CMake. autovcpkg seems like a good fit though. It does what you would have to do manually via cmake for you. – Developer Paul Apr 03 '20 at 18:03
  • Thank you for letting me know. Does a PR or an issue in [vcpkg](https://github.com/microsoft/vcpkg) exists for the following feature? – aks Apr 03 '20 at 19:58
  • do you mean to auto build dependencies? No, I think that is beyond the scope of what vcpkg is trying to do. The best you can do currently (if you're on windows) is use the vcpkg integrate command to make the libraries available globally on your system, but I feel that breaks the idea of using cmake since it's meant to be cross platform. – Developer Paul Apr 03 '20 at 22:27
  • I wanted something similar to what Conan does in [conanfile.txt](https://docs.conan.io/en/latest/reference/conanfile_txt.html) does. – aks Apr 04 '20 at 04:26

2 Answers2

2

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?

You can write a vcpkg port for your library or executable by providing a CONTROL and portfile.cmake file. In the CONTROL file you define all the dependencies and possible features while the portfile contains the build instruction. 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. Together with a port-overlay this port can also be used by others without being merged into vcpkg/master

Alexander Neumann
  • 1,479
  • 8
  • 17
2

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.

  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. It also means that you can fix the package versions
  2. Using a manifest file is how you programmatically tell vcpkg which packages to get and build during a CMake configuration phase
  3. Using a CMake toolchain file is the only way to tie this into your project's build system
$ 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
...
cmannett85
  • 21,725
  • 8
  • 76
  • 119