Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use find_package(cpprestsdk REQUIRED) in CMakeLists.txt #686

Open
limenghua opened this issue Feb 5, 2018 · 22 comments
Open

how to use find_package(cpprestsdk REQUIRED) in CMakeLists.txt #686

limenghua opened this issue Feb 5, 2018 · 22 comments

Comments

@limenghua
Copy link

ubuntu 16.4 LTS
install cpprestsdk use: sudo apt-get install libcpprest-dev

write "find_package(cpprestsdk REQUIRED)" to the CMakeLists.txt,there some build error:
"By not providing "Findcpprestsdk.cmake" in CMAKE_MODULE_PATH this project"

how to write the "Findcpprestsdk.cmake" file,is any example already exists on ubuntu?

@garethsb
Copy link
Contributor

garethsb commented Feb 5, 2018

It may be an issue with the naming of the C++ REST SDK CMake project vs module. Have you tried the following?

find_package(cpprestsdk REQUIRED NAMES cpprestsdk cpprest)

@elvisdukaj
Copy link

elvisdukaj commented Feb 14, 2018

try with this: find_package(cpprestsdk REQUIRED)
After you install the library you must heve this files:
cpprestsdk-targets.cmake cpprestsdk-config.cmake cpprestsdk-targets-release.cmake

@NevesLucas
Copy link

I am also having the same find package error when using the version in apt

@elvisdukaj
Copy link

I didn't tried with the package coming from apt... I built cpprestsdk and installed in my pc.

@sarunassarakojis
Copy link

I had the same problem, but as mentioned by @garethsb-sony, the suggestion did the trick for me. However, i acquired packages through vcpkg and passing -DCMAKE_TOOLCHAIN_FILE=<path to vcpkg>\vcpkg\scripts\buildsystems\vcpkg.cmake for cmake was also necessary.

@Southclaws
Copy link

I'm running into the same issue on an Ubuntu Docker image - I'm trying to set up a reproducable 32 bit build environment for Linux and this library just isn't playing well with Linux at all!

Are there also any plans to update this wiki page because it doesn't work on a blank Ubuntu image. I tried using apt get too and that didn't work either.

Here's my Dockerfile and cmake command that's executed inside the container.

@elvisdukaj
Copy link

What's the issue? I'm using cpprestsdk both on Linux machines and containers compiling for x86, x64 and arm architectures without any issue.
Can you put some logs and explain better what is going wrong?

@Southclaws
Copy link

Southclaws commented Apr 21, 2018

@elvisdukaj it just won't get past the cmake .. stage, claiming it can't find cpprestsdk, I even tried the NAMES edit suggested by @garethsb-sony and that just added more missing search queries to the error:

CMake Error at CMakeLists.txt:16 (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

I don't really know what else to do other than apt install -y libcpprest-dev do I need to manually point cmake to the cpprest installation directory? If so, where is that?

I should add that one of the requirements for my project is that it builds to 32 bit, so I have -m32 in the CMAKE_CXX_FLAGS if that makes a difference. I've been building the Windows version fine with 32 bit mode and it has been running in my host application fine.

@elvisdukaj
Copy link

elvisdukaj commented Apr 23, 2018

@Southclaws The version coming with apt-get don't install cmake files! You need to compile it by yourself...
If you need to build a 32-bit version on a 64-bit host, my suggestion is to create a 32-bit container and build from the container... Give a look here: https://www.ubuntu.com/containers/lxd

@sarunassarakojis
Copy link

It might an issue with your CMakeLists file, @Southclaws. You have to define your cmake project first with project (foo) and then call the find_package command. See the cmake lists file code example at cpprestsdk github homepage.

@Southclaws
Copy link

@elvisdukaj ah okay, I didn't know that, I'll try building from source again (I failed already, but that's probably a question for stackoverflow rather than here)

@sarunassarakojis already got a project and all the standard CMake stuff set up, my project is actually building fine on Windows already, but thanks for the reply!

@SailingDreams
Copy link

Try
find_library(cpprestsdk-lib cpprest)
message(STATUS "cpprestsdk-lib = ${cpprestsdk-lib}")
gives
-- cpprestsdk-lib = /usr/lib/x86_64-linux-gnu/libcpprest.so

@parikshitnangre22
Copy link

What's the issue? I'm using cpprestsdk both on Linux machines and containers compiling for x86, x64 and arm architectures without any issue.
Can you put some logs and explain better what is going wrong?

Hi,

Currently we are trying to install cpprest/casablanca on RHEL 6.9 but we are not successful. We also dont have root access. Could you please provide us the steps to install it with root access and also without root access ?
It is also not in source list of our RHEL version.

@dmjones
Copy link

dmjones commented Nov 20, 2018

I have the same issue. I installed libcpprest-dev on Ubuntu 18.04 and have the following in my CMakeLists.txt:

find_package(cpprestsdk REQUIRED)

I get a similar error:

CMake Error at CMakeLists.txt:19 (find_package):
  By not providing "Findcpprestsdk.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "cpprestsdk", but CMake did not find one.

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

    cpprestsdkConfig.cmake
    cpprestsdk-config.cmake

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

If I search for cpprestsdk-config.cmake, there is a hit on my system:

$ sudo updatedb
$ locate cpprestsdk-config.cmake
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-config.cmake

I'm playing around with the CMAKE variables (e.g. CMAKE_MODULE_PATH) to try and get this file found. No luck so far.

@EdgarWahn
Copy link
Contributor

You might have a look on my fork (https://github.com/EdgarWahn/cpprestsdk). I added some of the files needed to be able to import the project with find_package. Feel free to drop me a note, my target is to have the changes backported to the main project (I just touched makefiles, not code).

@dmjones
Copy link

dmjones commented Nov 21, 2018

I now understand the problem. When installing from the Ubuntu packages, the config.cmake file ends up here:

/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-config.cmake

Unfortunately, this doesn't match any of the paths that cmake will naturally search. This page describes the search order and you can see that the files are almost in the right place. Any of the following paths would have been acceptable:

/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk/cpprestsdk-config.cmake
/usr/lib/x86_64-linux-gnu/cpprestsdk/cpprestsdk-config.cmake
/usr/lib/x86_64-linux-gnu/cpprestsdk/cmake/cpprestsdk-config.cmake

I've worked around this by specifying cpprestsdk_DIR in my CMakeLists.txt file:

set(cpprestsdk_DIR /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/cmake/)

@alpparkan
Copy link

alpparkan commented Jan 28, 2019

On Ubuntu 16.04 LTS, there are no CMake config packages installed with the libcpprest-dev (2.8.0-2). You can see the files installed in the file list: https://packages.ubuntu.com/xenial/amd64/libcpprest-dev/filelist

On Ubuntu 18.04, libcpprest-dev (2.10.2-6) is installed with CMake config files. You can see those CMake files installed in file list: https://packages.ubuntu.com/bionic/amd64/libcpprest-dev/filelist

/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-config.cmake
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-targets-none.cmake
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-targets.cmake

PS: I just tried to build from source and it works for git tag v2.10.9 on Ubuntu 16.04 lts.

@pekingme
Copy link

Just come across with the same issue on Ubuntu 18.04 and cpprestsdk 2.10. As dmjones #686 (comment) mentioned, solved by wrapping the .cmake files with folder cpprestsdk, and add a new line in cpprestsdk-targets.cmake like below.

# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
# Use original install prefix when loaded through a
# cross-prefix symbolic link such as /lib -> /usr/lib.
get_filename_component(_realCurr "${_IMPORT_PREFIX}" REALPATH)
get_filename_component(_realOrig "/usr/lib/x86_64-linux-gnu/cmake" REALPATH)
if(_realCurr STREQUAL _realOrig)
  set(_IMPORT_PREFIX "/usr/lib/x86_64-linux-gnu/cmake")
endif()
unset(_realOrig)
unset(_realCurr)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)

# Backward one more layer, since wrapping it in another folder.
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)

if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()

This is an alternative way to resolve the issue. Personally think that they really should put these .cmake files in it own folder, instead of dumping them in.

@ivan2kh
Copy link

ivan2kh commented Jun 18, 2019

Workaround for Ubuntu
cmake . -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake

@mariusre
Copy link

mariusre commented Oct 30, 2019

Hey there. This one works for me (Ubuntu 18.04):

find_library(cpprest REQUIRED)
#add_executable ...
target_link_libraries(project PRIVATE cpprest)

@Naville
Copy link

Naville commented Feb 1, 2020

Seems like Ubuntu maintainers has fixed this. However it's not currently available in the stable branch
https://bugs.launchpad.net/ubuntu/+source/cpprest/+bug/1838826

@prashant-dn
Copy link

Building yourself fixes this

  22  apt-get install g++ git libboost-atomic-dev libboost-thread-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-filesystem-dev libboost-random-dev libboost-chrono-dev libboost-serialization-dev libwebsocketpp-dev openssl libssl-dev ninja-build

   23  git clone https://github.com/Microsoft/cpprestsdk.git casablanca
   24  cd casablanca
   25  mkdir build.debug
   26  cd build.debug
   27  cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Debug
   28  ninja
   29  ninja install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests