Search code examples
c++gitcmakevcpkg

How to install packages when cloning project that uses vcpkg


I am trying out vcpkg package manager but I am running in some issues. I have a c++ project that uses cmake and vcpkg and have used vcpkg to install the cache2 package. Now everything works but as soon as I push the project and clone it I can't find how to restore the installed packages.

What I have done is this:

  • installed vcpkg as submodule
  • installed cache2 with vcpkg
  • added cache2 to cmake

Till here everything works fine now when I push and clone the project it goes wrong.

  • git clone --recurse-submodules
  • .\extern\vcpkg\bootstrap-vcpkg.bat
  • vcpkg list

Now nothing appears to be installed and I don't want everyone to install all the packages one by one when they clone. Is there someway to automatically install all packages when cloning?


Solution

  • I have found a decent solution using vcpkg manifests, it is still an experimental feature but I haven't had any issues with it yet. In order to use manifests do the following:

    • At your root folder add a vcpkg.json file with the following contents:
    {
      "name": "projectname", // should be lowercase, uppercase will give an error
      "version-string": "0.1.0",
      "dependencies": [ // add here your dependencies you would normally install with vcpkg install [package name]
        "catch2"
      ]
    }
    
    • run: vcpkg install --feature-flags=manifests, this will install all dependencies in the array.

    In order to remove packages just remove the dependencies from the list and run the above command.