我想在 Windows 的 CMake 项目中使用
vcpkg
,因为我需要
boost
和
xerces
都由这个包管理器处理。
我有以下
CMakeLists.txt
:
cmake_minimum_required (VERSION 3.12.0)
project (myproj)
set (CMAKE_PREFIX_PATH ${XERCES_ROOT})
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
unset (Boost_INCLUDE_DIR CACHE)
unset (Boost_LIBRARY_DIRS CACHE)
# set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules)
find_package (Boost COMPONENTS filesystem regex REQUIRED)
find_package (XercesC CONFIG REQUIRED)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
message (STATUS "binary dir is ${CMAKE_BINARY_DIR}")
include_directories (${CMAKE_BINARY_DIR}/${PROJECT_NAME}/)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories (${Boost_INCLUDE_DIRS})
include_directories (${XercesC_INCLUDE_DIRS})
set (PROJECT_SRC
code.cpp
add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
add_dependencies (${PROJECT_NAME} UPDATE_RESOURCES)
target_link_libraries (${PROJECT_NAME} ${Boost_LIBRARIES} XercesC::XercesC)
Boost
和 --- 与 vcpkg
xerces-c
一起安装。由于我使用的是 Visual Studio Code,因此我正在设置 vcpkg
变量 settings.json
:
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE" : "some/path/vcpkg/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows"
当我运行 che CMake 时,我收到以下错误:
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:2132 (message):
[cmake] Unable to find the requested Boost libraries.
[cmake]
[cmake] Unable to find the Boost header files. Please set BOOST_ROOT to the root
[cmake] directory containing Boost or BOOST_INCLUDEDIR to the directory containing
[cmake] Boost's headers.
[cmake] Call Stack (most recent call first):
[cmake] D:/projects/vcpkg/scripts/buildsystems/vcpkg.cmake:233 (_find_package)
[cmake] src/myroject/CMakeLists.txt:24 (find_package)
[cmake]
[cmake]
[cmake] CMake Error at D:/Projects/vcpkg/installed/x64-windows/share/xercesc/vcpkg-cmake-wrapper.cmake:1 (_find_package):
[cmake] Could not find a package configuration file provided by "XercesC" with any
[cmake] of the following names:
[cmake]
[cmake] XercesCConfig.cmake
[cmake] xercesc-config.cmake
[cmake]
[cmake] Add the installation prefix of "XercesC" to CMAKE_PREFIX_PATH or set
[cmake] "XercesC_DIR" to a directory containing one of the above files. If
[cmake] "XercesC" provides a separate development package or SDK, be sure it has
[cmake] been installed.
[cmake] Call Stack (most recent call first):
[cmake] D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake:189 (include)
[cmake] src/ZLA/CMakeLists.txt:25 (find_package)
[cmake]
[cmake]
[cmake] Configuring incomplete, errors occurred!
[cmake] See also "D:/Projects/zla/build/vscode/CMakeFiles/CMakeOutput.log".
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.
目前我已经用vcpkg命令安装了 xerces
,虽然目前没有安装boost,但我期待在cmake命令的执行过程中, vcpkg
将下载并构建需要构建软件包。
我也试过命令行:
cmake -DCMAKE_TOOLCHAIN_FILE=D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ../
但结果是一样的。
我做错了什么?如何成功使用 vcpkg?
原文由 Jepessen 发布,翻译遵循 CC BY-SA 4.0 许可协议