5

I'm modifying a project which uses CMake to include a library which is managed by vcpkg.

It looks like in order for vcpkg's packages to be found, CMAKE_TOOLCHAIN_FILE has to be defined... somewhere.

I'm confused because everything suggests that the value of CMAKE_TOOLCHAIN_FILE should contain the install location of vcpkg on the user's system, but I don't know how to reliably obtain that or get that information into the build system of the project. It certainly seems untenable to require each user to modify their copy of the project CMake files to point to their chosen install location. Requiring the developer / build system to set an env variable also seems pretty fragile and is not very well encapsulated (I'd hope that setup + build could be a single command).

I am pretty new to CMake and completely new to vcpkg. What is the idiomatic way to configure a project to use vcpkg?

4
  • "What is the idiomatic way to configure a project to use vcpkg?" - Idiomatic way is to pass CMAKE_TOOLCHAIN_FILE as a parameter to cmake: cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/toolchain/file <other arguments>. Yes, this requires a user to know a path to vcpkg installation on his/her machine. But this is just how things work.
    – Tsyvarev
    Apr 8, 2021 at 20:50
  • 1
    To use vcpkg without any manual configuration from the user, I use it as a submodule in my projects : github.com/microsoft/vcpkg#vcpkg-as-a-submodule Apr 9, 2021 at 17:08
  • Possible answer: cmake -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake May 24, 2021 at 20:55
  • See also this question: stackoverflow.com/q/52077250/5067822 May 24, 2021 at 21:28

1 Answer 1

3

Possible answer: cmake -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.