Search code examples
cmakevcpkg

Why is vcpkg recommended as a git submodule?


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?


Solution

  • 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.