Skip to content

Commit

Permalink
Updated libcpr from v1.10.5 to v1.11.0 (Curl 8.10.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
baderouaich committed Oct 17, 2024
1 parent 0b05c87 commit 5b25533
Show file tree
Hide file tree
Showing 76 changed files with 1,108 additions and 692 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10)
project(tgbotxx VERSION "1.0.6.9" DESCRIPTION "Telegram Bot C++ Library" LANGUAGES C CXX)
project(tgbotxx VERSION "1.1.6.9" DESCRIPTION "Telegram Bot C++ Library" LANGUAGES C CXX)
# Note: tgbotxx version's patch & build is based on Telegram Bot Api version for compatibility. See https://core.telegram.org/bots/api-changelog
# <OurMajorVersion>.<OurMinorVersion>.<TelegramBotApiMajorVersion>.<TelegramBotApiMinorVersion>

Expand Down
48 changes: 36 additions & 12 deletions lib/cpr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15)
project(cpr VERSION 1.10.5 LANGUAGES CXX)
project(cpr VERSION 1.11.0 LANGUAGES CXX)

math(EXPR cpr_VERSION_NUM "${cpr_VERSION_MAJOR} * 0x10000 + ${cpr_VERSION_MINOR} * 0x100 + ${cpr_VERSION_PATCH}" OUTPUT_FORMAT HEXADECIMAL)
configure_file("${cpr_SOURCE_DIR}/cmake/cprver.h.in" "${cpr_BINARY_DIR}/cpr_generated_includes/cpr/cprver.h")
Expand Down Expand Up @@ -48,7 +48,6 @@ macro(cpr_option OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
endmacro()

option(BUILD_SHARED_LIBS "Build libraries as shared libraries" ON)
message(STATUS "C++ Requests CMake Options")
message(STATUS "=======================================================")
cpr_option(CPR_GENERATE_COVERAGE "Set to ON to generate coverage reports." OFF)
Expand All @@ -67,6 +66,7 @@ cpr_option(CPR_ENABLE_CPPCHECK "Set to ON to enable Cppcheck static analysis. Re
cpr_option(CPR_BUILD_TESTS "Set to ON to build cpr tests." OFF)
cpr_option(CPR_BUILD_TESTS_SSL "Set to ON to build cpr ssl tests" ${CPR_BUILD_TESTS})
cpr_option(CPR_BUILD_TESTS_PROXY "Set to ON to build proxy tests. They fail in case there is no valid proxy server available in proxy_tests.cpp" OFF)
cpr_option(CPR_BUILD_VERSION_OUTPUT_ONLY "Set to ON to only export the version into 'build/version.txt' and exit" OFF)
cpr_option(CPR_SKIP_CA_BUNDLE_SEARCH "Skip searching for Certificate Authority certs. Turn ON for systems like iOS where file access is restricted and prevents https from working." OFF)
cpr_option(CPR_USE_BOOST_FILESYSTEM "Set to ON to use the Boost.Filesystem library. This is useful, on, e.g., Apple platforms, where std::filesystem may not always be available when targeting older OS versions." OFF)
cpr_option(CPR_DEBUG_SANITIZER_FLAG_THREAD "Enables the ThreadSanitizer for debug builds." OFF)
Expand All @@ -76,6 +76,13 @@ cpr_option(CPR_DEBUG_SANITIZER_FLAG_UB "Enables the UndefinedBehaviorSanitizer f
cpr_option(CPR_DEBUG_SANITIZER_FLAG_ALL "Enables all sanitizers for debug builds except the ThreadSanitizer since it is incompatible with the other sanitizers." OFF)
message(STATUS "=======================================================")

# Save the project version as txt file for deb and NuGet builds
if(CPR_BUILD_VERSION_OUTPUT_ONLY)
message(STATUS "Printing version and exiting...")
file(WRITE "${CMAKE_BINARY_DIR}/version.txt" "${PROJECT_VERSION}")
return()
endif()

if (CPR_FORCE_USE_SYSTEM_CURL)
message(WARNING "The variable CPR_FORCE_USE_SYSTEM_CURL is deprecated, please use CPR_USE_SYSTEM_CURL instead")
set(CPR_USE_SYSTEM_CURL ${CPR_FORCE_USE_SYSTEM_CURL})
Expand Down Expand Up @@ -103,11 +110,6 @@ if(CPR_ENABLE_CPPCHECK)
include(cmake/cppcheck.cmake)
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
endif()

# SSL
if(CPR_ENABLE_SSL)
if(CPR_FORCE_OPENSSL_BACKEND OR CPR_FORCE_WINSSL_BACKEND OR CPR_FORCE_DARWINSSL_BACKEND OR CPR_FORCE_MBEDTLS_BACKEND)
Expand Down Expand Up @@ -181,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.")
Expand All @@ -201,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...")

Expand All @@ -209,7 +217,6 @@ else()
# * from command line:
# -DCURL_ZLIB=OFF
# * from CMake script:
# SET(CURL_ZLIB OFF CACHE STRING "" FORCE)
if (CURL_ZLIB OR CURL_ZLIB STREQUAL AUTO OR NOT DEFINED CACHE{CURL_ZLIB})
include(cmake/zlib_external.cmake)
endif()
Expand Down Expand Up @@ -278,14 +285,23 @@ else()
cmake_policy(SET CMP0135 NEW)
endif()
FetchContent_Declare(curl
URL https://github.com/curl/curl/releases/download/curl-8_4_0/curl-8.4.0.tar.xz
URL_HASH SHA256=16c62a9c4af0f703d28bda6d7bbf37ba47055ad3414d70dec63e2e6336f2a82d # the file hash for curl-8.4.0.tar.xz
URL https://github.com/curl/curl/releases/download/curl-8_10_1/curl-8.10.1.tar.xz
URL_HASH SHA256=73a4b0e99596a09fa5924a4fb7e4b995a85fda0d18a2c02ab9cf134bebce04ee # the file hash for curl-8.10.1.tar.xz
USES_TERMINAL_DOWNLOAD TRUE) # <---- This is needed only for Ninja to show download progress
FetchContent_MakeAvailable(curl)

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)
Expand All @@ -304,8 +320,8 @@ if(CPR_BUILD_TESTS)
clear_variable(DESTINATION CMAKE_CXX_CLANG_TIDY BACKUP CMAKE_CXX_CLANG_TIDY_BKP)

FetchContent_Declare(googletest
URL https://github.com/google/googletest/archive/release-1.11.0.tar.gz
URL_HASH SHA256=b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5 # the file hash for release-1.11.0.tar.gz
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
URL_HASH SHA256=8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7 # the file hash for release-1.14.0.tar.gz
USES_TERMINAL_DOWNLOAD TRUE) # <---- This is needed only for Ninja to show download progress
FetchContent_MakeAvailable(googletest)

Expand Down Expand Up @@ -363,6 +379,14 @@ if(CPR_BUILD_TESTS)
restore_variable(DESTINATION CMAKE_CXX_CLANG_TIDY BACKUP CMAKE_CXX_CLANG_TIDY_BKP)
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Disable C++98 compatibility support in clang: https://github.com/libcpr/cpr/issues/927
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-nonportable-system-include-path -Wno-exit-time-destructors -Wno-undef -Wno-global-constructors -Wno-switch-enum -Wno-old-style-cast -Wno-covered-switch-default -Wno-undefined-func-template")
endif()
endif()

add_subdirectory(cpr)
add_subdirectory(include)
Expand Down
38 changes: 32 additions & 6 deletions lib/cpr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Add the following to your `CMakeLists.txt`.
```cmake
include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG 0817715923c9705e68994eb52ef9df3f6845beba) # The commit hash for 1.10.x. Replace with the latest from: https://github.com/libcpr/cpr/releases
GIT_TAG 3b15fa82ea74739b574d705fea44959b58142eb8) # Replace with your desired git commit from: https://github.com/libcpr/cpr/releases
FetchContent_MakeAvailable(cpr)
```

Expand All @@ -112,19 +112,39 @@ If you prefer not to use `fetch_content`, you can download, build, and install t

**Note:** this feature is feasible only if CPR_USE_SYSTEM_CURL is set. (see [#645](https://github.com/libcpr/cpr/pull/645))
```Bash
$ git clone https://github.com/libcpr/cpr.git
$ cd cpr && mkdir build && cd build
$ cmake .. -DCPR_USE_SYSTEM_CURL=ON
$ cmake --build .
$ sudo cmake --install .
git clone https://github.com/libcpr/cpr.git
cd cpr && mkdir build && cd build
cmake .. -DCPR_USE_SYSTEM_CURL=ON
cmake --build . --parallel
sudo cmake --install .
```
#### Build Static Library
As an alternative if you want to switch between a static or shared version of cpr use ['-DBUILD_SHARED_LIBS=ON/OFF'](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html).
```Bash
git clone https://github.com/libcpr/cpr.git
cd cpr && mkdir build && cd build
cmake .. -DCPR_USE_SYSTEM_CURL=ON -DBUILD_SHARED_LIBS=OFF
cmake --build . --parallel
sudo cmake --install .
```

In your `CMakeLists.txt`:
```cmake
find_package(cpr REQUIRED)
add_executable(your_target_name your_target_name.cpp)
target_link_libraries(your_target_name PRIVATE cpr::cpr)
```

#### Tests
`cpr` provides a bunch of tests that can be executed via the following commands.
```Bash
git clone https://github.com/libcpr/cpr.git
cd cpr && mkdir build && cd build
cmake .. -DCPR_BUILD_TESTS=ON # There are other test related options like 'CPR_BUILD_TESTS_SSL' and 'CPR_BUILD_TESTS_PROXY'
cmake --build . --parallel
ctest -VV # -VV is optional since it enables verbose output
```

### Bazel

Please refer to [hedronvision/bazel-make-cc-https-easy](https://github.com/hedronvision/bazel-make-cc-https-easy).
Expand All @@ -136,6 +156,7 @@ Alternatively, you may install a package specific to your Linux distribution. Si
Currently, we are aware of packages for the following distributions:

* [Arch Linux (AUR)](https://aur.archlinux.org/packages/cpr)
* [Fedora Linux](https://src.fedoraproject.org/rpms/cpr)

If there's no package for your distribution, try making one! If you do, and it is added to your distribution's repositories, please submit a pull request to add it to the list above. However, please only do this if you plan to actively maintain the package.

Expand All @@ -145,13 +166,18 @@ For Windows, there is also a libcpr NuGet package available. Currently, x86 and

The package can be found here: [NuGet.org](https://www.nuget.org/packages/libcpr/)

### Port for macOS

On macOS you may install cpr via [MacPorts.org](https://ports.macports.org/port/cpr) (arm64, x86_64, powerpc)

## Requirements

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

Expand Down
5 changes: 4 additions & 1 deletion lib/cpr/cmake/mongoose.CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ target_include_directories(mongoose PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if(ENABLE_SSL_TESTS)
# Enable mongoose SSL
target_compile_definitions(mongoose PUBLIC MG_ENABLE_OPENSSL)
target_link_libraries(mongoose PRIVATE OpenSSL::SSL)
target_link_libraries(mongoose PUBLIC OpenSSL::SSL)

# Fix macOS and Windows invalid OpenSSL include path
target_include_directories(mongoose PUBLIC "${OPENSSL_INCLUDE_DIR}")
endif()
11 changes: 11 additions & 0 deletions lib/cpr/cmake/std_fs_support_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

int main() {
auto cwd = fs::current_path();
}
4 changes: 2 additions & 2 deletions lib/cpr/cmake/zlib_external.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ set(ZLIB_ENABLE_TESTS OFF CACHE INTERNAL "" FORCE)

FetchContent_Declare(zlib
GIT_REPOSITORY https://github.com/zlib-ng/zlib-ng
GIT_TAG 2.0.6
GIT_TAG 2.1.3
USES_TERMINAL_DOWNLOAD TRUE)
FetchContent_MakeAvailable(zlib)

# Fix Windows zlib dll names from "zlibd1.dll" to "zlib.dll":
if(WIN32)
if(WIN32 AND BUILD_SHARED_LIBS)
set_target_properties(zlib PROPERTIES OUTPUT_NAME "zlib")
set_target_properties(zlib PROPERTIES DEBUG_POSTFIX "")
set_target_properties(zlib PROPERTIES SUFFIX ".dll")
Expand Down
26 changes: 0 additions & 26 deletions lib/cpr/cpr-config.cmake

This file was deleted.

30 changes: 12 additions & 18 deletions lib/cpr/cpr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -49,13 +49,13 @@ set_target_properties(cpr
# Import GNU common install directory variables
include(GNUInstallDirs)

if(CPR_USE_SYSTEM_CURL)
install(TARGETS cpr
EXPORT cprTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS cpr
EXPORT cprTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(CPR_USE_SYSTEM_CURL)
# Include CMake helpers for package config files
# Follow this installation guideline: https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html
include(CMakePackageConfigHelpers)
Expand All @@ -69,17 +69,11 @@ if(CPR_USE_SYSTEM_CURL)
"${PROJECT_BINARY_DIR}/cpr/cprConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpr)

install(EXPORT cprTargets
FILE cprTargets.cmake
NAMESPACE cpr::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpr)

install(FILES ${PROJECT_BINARY_DIR}/cpr/cprConfig.cmake
${PROJECT_BINARY_DIR}/cpr/cprConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpr)

else()
install(TARGETS cpr
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

install(EXPORT cprTargets
FILE cprTargets.cmake
NAMESPACE cpr::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpr)
3 changes: 2 additions & 1 deletion lib/cpr/cpr/accept_encoding.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "cpr/accept_encoding.h"

#include <algorithm>
#include <cassert>
#include <initializer_list>
#include <iterator>
#include <numeric>
#include <stdexcept>
#include <string>
#include <utility>

namespace cpr {

Expand Down
10 changes: 10 additions & 0 deletions lib/cpr/cpr/auth.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include "cpr/auth.h"
#include "cpr/util.h"

#include <string_view>

namespace cpr {

Authentication::Authentication(std::string_view username, std::string_view password, AuthMode auth_mode) : auth_mode_{auth_mode} {
auth_string_.reserve(username.size() + 1 + password.size());
auth_string_ += username;
auth_string_ += ':';
auth_string_ += password;
}

Authentication::~Authentication() noexcept {
util::secureStringClear(auth_string_);
}
Expand Down
1 change: 1 addition & 0 deletions lib/cpr/cpr/bearer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cpr/bearer.h"
#include "cpr/util.h"
#include <curl/curlver.h>

namespace cpr {
// Only supported with libcurl >= 7.61.0.
Expand Down
4 changes: 2 additions & 2 deletions lib/cpr/cpr/callback.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <cpr/callback.h>
#include <curl/curl.h>
#include "cpr/callback.h"
#include "cpr/cprtypes.h"
#include <functional>

namespace cpr {
Expand Down
2 changes: 2 additions & 0 deletions lib/cpr/cpr/cert_info.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "cpr/cert_info.h"
#include <cstddef>
#include <string>

namespace cpr {

Expand Down
Loading

0 comments on commit 5b25533

Please sign in to comment.