diff options
author | Alexander Lanin <alex@lanin.de> | 2020-06-14 09:59:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-14 09:59:00 +0200 |
commit | f2341b2ba3369d5641a53deb3f6b1d513a8924e2 (patch) | |
tree | 229095217e949396920dbe3b77712bef25587775 /cmake/Findzstd.cmake | |
parent | b1fcfbca224b2af5b6499794edd8615dbc3dc7b5 (diff) | |
download | ccache-f2341b2ba3369d5641a53deb3f6b1d513a8924e2.tar.gz |
Switch to CMake (#573)
Co-authored-by: Cristian Adam <cristian.adam@gmail.com>
Co-authored-by: Joel Rosdahl <joel@rosdahl.net>
Diffstat (limited to 'cmake/Findzstd.cmake')
-rw-r--r-- | cmake/Findzstd.cmake | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cmake/Findzstd.cmake b/cmake/Findzstd.cmake new file mode 100644 index 00000000..a0095090 --- /dev/null +++ b/cmake/Findzstd.cmake @@ -0,0 +1,52 @@ +if(zstd_FOUND) + return() +endif() + +if(USE_LIBZSTD_FROM_INTERNET) + # Although ${zstd_FIND_VERSION} was requested, let's download a newer version. + # Note: structure has changed in 1.3.0, download supports only 1.3.0 and + # newer. + set(zstd_version "1.4.4") + set(zstd_url https://github.com/facebook/zstd/archive/v${zstd_version}.tar.gz) + + set(zstd_dir ${CMAKE_BINARY_DIR}/zstd-${zstd_version}) + set(zstd_build ${CMAKE_BINARY_DIR}/zstd-build) + + if(NOT EXISTS "${zstd_dir}.tar.gz") + file(DOWNLOAD "${zstd_url}" "${zstd_dir}.tar.gz") + endif() + + execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${zstd_dir}.tar.gz" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}") + + set(ZSTD_BUILD_SHARED OFF) + add_subdirectory("${zstd_dir}/build/cmake" "${zstd_build}" EXCLUDE_FROM_ALL) + + add_library(ZSTD::ZSTD ALIAS libzstd_static) + set_target_properties(libzstd_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${zstd_dir}/lib") + + set(zstd_FOUND TRUE) +else() + find_library(ZSTD_LIBRARY zstd) + find_path(ZSTD_INCLUDE_DIR zstd.h) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + zstd "please install libzstd or use -DUSE_LIBZSTD_FROM_INTERNET=ON" + ZSTD_INCLUDE_DIR ZSTD_LIBRARY) + 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}") +endif() + +include(FeatureSummary) +# cmake-format: off +# (behaviour change in cmake-format 0.6.10) +set_package_properties( + zstd PROPERTIES URL "https://facebook.github.io/zstd" + DESCRIPTION "Zstandard - Fast real-time compression algorithm") +# cmake-format: on |