Files
scylladb/cmake/Findzstd.cmake
Michał Chojnowski 866326efe4 utils: add stream_compressor
Adds utilities for "advanced" methods of compression with lz4
and zstd -- with streaming (a history buffer persisted across messages)
and/or precomputed dictionaries.

This patch is mostly just glue needed to use the underlying
libraries with discontiguous input and output buffers, and for reusing the
same compressor context objects across messages. It doesn't contain
any innovations of its own.

There is one "design decision" in the patch. The block format of LZ4
doesn't contain the length of the compressed blocks. At decompression
time, that length must be delivered to the decompressor by a channel
separate to the compressed block itself. In `lz4_cstream`, we deal
with that by prepending a variable-length integer containing the
compressed size to each compressed block. This is suboptimal for
single-fragment messages, since the user of lz4_cstream is likely
going to remember the length of the whole message anyway,
which makes the length prepended to the block redundant.
But a loss of 1 byte is probably acceptable for most uses.
2024-12-23 23:28:12 +01:00

63 lines
1.3 KiB
CMake

#
# Copyright 2024-present ScyllaDB
#
#
# SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
#
find_package (PkgConfig REQUIRED)
pkg_search_module (PC_zstd QUIET libzstd)
find_library (zstd_STATIC_LIBRARY
NAMES libzstd.a
HINTS
${PC_zstd_STATIC_LIBDIR}
${PC_zstd_STATIC_LIBRARY_DIRS})
find_library (zstd_LIBRARY
NAMES zstd
HINTS
${PC_zstd_LIBDIR}
${PC_zstd_LIBRARY_DIRS})
find_path (zstd_INCLUDE_DIR
NAMES zstd.h
HINTS
${PC_zstd_STATIC_INCLUDEDIR}
${PC_zstd_STATIC_INCLUDE_DIRS})
mark_as_advanced (
zstd_STATIC_LIBRARY
zstd_LIBRARY
zstd_INCLUDE_DIR)
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (zstd
REQUIRED_VARS
zstd_STATIC_LIBRARY
zstd_LIBRARY
zstd_INCLUDE_DIR
VERSION_VAR PC_zstd_STATIC_VERSION)
if (zstd_FOUND)
if (NOT (TARGET zstd::zstd_static))
add_library (zstd::zstd_static UNKNOWN IMPORTED)
set_target_properties (zstd::zstd_static
PROPERTIES
IMPORTED_LOCATION ${zstd_STATIC_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${zstd_INCLUDE_DIR})
endif ()
if (NOT (TARGET zstd::libzstd))
add_library (zstd::libzstd UNKNOWN IMPORTED)
set_target_properties (zstd::libzstd
PROPERTIES
IMPORTED_LOCATION ${zstd_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${zstd_INCLUDE_DIR})
endif ()
endif ()