4

Currently the README.md for vcpkg says

"First, download and bootstrap vcpkg itself; it can be installed anywhere, but generally we recommend using vcpkg as a submodule for CMake projects, and installing it globally for Visual Studio projects."

Why is the recommendation submodules for CMake? But global for Visual Studio?

jpr42
  • 718
  • 3
  • 14

1 Answers1

3

Why is the recommendation submodules for CMake?

The README is kind of out of date. The current advice for CMake uses would be to use FetchContent since it is less of a hassle compared to a git submodules.

But global for Visual Studio?

The is also kind of dated. The reason for it is that vcpkg + VS required integration with a vcpkg instance (vcpkg integrate install) but today there is also (vcpkg integrate project) which could be used. Still having per project setup is kind of a manual setup while having it globally is less manual since vcpkg is directly integrated into VS/MSBuild without having extra setup steps in VS.

Furthermore, at the time the advice was written, binary caching wasn't yet implemented so per project integration would probably have meant a rebuild for every project referencing a different vcpkg instance.

In the end it the suggestion comes down to ease of use. You don't have to do it the suggested way.

Alexander Neumann
  • 1,479
  • 8
  • 17
  • 2
    Just a note on this. @Alexander Neumann's suggestion was accurate for an entire 12 days before the vcpkg team removed the section in the readme regarding `FetchContent`. I have a personal aversion to committing large, mostly-unrelated submodules to my projects, so I experimented with trying to use `FetchContent` in conjunction with vcpkg. In the end I kept `FetchContent` and dropped vcpkg. `FetchContent` is entirely sufficient for my needs, and I would encourage CMake users considering vcpkg to investigate if `FetchContent` alone works for their use case. – Matthew Ratzloff Feb 09 '23 at 03:43
  • And the reason it was removed is: Deleting the build folder will also remove the checked out vcpkg version and thus vcpkg needs to be checked out again by `FetchContent` (which might take some time). The solution to that is simply to tell `FetchContent` to move vcpkg out of the normal build folder to somewhere else. But personally I don't think it matters which approach is used to get vcpkg. There are benefits and drawbacks for either approach. – Alexander Neumann Feb 11 '23 at 21:02