Skip to content

vcpkg notes

Mradul Dubey edited this page Aug 31, 2023 · 16 revisions

VCPKG Basics

The About vcpkg and its sub sections in reference-1 provide a good introduction to understand vcpkg port structure, versions, and triplets.

Upgrade vcpkg port to use thirdparty library. [The library exists in vcpkg package directory]

  1. Open vcpkg/ports/<package_name>/
    • . update the vcpkg_from_github() function in portfile.cmake file
      1. Update the REPO Name with the target repo (ex: Apra-Labs/openh264)
      2. Update REF to the required commit to extract the source code .
      3. calcaulate sha512 value for the above commit.
      4. changes the HEAD_REF to the target branch name of given repo.
    • . Update the version-date and port version in vcpkg/ports/<package_name>/vcpkg.json file.
  2. Update the baseline and port version in vcpkg/version/baseline.json file .
  3. commit the following vcpkg code.(Needs to be done)
  4. Now generate git-tree hash using the command: git rev-parse HEAD:ports/<package_name>
  5. Update git-tree with above generated hash, version-date and port-version in vcpkg/versions//package_name.json file
  6. commit and push the code the vcpkg code
  7. Update Aprapipes/base/vcpkg.json file: Change the builtin-baseline with the latest commit ID of vcpkg, also change the vcpkg submodule point to the latest commit.
  8. Also delete buildtrees, downloads, packages and installed folders in ApraPipes/vcpkg/ .
  9. If Above point 8 does not work try to delete archives in C:\Users\developer\AppData\Local\vcpkg\

Upgrade vcpkg port to use novel thirdparty library. [The library does not exist in vcpkg package directory]

  1. If the novel library is not a package in vcpkg directory then follow these steps. You need to write the portfile and json file.
  2. Lookup the general format of portfile in the reference given and write one for the library.Add a vcpkg.json file.
  3. Fork the novel library repository in ApraLabs and create a branch (forApraPipes) and point the portfile to it. This is to keep main in sync with original repo and also facilitates dependency issues.
  4. Then follow the same steps as for a library in vcpkg directory. (above section)

Dependency Notes

  1. If the library you're adding has dependency on a different library i.e depender. If the dependee library is not already a vcpkg port then it must be added by following the above steps.
  2. Once both the libraries are added its possible some errors may come up while building the second library eg - dependee library not found.
  3. If the library is built using cmake check the cmakelist to see which line tries to find the dependee library eg - find_package().
  4. In vcpkg, find_package() mostly won't be able to find the library using default paths since the installed library and headers are moved to build/vcpkg_installed folder from vcpkg/vcpkg_installed in vcpkg. If this is the case then you may have to point the right path.
  5. Sidenote - If the depender is dependent on many libraries and requires many changes in cmakelist but you dont want to change the cmakelist then a better way is to use a vcpkg-cmake-wrapper which replaces the find_package() functionality and helps it find the library.
  6. You can also add the path to library and header files in the cmakelist with relative path (use vcpkg_installed_dir to find them) and have the modified cmakelist in forAprapipes branch in the fork. This will prevent adding hardcoded paths to library files.
  7. Do not try to point the path to anywhere in vcpkg directory in aprapipes.

References :

  1. https://decovar.dev/blog/2022/10/30/cpp-dependencies-with-vcpkg
  2. https://devblogs.microsoft.com/cppblog/registries-bring-your-own-libraries-to-vcpkg/