cmakepackagevcpkg

Didnt find <package>.cmake with vcpkg


Could not find a package configuration file provided by "Xlnt" with any of
the following names:

    XlntConfig.cmake
    xlnt-config.cmake

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

CMakeLists.txt

cmake_minimum_required(VERSION 3.25.2)
SET(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(untitled)
set(CMAKE_CXX_STANDARD 17)
add_executable(untitled main.cpp)
find_package(Xlnt CONFIG REQUIRED)
find_package(duckx CONFIG REQUIRED)
target_link_libraries(untitled PRIVATE xlnt::xlnt)
target_link_libraries(untitled PRIVATE duckx::duckx)

vcpkg.json

{
"name" : "untitled",
"dependencies" : [ {
"name" : "duckx",
"version>=" : "1.2.2#1"
}, {
"name" : "xlnt",
"version>=" : "1.5.0#4"
} ]
}

IDE: Clion, with using vcpkg.

P.S. Beginner

Try to use another (from clion, may they config is better than my) vcpkg. try to add

include_directories("C:\\vcpkg\\packages\\xlnt_x64-windows")
link_directories("C:\\vcpkg\\packages\\xlnt_x64-windows")

Nothing change. when im add

include("C:/vcpkg/scripts/buildsystems/vcpkg.cmake")

I take:

"C:\Program Files\JetBrains\CLion 2023.1.5\bin\cmake\win\x64\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2023.1.5/bin/ninja/win/x64/ninja.exe" -G Ninja -S C:\Users\Kosmo\CLionProjects\untitled -B C:\Users\Kosmo\CLionProjects\untitled\cmake-build-debug -- Running vcpkg install error: C:\Users\Kosmo\CLionProjects\untitled\vcpkg.json was rejected because it uses "version>=" and does not have a "builtin-baseline". This can be fixed by removing the uses of "version>=" or adding a "builtin-baseline". See 'vcpkg help versioning for more information. -- Running vcpkg install - failed CMake Error at C:/vcpkg/scripts/buildsystems/vcpkg.cmake:899 (message):   vcpkg install failed.  See logs for more information:   C:\Users\Kosmo\CLionProjects\untitled\cmake-build-debug\vcpkg-manifest-install.log Call Stack (most recent call first):   C:/Program Files/JetBrains/CLion 2023.1.5/bin/cmake/win/x64/share/cmake-3.25/Modules/CMakeDetermineSystem.cmake:124 (include)   CMakeLists.txt:3 (project) CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage -- Configuring incomplete, errors occurred! [Failed to reload]

and that problem didn't resolved. Removed include, deleted build directory.


Solution

  • I do not really know vcpkg well so not sure if I can help. As you might see in the error message, for each package you are looking for, cmake searches a file named <PackageName>Config.cmake or <PackageName>-config.cmake. In your case it cannot find them. That might be because cmake searches at the wrong locations.

    Since you use the config mode, cmake searches for them in some directories located in the path which is stored in the CMAKE_PREFIX_PATH variable. A more detailed description can be found here: https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure

    However, you do not want to move those files there by hand. I checked the vcpkg documentation and it states, that you should create a CMakePresets.json file inside your project directory:

    {
      "version": 3,
      "configurePresets": [
        {
          "name": "default",
          "binaryDir": "${sourceDir}/build",
          "cacheVariables": {
            "CMAKE_TOOLCHAIN_FILE": "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
          }
        }
      ]
    }
    

    With the help of this file, vcpkg will generate a CMakeToolchain.cmake file, which enables the possibility to find the packages.

    Source: https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?pivots=shell-c