From: Joel Rosdahl Date: Fri, 27 Jan 2023 12:09:25 +0000 (+0100) Subject: feat: Allow forcing download of zstd and hiredis again X-Git-Tag: v4.8~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe5ddc9e79c39ba1b98f124561ce1b3f2cec3c19;p=thirdparty%2Fccache.git feat: Allow forcing download of zstd and hiredis again Before it was possible to force downloading of the Zstandard library using "-D ZSTD_FROM_INTERNET=ON" and similar for Hiredis. That ability was lost in 2c742c2c7ca9, so if you for some reason want to not use a locally installed library you're out of luck. Improve this by letting ZSTD_FROM_INTERNET and HIREDIS_FROM_INTERNET be tristate variables: ON: Always download AUTO (default): Download if local installation not found OFF: Never download As mentioned in #1240. --- diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 363afdcbb..197cd93f0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -221,7 +221,7 @@ jobs: path: testdir.tar.xz build_macos_universal: - name: MacOS Universal Binary + name: macOS universal binary runs-on: macos-12 env: CMAKE_GENERATOR: Ninja diff --git a/CMakeLists.txt b/CMakeLists.txt index 06644f74f..a929775ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,13 +112,11 @@ endif() # # Third party # -option(ZSTD_FROM_INTERNET - "Download and use libzstd from the Internet if not available" ON) -option(HIREDIS_FROM_INTERNET - "Download and use libhiredis from the Internet if not available" ON) +set(ZSTD_FROM_INTERNET AUTO CACHE STRING "Download and use libzstd from the Internet") +set_property(CACHE ZSTD_FROM_INTERNET PROPERTY STRINGS AUTO ON OFF) -option(FORCE_INTERNET_ZSTD - "Only use libzstd from the Internet" OFF) +set(HIREDIS_FROM_INTERNET AUTO CACHE STRING "Download and use libhiredis from the Internet") +set_property(CACHE HIREDIS_FROM_INTERNET PROPERTY STRINGS AUTO ON OFF) find_package(zstd 1.1.2 MODULE REQUIRED) diff --git a/ci/build-macos-binary b/ci/build-macos-binary index 44381d30f..403305c3d 100755 --- a/ci/build-macos-binary +++ b/ci/build-macos-binary @@ -5,7 +5,13 @@ set -eu build() { mkdir -p "build_$1" cd "build_$1" - cmake -DFORCE_INTERNET_ZSTD=ON -DCMAKE_OSX_DEPLOYMENT_TARGET="10.15" -DCMAKE_OSX_ARCHITECTURES="$1" -DCMAKE_SYSTEM_PROCESSOR="$1" .. + cmake \ + -DZSTD_FROM_INTERNET=ON \ + -DHIREDIS_FROM_INTERNET=ON \ + -DCMAKE_OSX_DEPLOYMENT_TARGET="10.15" \ + -DCMAKE_OSX_ARCHITECTURES="$1" \ + -DCMAKE_SYSTEM_PROCESSOR="$1" \ + .. cmake --build . cd .. } diff --git a/cmake/Findhiredis.cmake b/cmake/Findhiredis.cmake index b8045f6f2..b52cb1d8f 100644 --- a/cmake/Findhiredis.cmake +++ b/cmake/Findhiredis.cmake @@ -4,52 +4,66 @@ endif() set(hiredis_FOUND FALSE) -find_package(PkgConfig) -if(PKG_CONFIG_FOUND) - pkg_check_modules(HIREDIS hiredis>=${hiredis_FIND_VERSION}) - find_library(HIREDIS_LIBRARY ${HIREDIS_LIBRARIES} HINTS ${HIREDIS_LIBDIR}) - find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h HINTS ${HIREDIS_PREFIX}/include) +if(HIREDIS_FROM_INTERNET AND NOT HIREDIS_FROM_INTERNET STREQUAL "AUTO") + message(STATUS "Using hiredis from the Internet") + set(do_download TRUE) else() - find_library(HIREDIS_LIBRARY hiredis) - find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h) -endif() - -if(HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARY) - mark_as_advanced(HIREDIS_INCLUDE_DIR HIREDIS_LIBRARY) + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(HIREDIS hiredis>=${hiredis_FIND_VERSION}) + find_library(HIREDIS_LIBRARY ${HIREDIS_LIBRARIES} HINTS ${HIREDIS_LIBDIR}) + find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h HINTS ${HIREDIS_PREFIX}/include) + if(HIREDIS_LIBRARY AND HIREDIS_INCLUDE_DIR) + message(STATUS "Using hiredis from ${HIREDIS_LIBRARY} via pkg-config") + set(hiredis_FOUND TRUE) + endif() + endif() - add_library(HIREDIS::HIREDIS UNKNOWN IMPORTED) - set_target_properties( - HIREDIS::HIREDIS - PROPERTIES - IMPORTED_LOCATION "${HIREDIS_LIBRARY}" - INTERFACE_COMPILE_OPTIONS "${HIREDIS_CFLAGS_OTHER}" - INTERFACE_INCLUDE_DIRECTORIES "${HIREDIS_INCLUDE_DIR}") - if(WIN32 AND STATIC_LINK) - target_link_libraries(HIREDIS::HIREDIS INTERFACE ws2_32) + if(NOT hiredis_FOUND) + find_library(HIREDIS_LIBRARY hiredis) + find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h) + if(HIREDIS_LIBRARY AND HIREDIS_INCLUDE_DIR) + message(STATUS "Using hiredis from ${HIREDIS_LIBRARY}") + set(hiredis_FOUND TRUE) + endif() endif() - set(hiredis_FOUND TRUE) - set(target HIREDIS::HIREDIS) -elseif(HIREDIS_FROM_INTERNET) - message(STATUS "*** WARNING ***: Using hiredis from the internet because it was NOT found and HIREDIS_FROM_INTERNET is TRUE") + if(hiredis_FOUND) + mark_as_advanced(HIREDIS_INCLUDE_DIR HIREDIS_LIBRARY) + add_library(HIREDIS::HIREDIS UNKNOWN IMPORTED) + set_target_properties( + HIREDIS::HIREDIS + PROPERTIES + IMPORTED_LOCATION "${HIREDIS_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${HIREDIS_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${HIREDIS_INCLUDE_DIR}" + ) + if(WIN32 AND STATIC_LINK) + target_link_libraries(HIREDIS::HIREDIS INTERFACE ws2_32) + endif() + set(hiredis_FOUND TRUE) + set(target HIREDIS::HIREDIS) + elseif(HIREDIS_FROM_INTERNET STREQUAL "AUTO") + message(STATUS "*** WARNING ***: Using hiredis from the Internet because it was not found and HIREDIS_FROM_INTERNET is AUTO") + set(do_download TRUE) + endif() +endif() +if(do_download) set(hiredis_version "1.1.0") - set(hiredis_dir ${CMAKE_BINARY_DIR}/hiredis-${hiredis_version}) set(hiredis_build ${CMAKE_BINARY_DIR}/hiredis-build) include(FetchContent) - FetchContent_Declare( hiredis - URL https://github.com/redis/hiredis/archive/v${hiredis_version}.tar.gz - URL_HASH SHA256=fe6d21741ec7f3fc9df409d921f47dfc73a4d8ff64f4ac6f1d95f951bf7f53d6 - SOURCE_DIR ${hiredis_dir} - BINARY_DIR ${hiredis_build} + URL https://github.com/redis/hiredis/archive/v${hiredis_version}.tar.gz + URL_HASH SHA256=fe6d21741ec7f3fc9df409d921f47dfc73a4d8ff64f4ac6f1d95f951bf7f53d6 + SOURCE_DIR ${hiredis_dir} + BINARY_DIR ${hiredis_build} ) FetchContent_GetProperties(hiredis) - if(NOT hiredis_POPULATED) FetchContent_Populate(hiredis) endif() @@ -88,7 +102,6 @@ endif() if(WIN32 AND hiredis_FOUND) target_link_libraries(${target} INTERFACE ws2_32) endif() -unset(target) include(FeatureSummary) set_package_properties( diff --git a/cmake/Findzstd.cmake b/cmake/Findzstd.cmake index 2ce763d55..3c770a9e0 100644 --- a/cmake/Findzstd.cmake +++ b/cmake/Findzstd.cmake @@ -4,52 +4,64 @@ endif() set(zstd_FOUND FALSE) -if(NOT FORCE_INTERNET_ZSTD) +if(ZSTD_FROM_INTERNET AND NOT ZSTD_FROM_INTERNET STREQUAL "AUTO") + message(STATUS "Using zstd from the Internet") + set(do_download TRUE) +else() find_package(PkgConfig) if(PKG_CONFIG_FOUND) pkg_search_module(PC_ZSTD libzstd) find_library(ZSTD_LIBRARY zstd HINTS ${PC_ZSTD_LIBDIR} ${PC_ZSTD_LIBRARY_DIRS}) find_path(ZSTD_INCLUDE_DIR zstd.h HINTS ${PC_ZSTD_INCLUDEDIR} ${PC_ZSTD_INCLUDE_DIRS}) - else() + if(ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR) + message(STATUS "Using zstd from ${ZSTD_LIBRARY} via pkg-config") + set(zstd_FOUND TRUE) + endif() + endif() + + if(NOT zstd_FOUND) find_library(ZSTD_LIBRARY zstd) find_path(ZSTD_INCLUDE_DIR zstd.h) + if(ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR) + message(STATUS "Using zstd from ${ZSTD_LIBRARY}") + set(zstd_FOUND TRUE) + endif() endif() -endif() - -if(ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR) - mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY) - - add_library(ZSTD::ZSTD UNKNOWN IMPORTED) - set_target_properties( - ZSTD::ZSTD - PROPERTIES - IMPORTED_LOCATION "${ZSTD_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIR}") - set(zstd_FOUND TRUE) -elseif(ZSTD_FROM_INTERNET) - message(STATUS "*** WARNING ***: Using zstd from the internet because it was NOT found and ZSTD_FROM_INTERNET is TRUE") + if(zstd_FOUND) + mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY) + add_library(ZSTD::ZSTD UNKNOWN IMPORTED) + set_target_properties( + ZSTD::ZSTD + PROPERTIES + IMPORTED_LOCATION "${ZSTD_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIR}" + ) + set(zstd_FOUND TRUE) + elseif(ZSTD_FROM_INTERNET STREQUAL "AUTO") + message(STATUS "*** WARNING ***: Using zstd from the Internet because it was not found and ZSTD_FROM_INTERNET is AUTO") + set(do_download TRUE) + endif() +endif() +if(do_download) # Although ${zstd_FIND_VERSION} was requested, let's download a newer version. # Note: The directory structure has changed in 1.3.0; we only support 1.3.0 # and newer. set(zstd_version "1.5.2") - set(zstd_dir ${CMAKE_BINARY_DIR}/zstd-${zstd_version}) set(zstd_build ${CMAKE_BINARY_DIR}/zstd-build) include(FetchContent) - FetchContent_Declare( zstd - URL https://github.com/facebook/zstd/archive/v${zstd_version}.tar.gz - URL_HASH SHA256=f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e - SOURCE_DIR ${zstd_dir} - BINARY_DIR ${zstd_build} + URL https://github.com/facebook/zstd/archive/v${zstd_version}.tar.gz + URL_HASH SHA256=f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e + SOURCE_DIR ${zstd_dir} + BINARY_DIR ${zstd_build} ) FetchContent_GetProperties(zstd) - if(NOT zstd_POPULATED) FetchContent_Populate(zstd) endif() @@ -72,4 +84,5 @@ set_package_properties( zstd PROPERTIES URL "https://facebook.github.io/zstd" - DESCRIPTION "Zstandard - Fast real-time compression algorithm") + DESCRIPTION "Zstandard - Fast real-time compression algorithm" +) diff --git a/doc/INSTALL.md b/doc/INSTALL.md index e07638743..920cb4de8 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -14,9 +14,9 @@ To build ccache you need: - [libzstd](http://www.zstd.net). If you don't have libzstd installed and can't or don't want to install it in a standard system location, it will be automatically downloaded, built and linked statically as part of the build - process. To disable this, pass `-DZSTD_FROM_INTERNET=OFF` to `cmake`. You can - also install zstd in a custom path and pass - `-DCMAKE_PREFIX_PATH=/some/custom/path` to `cmake`. + process. To disable this, pass `-DZSTD_FROM_INTERNET=OFF` to `cmake`, or pass + `-DZSTD_FROM_INTERNET=ON` to force downloading. You can also install zstd in a + custom path and pass `-DCMAKE_PREFIX_PATH=/some/custom/path` to `cmake`. To link libzstd statically (and you have a static libzstd available), pass `-DSTATIC_LINK=ON` to `cmake`. This is the default on Windows. Alternatively, @@ -28,8 +28,9 @@ Optional: you don't have libhiredis installed and can't or don't want to install it in a standard system location, it will be automatically downloaded, built and linked statically as part of the build process. To disable this, pass - `-DHIREDIS_FROM_INTERNET=OFF` to cmake. You can also install hiredis in a - custom path and pass `-DCMAKE_PREFIX_PATH=/some/custom/path` to `cmake`. + `-DHIREDIS_FROM_INTERNET=OFF` to `cmake`, or pass `-DHIREDIS_FROM_INTERNET=ON` + to force downloading.. You can also install hiredis in a custom path and pass + `-DCMAKE_PREFIX_PATH=/some/custom/path` to `cmake`. To link libhiredis statically (and you have a static libhiredis available), pass `-DSTATIC_LINK=ON` to `cmake`. This is the default on Windows.