diff --git a/CMakeLists.txt b/CMakeLists.txt index 13dbae09b..70d3296d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,6 +183,7 @@ if(CPR_USE_SYSTEM_CURL) find_package(CURL COMPONENTS HTTP HTTPS) if(CURL_FOUND) message(STATUS "Curl ${CURL_VERSION_STRING} found on this system.") + # To be able to load certificates under Windows when using OpenSSL: if(CMAKE_USE_OPENSSL AND WIN32 AND (NOT (CURL_VERSION_STRING VERSION_GREATER_EQUAL "7.71.0"))) message(FATAL_ERROR "Your system curl version (${CURL_VERSION_STRING}) is too old to support OpenSSL on Windows which requires curl >= 7.71.0. Update your curl version, use WinSSL, disable SSL or use the built-in version of curl.") @@ -203,6 +204,11 @@ if(CPR_USE_SYSTEM_CURL) message(FATAL_ERROR "Curl not found on this system. To use the built-in version set CPR_USE_SYSTEM_CURL to OFF.") endif() endif() + + # Check for the minimum supported curl version + if(NOT (CURL_VERSION_STRING VERSION_GREATER_EQUAL "7.64.0")) + message(FATAL_ERROR "Your system curl version (${CURL_VERSION_STRING}) is too old! curl >= 7.64.0 is required. Update your curl version, or use the build in curl version e.g. via `cmake .. -DCPR_USE_SYSTEM_CURL=OFF` during CMake configure.") + endif() else() message(STATUS "Configuring built-in curl...") @@ -287,6 +293,15 @@ else() restore_variable(DESTINATION CMAKE_CXX_CLANG_TIDY BACKUP CMAKE_CXX_CLANG_TIDY_BKP) endif() +# Depending on which version of libcurl we are using the CMake target is called differently +if(TARGET libcurl) + # Old curl CMake target name + set(CURL_LIB libcurl) +else() + # New curl CMake target name + set(CURL_LIB CURL::libcurl) +endif() + # GTest configuration if(CPR_BUILD_TESTS) if(CPR_USE_SYSTEM_GTEST) diff --git a/README.md b/README.md index 1585e1811..ce63880f7 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,7 @@ The only explicit requirements are: * a `C++17` compatible compiler such as Clang or GCC. The minimum required version of GCC is unknown, so if anyone has trouble building this library with a specific version of GCC, do let us know * in case you only have a `C++11` compatible compiler available, all versions below cpr 1.9.x are for you. The 1.10.0 release of cpr switches to `C++17` as a requirement. * If you would like to perform https requests `OpenSSL` and its development libraries are required. +* If you do not use the build in version of [curl](https://github.com/curl/curl) but instead use your systems version, make sure you use a version `>= 7.64.0`. Lower versions are not supported. This means you need Debian `>= 10` or Ubuntu `>= 20.04 LTS`. ## Building cpr - Using vcpkg diff --git a/cpr/CMakeLists.txt b/cpr/CMakeLists.txt index 3428e0b35..0c7083c4e 100644 --- a/cpr/CMakeLists.txt +++ b/cpr/CMakeLists.txt @@ -32,7 +32,7 @@ add_library(cpr add_library(cpr::cpr ALIAS cpr) -target_link_libraries(cpr PUBLIC CURL::libcurl) # todo should be private, but first dependencies in ssl_options need to be removed +target_link_libraries(cpr PUBLIC ${CURL_LIB}) # todo should be private, but first dependencies in ssl_options need to be removed # Fix missing OpenSSL includes for Windows since in 'ssl_ctx.cpp' we include OpenSSL directly if(SSL_BACKEND_USED STREQUAL "OpenSSL") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f30e5d1f2..d78ff8229 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,7 +26,7 @@ macro(add_cpr_test _TEST_NAME) test_server GTest::GTest cpr::cpr - CURL::libcurl) + ${CURL_LIB}) add_test(NAME cpr_${_TEST_NAME}_tests COMMAND ${_TEST_NAME}_tests) # Group under the "tests" project folder in IDEs such as Visual Studio. set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")