libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.48k stars 921 forks source link

CMake fails to detect libcurl protocol HTTP #824

Open gholmann16 opened 2 years ago

gholmann16 commented 2 years ago

Description

When trying to compile cpr on Ubuntu 14.04 I run into the error that your CMake file cannot properly detect the supported protocols of libcurl. I know for sure that libcurl supports http due to a quick curl-config:

~/gpgme-1.18.0$  curl-config --protocols
DICT
FILE
FTP
FTPS
GOPHER
HTTP
HTTPS
IMAP
IMAPS
LDAP
LDAPS
POP3
POP3S
RTMP
RTSP
SMTP
SMTPS
TELNET
TFTP

But the cmake fails to detect it ending with this error:

-- Detecting SSL backend...
-- SSL auto detect: Using OpenSSL.
-- Could NOT find CURL (missing: HTTP HTTPS) (found version "7.35.0")
-- Could NOT find CURL (missing: HTTP) (found version "7.35.0")
CMake Error at lib/zsync2/lib/cpr/CMakeLists.txt:172 (message):
Curl not found on this system. To use the build in version set
CPR_FORCE_USE_SYSTEM_CURL to OFF.

When I asked the same question over on this thread: https://github.com/AppImage/AppImageUpdate/issues/210 , I was recomended to manually edit my /usr/lib/x86_64-linux-gnu/pkgconfig/libcurl.pc file and to make sure HTTP was supported as so:

supported_protocols="DICT FILE FTP FTPS GOPHER GOPHERS HTTP HTTPS IMAP IMAPS LDAP LDAPS MQTT POP3 POP3S RTMP RTSP SCP SFTP SMB SMBS SMTP SMTPS TELNET TFTP"

But even upon doing so I still got the same error.

Expected Behavior

Seeing as I have the latest cmake and all necessary libraries as far as I know, it should be compiling normally, and yet it does not.

Actual Behavior

Fails to compile, gives error I pasted above.

Possible Fix

Wave check in CMake? This is a horrible fix but it might be necessary.

Steps to Reproduce

  1. Launch a new Ubuntu 14.04 VM
  2. Install g++ 9 (for C++ 17 support) using these commands:
    sudo apt update
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 --slave /usr/bin/g++ g++ /usr/bin/g++-9
  3. Install git
  4. Install cmake from this github project for newest version: https://github.com/Kitware/CMake
  5. export CXX=g++
  6. Install and attempt to build this repo with system ssl
    git clone https://github.com/libcpr/cpr
    cd cpr
    mkdir build
    cd build 
    cmake .. -DCPR_USE_SYSTEM_CURL=ON
  7. CMake fails!

Context

In order to be backwards compatible on linux, you must compile on an older distribution than the one you want to support. So if I wanted to support Ubuntu 14.04 and up, that means I must compile my program on Ubuntu 14.04. One of my dependencies is AppImageUpdate (https://github.com/AppImage/AppImageUpdate), which relies on libcpr. While attempting to compile that I got this error.

Your Environment

gholmann16 commented 2 years ago

@TheAssassin

KingKili commented 2 years ago

It seems to me like the libcurl version of Ubuntu 14.04 is propably to old. You can try to use a fetch content curl instead

TheAssassin commented 1 year ago

My guess is CMake's FindCURL.cmake is reporting things incorrectly there. Even though libcurl provides HTTP/HTTPS support, CMake's built-in check doesn't report this, even though compilation would succeed.

gholmann16 commented 1 year ago

It seems to me like the libcurl version of Ubuntu 14.04 is propably to old. You can try to use a fetch content curl instead

I tried building it previously and that did not solve it

My guess is CMake's FindCURL.cmake is reporting things incorrectly there. Even though libcurl provides HTTP/HTTPS support, CMake's built-in check doesn't report this, even though compilation would succeed.

I do think this is definitely a cmake error, because the curl command is functioning for http links and reporting that it has http functionality.

Nightyly commented 1 year ago

I am getting the same error when trying to build cpr, in windows 10, using g++ 12.2.0 and cmake 3.23.1, I tried both building curl from source and getting libcurl from msys2 via pacman -S libcurl-devel, but to no avail. I then tried to use both cmake and make downloaded from msys2, this time cmake was able to create build files, but when trying to compile, i got fd_set and associated macros have been defined in sys/types. This can cause runtime problems with W32 sockets, and then a compilation error, I am assuming because there is a collision between msys2's headers and windows's

TheAssassin commented 1 year ago

This has got nothing to do with headers. Look at the CMake module's code https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindCURL.cmake (or better check your local version, modules get updated every now and then).

The workflow is easy to understand. First, CMake needs to find the library:

Assuming the package has been found in some way, it checks for the components. If pkg-config is used, it'll use its information, otherwise it will use curl-config to check for the protocols.

This last check is unreliable if the information fed into it is incomplete or incorrect for obvious reasons. Hence, my workaround in some places is to just delete the pkg-config file and have it fall back to curl-config, which is built along with the cURL code and therefore should be correct (the pkg-config file might be maintainer-provided and possibly outdated).

ronytigo commented 1 year ago

I get Could NOT find CURL (missing: HTTP) (found version "7.80.0"). Any update?

cppdecl commented 1 year ago

I get Could NOT find CURL (missing: HTTP) (found version "7.80.0"). Any update?

I fixed this issue by uninstalling currently installed curl (not sure if this is really required), then installing the latest curl from the tarball from https://github.com/curl/curl/releases, afther which i then installed cpr with -DCPR_USE_SYSTEM_CURL=ON

Hope it works for you.

TheAssassin commented 1 year ago

I fixed this issue by uninstalling currently installed curl (not sure if this is really required), then installing the latest curl from the tarball from https://github.com/curl/curl/releases, afther which i then installed cpr with -DCPR_USE_SYSTEM_CURL=ON

Please beware that you shouldn't just install libraries from random places on productive systems.

The easiest workaround is shown here, which I already explained in my last comment. By deleting the pkg-config files from the build system (I wouldn't necessarily recommend this on a productive/development system), CMake will use curl-config, which works as expected.

Someone needs to report this bug upstream with CMake. This is not a bug in CPR.