From 25bb0957d0a8a611a0dda6574ce3613b0b1d87f4 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Sun, 15 Dec 2024 10:56:18 +0100 Subject: [PATCH] curl: build a static library (#2004) Since there's only one user: zsync2. --- thirdparty/curl/CMakeLists.txt | 23 ++---- thirdparty/curl/pocketbook_lib_rename.patch | 23 ------ thirdparty/curl/use_-pthread.patch | 10 +++ thirdparty/zsync2/CMakeLists.txt | 6 +- thirdparty/zsync2/cpr_cmake_tweaks.patch | 77 +++++++++++++++++++++ thirdparty/zsync2/cpr_need_pthread.patch | 14 ---- 6 files changed, 94 insertions(+), 59 deletions(-) delete mode 100644 thirdparty/curl/pocketbook_lib_rename.patch create mode 100644 thirdparty/curl/use_-pthread.patch create mode 100644 thirdparty/zsync2/cpr_cmake_tweaks.patch delete mode 100644 thirdparty/zsync2/cpr_need_pthread.patch diff --git a/thirdparty/curl/CMakeLists.txt b/thirdparty/curl/CMakeLists.txt index aaa043ff3..6b652b157 100644 --- a/thirdparty/curl/CMakeLists.txt +++ b/thirdparty/curl/CMakeLists.txt @@ -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… @@ -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 diff --git a/thirdparty/curl/pocketbook_lib_rename.patch b/thirdparty/curl/pocketbook_lib_rename.patch deleted file mode 100644 index f99dca57b..000000000 --- a/thirdparty/curl/pocketbook_lib_rename.patch +++ /dev/null @@ -1,23 +0,0 @@ ---- i/lib/CMakeLists.txt -+++ w/lib/CMakeLists.txt -@@ -21,8 +21,8 @@ - # SPDX-License-Identifier: curl - # - ########################################################################### --set(LIB_NAME libcurl) --set(LIBCURL_OUTPUT_NAME libcurl CACHE STRING "Basename of the curl library") -+set(LIB_NAME libcurl_ko) -+set(LIBCURL_OUTPUT_NAME libcurl_ko CACHE STRING "Basename of the curl library") - add_definitions(-DBUILDING_LIBCURL) - - configure_file(curl_config.h.cmake ---- i/libcurl.pc.in -+++ w/libcurl.pc.in -@@ -36,6 +36,6 @@ Name: libcurl - URL: https://curl.se/ - Description: Library to transfer files with ftp, http, etc. - Version: @CURLVERSION@ --Libs: -L${libdir} -lcurl @LIBCURL_NO_SHARED@ -+Libs: -L${libdir} -lcurl_ko @LIBCURL_NO_SHARED@ - Libs.private: @LIBCURL_LIBS@ - Cflags: -I${includedir} @CPPFLAG_CURL_STATICLIB@ diff --git a/thirdparty/curl/use_-pthread.patch b/thirdparty/curl/use_-pthread.patch new file mode 100644 index 000000000..4c1943492 --- /dev/null +++ b/thirdparty/curl/use_-pthread.patch @@ -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}) diff --git a/thirdparty/zsync2/CMakeLists.txt b/thirdparty/zsync2/CMakeLists.txt index cd1f49b7a..c5a044784 100644 --- a/thirdparty/zsync2/CMakeLists.txt +++ b/thirdparty/zsync2/CMakeLists.txt @@ -1,7 +1,4 @@ -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} @@ -9,6 +6,7 @@ list(APPEND CMAKE_ARGS # Options. -DBUILD_CPR_TESTS=FALSE -DBUILD_TESTING=FALSE + -DCPR_FORCE_OPENSSL_BACKEND=TRUE -DUSE_SYSTEM_CURL=TRUE ) diff --git a/thirdparty/zsync2/cpr_cmake_tweaks.patch b/thirdparty/zsync2/cpr_cmake_tweaks.patch new file mode 100644 index 000000000..e17cfc804 --- /dev/null +++ b/thirdparty/zsync2/cpr_cmake_tweaks.patch @@ -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. diff --git a/thirdparty/zsync2/cpr_need_pthread.patch b/thirdparty/zsync2/cpr_need_pthread.patch deleted file mode 100644 index 0a506abf1..000000000 --- a/thirdparty/zsync2/cpr_need_pthread.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- a/lib/cpr/cpr/CMakeLists.txt -+++ b/lib/cpr/cpr/CMakeLists.txt -@@ -40,6 +40,11 @@ if(SSL_BACKEND_USED STREQUAL "OpenSSL") - target_include_directories(cpr PRIVATE ${OPENSSL_INCLUDE_DIR}) - endif() - -+find_package(Threads) -+if(CMAKE_USE_PTHREADS_INIT) -+ target_link_libraries(cpr PRIVATE -pthread) -+endif() -+ - # Set version for shared libraries. - set_target_properties(cpr - PROPERTIES