使用vcpkg,cmake的cpprestsdk-找不到包含文件

时间:2019-04-29 02:30:24

标签: c++ cmake cpprest-sdk vcpkg

我正在将Windows项目移植到使用cpprestsdk的CentOS Linux。我在Windows上使用vcpkg,我以为我会使用vcpkg(和cmake)引入并构建软件包并将库和标头文件“暴露”到我的项目中。该序列未能尝试使包头文件对我的源“已知”。这就是我所做的。

$ vcpkg install boost cpprestsdk
$ vcpkg integrate install
Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake"

$ cd <source>
$ vi CMakeLists.txt
cmake_minimum_required(VERSION 2.8.9)
project(Domain)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -I../ ")
file(GLOB SOURCES "*.cpp")

#Generate the shared library from the sources
add_library(Domain SHARED ${SOURCES})

install(TARGETS Domain DESTINATION ../lib)

$ cmake -DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake -G "Unix Makefiles" .
$ make
[  7%] Building CXX object CMakeFiles/Domain.dir/BaseDataFactory.cpp.o
In file included from /src/Domain/stdafx.h:4:0,
             from /src/Domain/BaseDataFactory.cpp:1:
../Common/Common.h:75:26: fatal error: cpprest/json.h: No such file or directory
#include <cpprest/json.h>

通过将vcpkg工具链文件参数添加到cmake,我认为它应该负责公开所有包路径(lib / header)并将它们写入输出Makefile?

我尝试添加

find_package(cpprestsdk REQUIRED)

然后我收到了很多新错误:

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

cpprestsdkConfig.cmake
cpprestsdk-config.cmake
cpprestConfig.cmake
cpprest-config.cmake

cpprestsdk-config.cmake确实存在于vcpkg根目录下,我肯定可以在vcpkg根目录下看到该软件包的有问题的头文件,但是为什么cmake生成的Makefile没有构建所需的所有内容?是否必须以某种方式手动将vcpkg下的每个软件包都包含在CMakeLists.txt文件中?

2 个答案:

答案 0 :(得分:1)

我发现了问题。 Cpprestsdk不会注册/公开任何cmake find_package()配置模块。如果这样做的话,这将不是问题-生成的工具链文件将设置cmake所需的一切,以便生成要包含在MakeFile中的路径。

我将以下行添加到CMakeList.txt文件中,然后cmake能够找到配置文件:

set(cpprestsdk_DIR“ / vcpkg / installed / x64-linux / share / cpprestsdk”)

恕我直言,这真的非常糟糕,必须硬编码找到cpprestsdk的路径。我仍然有头文件路径问题,所以实际上还有更多的错误/遗漏。一旦收到vcpkg / cmake团队的支持,我将更新此帖子。

答案 1 :(得分:0)

https://github.com/Microsoft/cpprestsdk/blob/ea4eff7cd1d6110833df869f7591f266816f8328/Release/src/CMakeLists.txt#L282-L285

install(
    FILES "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config.cmake"
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CPPREST_EXPORT_DIR}
  )

https://github.com/Microsoft/cpprestsdk/blob/9d8f544001cb74544de6dc8c565592f7e2626d6e/Release/CMakeLists.txt#L22

set(CPPREST_EXPORT_DIR cpprestsdk CACHE STRING "Directory to install CMake config files.")

一件事困扰着我(还不是vcpkg专家) https://github.com/Microsoft/vcpkg/blob/master/ports/cpprestsdk/portfile.cmake#L45

vcpkg_fixup_cmake_targets(CONFIG_PATH lib/share/cpprestsdk)

应为lib/cpprestsdk恕我直言(未编辑SHA1版本)

@cardinalPilot您是否尝试在系统上找到配置文件? 您还可以尝试打印CMAKE_PREFIX_PATH等以查看vcpkg是否正确执行其工作...