]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Allow forcing download of zstd and hiredis again
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 27 Jan 2023 12:09:25 +0000 (13:09 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 29 Jan 2023 09:28:41 +0000 (10:28 +0100)
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.

.github/workflows/build.yaml
CMakeLists.txt
ci/build-macos-binary
cmake/Findhiredis.cmake
cmake/Findzstd.cmake
doc/INSTALL.md

index 363afdcbb4de92698d5a6b94124e1bab43a60917..197cd93f029669ba89ada6383ac7979c39e6c1d7 100644 (file)
@@ -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
index 06644f74fb09f3ea55c20b5ee1db1a1727ddd9a1..a929775ed9a796ddc5fa16c11e3922d3e1c62785 100644 (file)
@@ -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)
 
index 44381d30f1c3a1bbd0a939b9da67c14adf323557..403305c3d8220a0073733763354c5db850da91b8 100755 (executable)
@@ -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 ..
 }
index b8045f6f2cc31daed0a5b1539d2ed19cc13f2bf6..b52cb1d8f509882401fe50a2eb63e1cbec4fc366 100644 (file)
@@ -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(
index 2ce763d5588f410c739ab39e3034243b7b995eae..3c770a9e0fd191bc3f941748b38dc56dc2710a5c 100644 (file)
@@ -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"
+)
index e07638743e14dd639ac66d4ec8e3cba0ba129a27..920cb4de89f632c4d69ef3e1fe0e02671eece0c6 100644 (file)
@@ -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.