2

I having trouble integrating vcpkg package manager with CMake project on Linux. I want to use the doctest library in my project but the same problem exists with other packages too. I performed the following steps.

  1. $ vcpkg install doctest
Computing installation plan...
The following packages will be built and installed:
    doctest[core]:x64-linux -> 2.4.9
Detecting compiler hash for triplet "x64-linux"...
Restored 1 packages from /home/bobeff/.cache/vcpkg/archives in 7.67 ms. Use --debug to see more details.
Installing 1/1 doctest:x64-linux...
Elapsed time to handle doctest:x64-linux: 2.183 ms

Total elapsed time: 390 ms

doctest provides CMake targets:
    # this is heuristically generated, and may not be correct
    find_package(doctest CONFIG REQUIRED)
    target_link_libraries(main PRIVATE doctest::doctest)
  1. $ vcpkg integrate install
Applied user-wide integration for this vcpkg root.

CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=/home/bobeff/projects/cpp/vcpkg/scripts/buildsystems/vcpkg.cmake"
  1. I have a vcpkg.json file in the root directory of my project with the following content:
{
  "name": "cpp-programming-language",
  "version-string": "0.1.0",
  "dependencies": [
    "doctest"
  ]
}
$ cmake ../cpp_programming_language/ -DCMAKE_TOOLCHAIN_FILE=/home/bobeff/projects/cpp/vcpkg/scripts/buildsystems/vcpkg.cmake

The last command is giving me the following output:

CMake Error at CMakeLists.txt:7 (find_package):
  Could not find a package configuration file provided by "doctest" with any
  of the following names:

    doctestConfig.cmake
    doctest-config.cmake

  Add the installation prefix of "doctest" to CMAKE_PREFIX_PATH or set
  "doctest_DIR" to a directory containing one of the above files.  If
  "doctest" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!
See also "/home/bobeff/projects/cpp/temp/CMakeFiles/CMakeOutput.log".

When I perform the search for the not found files from the configure error message I have the following output:

$ locate doctestConfig.cmake
/home/bobeff/projects/cpp/vcpkg/buildtrees/doctest/x64-linux-dbg/generated/doctestConfig.cmake
/home/bobeff/projects/cpp/vcpkg/buildtrees/doctest/x64-linux-rel/generated/doctestConfig.cmake
/home/bobeff/projects/cpp/vcpkg/installed/x64-linux/share/doctest/doctestConfig.cmake
/home/bobeff/projects/cpp/vcpkg/packages/doctest_x64-linux/share/doctest/doctestConfig.cmake

Used versions of the programs are as follows:

  • CMake
$ cmake --version
cmake version 3.16.3
  • vcpkg
$ vcpkg --version
vcpkg package management program version 2022-06-17-9268e366206712e38102b28dbd1617697a99ff2e
  • Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:    20.04
Codename:   focal
bobeff
  • 3,543
  • 3
  • 34
  • 62
  • 1
    If you run cmake manually do you have the same problem? – Alan Birtles Jul 13 '22 at 16:48
  • @Alan Birtles Yes, I have the same problem. As a workaround, I can add the path to `doctestConfig.cmake` to the system path, but I think that it must not be required. – bobeff Jul 13 '22 at 16:52
  • 1
    In that case it might simplify your question to remove VS code from it as it seems like you have a cmake/vcpkg problem not related to VS code – Alan Birtles Jul 13 '22 at 16:56
  • 1
    @Alan Birtles I simplified it. – bobeff Jul 13 '22 at 17:08
  • When you use toolchain + manifest combo, libraries will be installed into `${CMAKE_BINARY_DIR}/vcpkg_installed` (unless changed with `VCPKG_INSTALL_DIR`). If you change toolchain for project, make sure you cleaned cmake cache. – Osyotr Jul 13 '22 at 22:00

0 Answers0