Skip to content

Commit

Permalink
curl: build a static library (#2004)
Browse files Browse the repository at this point in the history
Since there's only one user: zsync2.
  • Loading branch information
benoit-pierre authored Dec 15, 2024
1 parent 808ec81 commit 25bb095
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 59 deletions.
23 changes: 5 additions & 18 deletions thirdparty/curl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ list(APPEND PATCH_FILES
curl-8.5.0-mpd-stream-http-adjust_pollset.patch
# Need `-lrt` for `clock_gettime` support.
clock_gettime_needs_rt.patch
# Use `-pthread` flag, not `-lpthread`
# to avoid conflicts with OpenSSL.
use_-pthread.patch
)
# NOTE: Because InkView is the worst, we rename our own cURL build on PocketBook.... (#5861)
if(POCKETBOOK)
list(APPEND PATCH_FILES pocketbook_lib_rename.patch)
endif()

list(APPEND CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
# Build a static library, since there's only one user (zsync2).
-DBUILD_SHARED_LIBS=FALSE
# Project options.
# TODO: Enable ZSTD support? We currently only use cURL
# for zsync2, so, obviously, not necessary right now…
Expand Down Expand Up @@ -41,20 +42,6 @@ list(APPEND INSTALL_CMD COMMAND ${CMAKE_COMMAND} --install .)

append_install_commands(INSTALL_CMD ${DOWNLOAD_DIR}/ca-bundle.crt DESTINATION data)

if(POCKETBOOK)
set(LIB_NAME curl_ko)
else()
set(LIB_NAME curl)
endif()
append_shared_lib_install_commands(INSTALL_CMD ${LIB_NAME} VERSION 4)

# Even after installing a patched pkg-config entry, we still need to add a symlink
# with the canonical library name or the mess that is CMake's FindCURl module will
# fail to detect our renamed library…
if(POCKETBOOK)
list(APPEND INSTALL_CMD COMMAND ${CMAKE_COMMAND} -E create_symlink libcurl_ko${LIB_EXT} ${STAGING_DIR}/lib/libcurl${LIB_EXT})
endif()

external_project(
DOWNLOAD URL 3e9e5c2db494e7dbd4e7024b149021c9
https://github.com/curl/curl/releases/download/curl-8_5_0/curl-8.5.0.tar.xz
Expand Down
23 changes: 0 additions & 23 deletions thirdparty/curl/pocketbook_lib_rename.patch

This file was deleted.

10 changes: 10 additions & 0 deletions thirdparty/curl/use_-pthread.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -378,6 +378,7 @@
if(WIN32)
set(USE_THREADS_WIN32 ON)
else()
+ set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
6 changes: 2 additions & 4 deletions thirdparty/zsync2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
list(APPEND PATCH_FILES
# CPR need `-pthread`.
cpr_need_pthread.patch
)
list(APPEND PATCH_FILES cpr_cmake_tweaks.patch)

list(APPEND CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DOPENSSL_USE_STATIC_LIBS=$<BOOL:${MONOLIBTIC}>
# Options.
-DBUILD_CPR_TESTS=FALSE
-DBUILD_TESTING=FALSE
-DCPR_FORCE_OPENSSL_BACKEND=TRUE
-DUSE_SYSTEM_CURL=TRUE
)

Expand Down
77 changes: 77 additions & 0 deletions thirdparty/zsync2/cpr_cmake_tweaks.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
--- i/lib/cpr/CMakeLists.txt
+++ w/lib/cpr/CMakeLists.txt
@@ -147,13 +147,10 @@ if(CPR_ENABLE_SSL)
endif()
else()
if(CPR_FORCE_OPENSSL_BACKEND)
- find_package(OpenSSL)
- if(OPENSSL_FOUND)
- message(STATUS "Using OpenSSL.")
- set(SSL_BACKEND_USED "OpenSSL")
- else()
- message(FATAL_ERROR "CPR_FORCE_OPENSSL_BACKEND enabled but we were not able to find OpenSSL!")
- endif()
+ find_package(PkgConfig REQUIRED)
+ pkg_check_modules(OpenSSL openssl REQUIRED IMPORTED_TARGET)
+ message(STATUS "Using OpenSSL.")
+ set(SSL_BACKEND_USED "OpenSSL")
elseif(CPR_FORCE_WINSSL_BACKEND)
message(STATUS "Using WinSSL.")
set(SSL_BACKEND_USED "WinSSL")
@@ -170,37 +167,13 @@ if(CPR_ENABLE_SSL)
endif()

if(SSL_BACKEND_USED STREQUAL "OpenSSL")
-# Fix missing OpenSSL includes for Windows since in 'ssl_ctx.cpp' we include OpenSSL directly
-find_package(OpenSSL REQUIRED)
add_compile_definitions(OPENSSL_BACKEND_USED)
endif()

# Curl configuration
if(CPR_USE_SYSTEM_CURL)
- if(CPR_ENABLE_SSL)
- 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.")
- endif()
- else()
- find_package(CURL COMPONENTS HTTP)
- if(CURL_FOUND)
- message(FATAL_ERROR "Curl found on this system but WITHOUT HTTPS/SSL support. Either disable SSL by setting CPR_ENABLE_SSL to OFF or use the built-in version of curl by setting CPR_USE_SYSTEM_CURL to OFF.")
- else()
- message(FATAL_ERROR "Curl not found on this system. To use the built-in version set CPR_USE_SYSTEM_CURL to OFF.")
- endif()
- endif()
- else()
- find_package(CURL COMPONENTS HTTP)
- if(CURL_FOUND)
- message(STATUS "Curl found on this system.")
- else()
- message(FATAL_ERROR "Curl not found on this system. To use the built-in version set CPR_USE_SYSTEM_CURL to OFF.")
- endif()
- endif()
+ find_package(PkgConfig REQUIRED)
+ pkg_check_modules(CURL libcurl REQUIRED IMPORTED_TARGET)
else()
message(STATUS "Configuring built-in curl...")

--- i/lib/cpr/cpr/CMakeLists.txt
+++ w/lib/cpr/cpr/CMakeLists.txt
@@ -32,12 +32,11 @@ 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 PkgConfig::CURL) # 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")
- target_link_libraries(cpr PRIVATE OpenSSL::SSL)
- target_include_directories(cpr PRIVATE ${OPENSSL_INCLUDE_DIR})
+ target_link_libraries(cpr PRIVATE PkgConfig::OpenSSL)
endif()

# Set version for shared libraries.
14 changes: 0 additions & 14 deletions thirdparty/zsync2/cpr_need_pthread.patch

This file was deleted.

0 comments on commit 25bb095

Please sign in to comment.