2

I am porting a Windows project to CentOS Linux that uses cpprestsdk. I use vcpkg on Windows and I thought I would use vcpkg (and cmake) to bring in and build the packages and 'expose' the libs and header files to my project. The sequence fails in trying to get package header file 'known' to my source. This is what I did.

$ 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>

By adding the vcpkg toolchain file parameter to cmake, I thought it was supposed to take care of exposing all of the package paths (lib/header) and write them to the output Makefile?

I tried adding

find_package(cpprestsdk REQUIRED)

Then I got bunch of new errors:

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 does exist under the vcpkg root directory and I can definitely see the offending header file for the package under the vcpkg root directory, but why does the cmake-generated Makefile not have everything it needs to build? Does each and every package under vcpkg have to be manually included in some way in the CMakeLists.txt file?

pathrider
  • 844
  • 2
  • 12
  • 27
  • `vcpkg` doesn't *automatically* add include directories to the compiler and doesn't automatically link libraries for every executable you create. Instead, it adds to the CMake environment the directories, where configuration files or find scripts can be found by `find_package()`. That is, `find_package(cpprestsdk REQUIRED)` is needed to work with `cpprestsdk`. "All these files do exist under the vcpkg root directory" - Probably, you mean that **only** `cpprestsdk-config.cmake` file exists. Other names are alternative names for the CMake configuration file which follows CMake conventions. – Tsyvarev Apr 29 '19 at 07:52
  • I thought that was the point of the 'vcpkg integrate install' - to generate the toolchain file for cmake? In any case 'cpprestsdk-config.cmake' exists, but cannot be found, why is that? Lots of good information, but no suggestion on a solution... – pathrider Apr 29 '19 at 13:53
  • Hm, I meant the purpose of toolchain file, provided by vcpkg, is to adjust CMake variables (and environment ones), so `find_package()` should work. I don't know why it doesn't work in your case, and agree, that this is looks strange. – Tsyvarev Apr 29 '19 at 14:12

2 Answers2

1

I found the problem. Cpprestsdk does not register/expose any cmake find_package() config module. If it did that, this wouldn't be an issue - the generated toolchain file would set everything cmake needs in order to generate the paths to include in the MakeFile.

I added the following line to the CMakeList.txt file and cmake was then able to find the config file:

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

Which is really, really bad, IMHO, to have to hard code a path to find cpprestsdk. I still have the header file path problem, so there's actually much more going wrong/missing. I'll update this post once I get word from the vcpkg/cmake teams.

pathrider
  • 844
  • 2
  • 12
  • 27
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}
  )

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

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

One thing puzzle me (not a vcpkg expert yet) https://github.com/Microsoft/vcpkg/blob/master/ports/cpprestsdk/portfile.cmake#L45

vcpkg_fixup_cmake_targets(CONFIG_PATH lib/share/cpprestsdk)

while it should be lib/cpprestsdk IMHO (ed: not checked SHA1 version)

@cardinalPilot did you try to locate the config file on your system ? can you also try to print the CMAKE_PREFIX_PATH etc to see if vcpkg do correctly its stuff...

Mizux
  • 8,222
  • 7
  • 32
  • 48