1

I've installed Drogon using vcpkg, and in my IDE I have following error: Package 'Drogon' not found. After installing, regenerate the CMake cache.

I am using Visual Studio 2022

vcpkg_rf.txt:

install
drogon

CMakeLists.txt:

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)

project ("Drogon Server1")

# Include sub-projects.
add_subdirectory ("Drogon Server1")

# Line below is showing the error
find_package(Drogon CONFIG REQUIRED)
target_link_libraries("Drogon Server1" PRIVATE Drogon::Drogon)

I have found this error also:

CMake Error at C:/Users/MY_USERNAME/Documents/sdk/vcpkg/scripts/buildsystems/vcpkg.cmake:829 (_find_package):
  Could not find a package configuration file provided by "Drogon" with any
  of the following names:

    DrogonConfig.cmake
    drogon-config.cmake

  Add the installation prefix of "Drogon" to CMAKE_PREFIX_PATH or set
  "Drogon_DIR" to a directory containing one of the above files.  If "Drogon"
  provides a separate development package or SDK, be sure it has been
  installed.
Penny M.
  • 147
  • 10
  • Did you use the vcpkg toolchain file when you configured your package on the command line? Or are you using a CMakeSettings.json file configured with the toolchain: [https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/](https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/) – drescherjm Aug 26 '22 at 13:01
  • I have configured vcpkg toolchain in CMakePresets.json. – Penny M. Aug 26 '22 at 13:04
  • like this: `"CMAKE_TOOLCHAIN_FILE": "C:/Users/MY_USERNAME/Documents/sdk/vcpkg/scripts/buildsystems/vcpkg.cmake"` – Penny M. Aug 26 '22 at 13:07
  • 1
    I do have a complaint `project ("Drogon Server1")` and `add_subdirectory ("Drogon Server1")` you should avoid spaces in both of these. – drescherjm Aug 26 '22 at 13:22
  • Is there more info in the error message? I use vcpkg + Visual Studio + CMake but don't use the integration in the IDE. I use the standalone CMake-GUI to configure and generate my VS project. In CMake-GUI it should give you a longer error message when it cant find a package. It should mention that there are 2 files that it searched for but did not find and give the file names. If you see that check if either of these exist. – drescherjm Aug 26 '22 at 13:29
  • 1
    Assuming you create the target `"Drogon Server1"` in your `add_subdirectory` CMakeLists.txt you need to properly enclose it in quotes in your `target_link_libraries` command. Try to avoid spaces in target names! – vre Aug 26 '22 at 13:35
  • @vre I added quotes around it and it still gives me this error. (I have done this: `target_link_libraries("Drogon Server1" PRIVATE Drogon::Drogon)`) – Penny M. Aug 26 '22 at 13:38
  • @drescherjm I have added error it gives me at the end of question – Penny M. Aug 26 '22 at 13:41
  • Does your directory `C:/Users/MY_USERNAME/Documents/sdk/vcpkg` contains any Drogon files? `dir /r /s Drogon*` should show the files. – vre Aug 26 '22 at 13:44
  • @vre Yes it does, it is saying: `Total files listed: 57 File(s)` – Penny M. Aug 26 '22 at 13:49
  • And are those `.cmake` files in question amongst them? How are they named? – vre Aug 26 '22 at 13:56
  • @vre I can see some: `DrogonUtilities.cmake`, `DrogonConfig.cmake.in`, `DrogonConfigVersion.cmake`, `DrogonConfig.cmake`, `DrogonTargets.cmake`, `DrogonTargets-debug.cmake`, `DrogonTargets.cmake`, `DrogonTargets-release.cmake`, ... – Penny M. Aug 26 '22 at 13:59
  • Did you cleared the CMake cache as suggested, i.e. deleted CMakeCache.txt and CMakeFiles in the build directory or started in a fresh build directory after installation of drogon? – vre Aug 26 '22 at 14:06
  • @vre I did, I have deleted whole build directory, I have even created another CMake project without spaces in the name, and it is still showing this error – Penny M. Aug 26 '22 at 14:11
  • 1
    There should be an entry in your CMakePresets.json file named `cacheVariables`. Please add a variable `Drogon_DIR` to it with the path to the `DrogonConfig.cmake` file, e.g. `"cacheVariables": { "Drogon_DIR": "" },` and retry in a new builddir – vre Aug 26 '22 at 14:18

1 Answers1

1

Considering the given information:

Visual Studio 2022

-> Means CMake will default to x64 -> vcpkg will use VCPKG_TARGET_TRIPLET=x64-windows

vcpkg_rf.txt: install drogon

-> Means you use a response file to install drogon. Without specifying the triplet this is x86-windows

As such your triplet used by CMake and vcpkg doesn't agree. Consider using vcpkg in manifest mode by providing a vcpkg.json with the dependency instead of a response file. This way you won't have a discrepancy in your triplet selection

(As always chanigng this also requires to delete the cmake cache for a clean reconfigure. Furthermore don't have spaces in your target and paths; you are just asking for trouble.)

Alexander Neumann
  • 1,479
  • 8
  • 17