From dc910ceaeb2e07c0ab53959b0bc2a4784f1b4969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3=E8=88=9F?= Date: Tue, 26 Sep 2023 15:32:35 +0800 Subject: [PATCH] build overlaybd using static compiled libcurl 7.42.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 鸣舟 --- CMake/FindCURL.cmake | 50 ++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 CMake/FindCURL.cmake diff --git a/CMake/FindCURL.cmake b/CMake/FindCURL.cmake new file mode 100644 index 00000000..9b79ea58 --- /dev/null +++ b/CMake/FindCURL.cmake @@ -0,0 +1,50 @@ +include(FetchContent) + +if(${BUILD_CURL_FROM_SOURCE}) + message("Add and build standalone libcurl") + include(FetchContent) + FetchContent_Declare( + curl_bundle + GIT_REPOSITORY https://github.com/curl/curl.git + GIT_TAG curl-7_42_1 + GIT_PROGRESS 1) + + FetchContent_MakeAvailable(curl_bundle) + + # In libcurl, CMakeLists build static lib is broken add build command via + # make + if(NOT TARGET libcurl_static_build) + add_custom_command( + OUTPUT ${curl_bundle_BINARY_DIR}/lib/libcurl.a + WORKING_DIRECTORY ${curl_bundle_SOURCE_DIR} + COMMAND + autoreconf -i && sh configure --with-openssl --without-libssh2 + --enable-static --enable-shared=no --enable-optimize + --enable-symbol-hiding --disable-manual --without-libidn + --prefix=${curl_bundle_BINARY_DIR} && make -j && make install) + add_custom_target(libcurl_static_build + DEPENDS ${curl_bundle_BINARY_DIR}/lib/libcurl.a) + endif() + + set(CURL_FOUND yes) + set(CURL_LIBRARY ${curl_bundle_BINARY_DIR}/lib/libcurl.a) + set(CURL_LIBRARIES ${CURL_LIBRARY}) + set(CURL_INCLUDE_DIR ${curl_bundle_BINARY_DIR}/include) + set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) + set(CURL_VERSION_STRING 7.42.1) + + # Use libcurl static lib instead of cmake defined shared lib + if(NOT TARGET CURL::libcurl) + add_library(CURL::libcurl UNKNOWN IMPORTED) + endif() + add_dependencies(CURL::libcurl libcurl_static_build) + message("${CURL_LIBRARY}") + set_target_properties( + CURL::libcurl + PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" + INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}" + IMPORTED_LOCATION "${CURL_LIBRARY}" + IMPORTED_LINK_DEPENDENT_LIBRARIES "crypto ssl") +else() + include(${CMAKE_ROOT}/Modules/FindCURL.cmake) +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 798f86ea..51fbac88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ endif() set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED on) set(ENABLE_MIMIC_VDSO off) - +option(BUILD_CURL_FROM_SOURCE "Compile static libcurl" on) find_package(photon REQUIRED) find_package(tcmu REQUIRED)