From d5bca9eb23fa9b69294f458a2df201834da1ae96 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sat, 25 Sep 2021 16:16:46 -0400 Subject: [PATCH] Add patches to find zlibng correctly --- CMakeLists.txt | 35 +++++++++++---------------- bench/CMakeLists.txt | 8 +++---- blosc/CMakeLists.txt | 22 ++++++++--------- blosc/blosc2.c | 23 ++++++++++++++---- blosc/config.h.in | 2 +- cmake/FindZLIBNG.cmake | 54 ++++++++++++++++++++++++++++++++++++++++++ compat/CMakeLists.txt | 10 +++++--- tests/Makefile | 12 +++++----- 8 files changed, 116 insertions(+), 50 deletions(-) create mode 100644 cmake/FindZLIBNG.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d0f000558..2daa2bd9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,14 +21,14 @@ # build a lite version (only with BloscLZ and LZ4/LZ4HC) of the blosc library # DEACTIVATE_AVX2: default OFF # do not attempt to build with AVX2 instructions -# DEACTIVATE_ZLIB: default OFF +# DEACTIVATE_ZLIBNG: default OFF # do not include support for the Zlib library # DEACTIVATE_ZSTD: default OFF # do not include support for the Zstd library # PREFER_EXTERNAL_LZ4: default OFF # when found, use the installed LZ4 libs instead of included # sources -# PREFER_EXTERNAL_ZLIB: default OFF +# PREFER_EXTERNAL_ZLIBNG: default OFF # when found, use the installed ZLIB libs instead of included # MINIZ sources # PREFER_EXTERNAL_ZSTD: default OFF @@ -107,16 +107,16 @@ option(BUILD_LITE "Build a lite version (only with BloscLZ and LZ4/LZ4HC) of the blosc library." OFF) option(DEACTIVATE_AVX2 "Do not attempt to build with AVX2 instructions" OFF) -option(DEACTIVATE_ZLIB - "Do not include support for the ZLIB library." OFF) +option(DEACTIVATE_ZLIBNG + "Do not include support for the ZLIBNG library." OFF) option(DEACTIVATE_ZSTD "Do not include support for the ZSTD library." OFF) option(DEACTIVATE_IPP "Do not include support for the Intel IPP library." ON) option(PREFER_EXTERNAL_LZ4 "Find and use external LZ4 library instead of included sources." OFF) -option(PREFER_EXTERNAL_ZLIB - "Find and use external ZLIB library instead of included sources." OFF) +option(PREFER_EXTERNAL_ZLIBNG + "Find and use external ZLIBNG library instead of included sources." OFF) option(PREFER_EXTERNAL_ZSTD "Find and use external ZSTD library instead of included sources." OFF) @@ -139,7 +139,7 @@ if(BUILD_PLUGINS AND BUILD_LITE) endif() if(BUILD_LITE) - set(DEACTIVATE_ZLIB ON) + set(DEACTIVATE_ZLIBNG ON) set(DEACTIVATE_ZSTD ON) endif() @@ -149,23 +149,16 @@ else() message(STATUS "Using LZ4 internal sources.") endif() -if(NOT DEACTIVATE_ZLIB) - # import the ZLIB_ROOT environment variable to help finding the zlib library - if(PREFER_EXTERNAL_ZLIB) - set(ZLIB_ROOT $ENV{ZLIB_ROOT}) - find_package(ZLIB) - if(NOT ZLIB_FOUND) +if(NOT DEACTIVATE_ZLIBNG) + # import the ZLIBNG_ROOT environment variable to help finding the zlib library + if(PREFER_EXTERNAL_ZLIBNG) + set(ZLIBNG_ROOT $ENV{ZLIBNG_ROOT}) + find_package(ZLIBNG) + if(NOT ZLIBNG_FOUND) message(STATUS "No ZLIB found. Using ZLIB-NG internal sources.") - set(HAVE_ZLIB_NG TRUE) endif() - else() - message(STATUS "Using ZLIB-NG internal sources for ZLIB support.") - set(HAVE_ZLIB_NG TRUE) + set(HAVE_ZLIBNG TRUE) endif() - # HAVE_ZLIB will be set to true because even if the library is not found, - # we will use the included sources for it - set(HAVE_ZLIB TRUE) -endif() if(HAVE_ZLIB_NG) set(ZLIB_NG_DIR "zlib-ng-2.0.6") # update to the actual included version diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 3d72c0555..11efd83e3 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -51,7 +51,7 @@ if(BUILD_TESTS) add_test(test_blosclz_shuffle_1 ${BENCH_EXE} blosclz ${SHUFFLE_1_OPTS}) add_test(test_lz4_shuffle_1 ${BENCH_EXE} lz4 ${SHUFFLE_1_OPTS}) # add_test(test_lz4hc_shuffle_1 ${BENCH_EXE} lz4hc ${SHUFFLE_1_OPTS}) - if(HAVE_ZLIB) + if(HAVE_ZLIBNG) # add_test(test_zlib_shuffle_1 ${BENCH_EXE} zlib ${SHUFFLE_1_OPTS}) endif() if(HAVE_ZSTD) @@ -65,7 +65,7 @@ if(BUILD_TESTS) add_test(test_blosclz_shuffle_n ${BENCH_EXE} blosclz ${SHUFFLE_N_OPTS}) add_test(test_lz4_shuffle_n ${BENCH_EXE} lz4 ${SHUFFLE_N_OPTS}) add_test(test_lz4hc_shuffle_n ${BENCH_EXE} lz4hc ${SHUFFLE_N_OPTS}) - if(HAVE_ZLIB) + if(HAVE_ZLIBNG) add_test(test_zlib_shuffle_n ${BENCH_EXE} zlib ${SHUFFLE_N_OPTS}) endif() if(HAVE_ZSTD) @@ -79,7 +79,7 @@ if(BUILD_TESTS) add_test(test_blosclz_bitshuffle_1 ${BENCH_EXE} blosclz ${BITSHUFFLE_1_OPTS}) add_test(test_lz4_bitshuffle_1 ${BENCH_EXE} lz4 ${BITSHUFFLE_1_OPTS}) # add_test(test_lz4hc_bitshuffle_1 ${BENCH_EXE} lz4hc ${BITSHUFFLE_1_OPTS}) - if(HAVE_ZLIB) + if(HAVE_ZLIBNG) # add_test(test_zlib_bitshuffle_1 ${BENCH_EXE} zlib ${BITSHUFFLE_1_OPTS}) endif() if(HAVE_ZSTD) @@ -93,7 +93,7 @@ if(BUILD_TESTS) add_test(test_blosclz_bitshuffle_n ${BENCH_EXE} blosclz ${BITSHUFFLE_N_OPTS}) add_test(test_lz4_bitshuffle_n ${BENCH_EXE} lz4 ${BITSHUFFLE_N_OPTS}) # add_test(test_lz4hc_bitshuffle_n ${BENCH_EXE} lz4hc ${BITSHUFFLE_N_OPTS}) - if(HAVE_ZLIB) + if(HAVE_ZLIBNG) # add_test(test_zlib_bitshuffle_n ${BENCH_EXE} zlib ${BITSHUFFLE_N_OPTS}) endif() if(HAVE_ZSTD) diff --git a/blosc/CMakeLists.txt b/blosc/CMakeLists.txt index d276b604c..7cee6c391 100644 --- a/blosc/CMakeLists.txt +++ b/blosc/CMakeLists.txt @@ -18,11 +18,11 @@ else() endif() if(NOT DEACTIVATE_ZLIB) - if(ZLIB_FOUND) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR}) + if(ZLIBNG_FOUND) + set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIBNG_INCLUDE_DIR}) else() - set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIB_NG_DIR}) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_LOCAL_DIR}) + set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIBNG_DIR}) + set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIBNG_LOCAL_DIR}) endif() endif() @@ -96,14 +96,14 @@ else() source_group("LZ4" FILES ${LZ4_FILES}) endif() -if(NOT DEACTIVATE_ZLIB) - if(ZLIB_FOUND) - set(LIBS ${LIBS} ${ZLIB_LIBRARY}) +if(NOT DEACTIVATE_ZLIBNG) + if(ZLIBNG_FOUND) + set(LIBS ${LIBS} ${ZLIBNG_LIBRARY}) else() - set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIB_NG_DIR}) - file(GLOB ZLIB_FILES ${ZLIB_LOCAL_DIR}/*.c) - set(SOURCES ${SOURCES} ${ZLIB_FILES}) - source_group("Zlib" FILES ${ZLIB_FILES}) + set(ZLIBNG_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIBNG_DIR}) + file(GLOB ZLIBNG_FILES ${ZLIBNG_LOCAL_DIR}/*.c) + set(SOURCES ${SOURCES} ${ZLIBNG_FILES}) + source_group("Zlib-ng" FILES ${ZLIBNG_FILES}) endif() endif() diff --git a/blosc/blosc2.c b/blosc/blosc2.c index 0d0259dbf..a3992d3d1 100644 --- a/blosc/blosc2.c +++ b/blosc/blosc2.c @@ -42,8 +42,11 @@ #include #include #endif -#if defined(HAVE_ZLIB_NG) - #include "zlib.h" +#if defined(HAVE_ZLIBNG) + #include "zlib-ng.h" +#ifndef HAVE_ZLIB +#define HAVE_ZLIB +#endif #elif defined(HAVE_ZLIB) #include "zlib.h" #endif /* HAVE_MINIZ */ @@ -432,7 +435,11 @@ static int zlib_wrap_compress(const char* input, size_t input_length, char* output, size_t maxout, int clevel) { int status; uLongf cl = (uLongf)maxout; +#if defined(HAVE_ZLIBNG) + status = zng_compress2( +#else status = compress2( +#endif (Bytef*)output, &cl, (Bytef*)input, (uLong)input_length, clevel); if (status != Z_OK) { return 0; @@ -444,7 +451,11 @@ static int zlib_wrap_decompress(const char* input, size_t compressed_length, char* output, size_t maxout) { int status; uLongf ul = (uLongf)maxout; +#if defined(HAVE_ZLIBNG) + status = zng_uncompress( +#else status = uncompress( +#endif (Bytef*)output, &ul, (Bytef*)input, (uLong)compressed_length); if (status != Z_OK) { return 0; @@ -3346,11 +3357,15 @@ int blosc_get_complib_info(const char* compname, char** complib, char** version) LZ4_VERSION_MAJOR, LZ4_VERSION_MINOR, LZ4_VERSION_RELEASE); clibversion = sbuffer; } -#if defined(HAVE_ZLIB) +#if defined(HAVE_ZLIBNG) + else if (clibcode == BLOSC_ZLIB_LIB) { + clibversion = ZLIBNG_VERSION; + } +#elif defined(HAVE_ZLIB) else if (clibcode == BLOSC_ZLIB_LIB) { clibversion = ZLIB_VERSION; } -#endif /* HAVE_ZLIB */ +#endif /* HAVE_ZLIBNG or HAVE_ZLIB */ #if defined(HAVE_ZSTD) else if (clibcode == BLOSC_ZSTD_LIB) { sprintf(sbuffer, "%d.%d.%d", diff --git a/blosc/config.h.in b/blosc/config.h.in index 66cfd90b9..48727506b 100644 --- a/blosc/config.h.in +++ b/blosc/config.h.in @@ -2,7 +2,7 @@ #define _CONFIGURATION_HEADER_GUARD_H_ #cmakedefine HAVE_ZLIB @HAVE_ZLIB@ -#cmakedefine HAVE_ZLIB_NG @HAVE_ZLIB_NG@ +#cmakedefine HAVE_ZLIBNG @HAVE_ZLIBNG@ #cmakedefine HAVE_ZSTD @HAVE_ZSTD@ #cmakedefine HAVE_IPP @HAVE_IPP@ #cmakedefine BLOSC_DLL_EXPORT @DLL_EXPORT@ diff --git a/cmake/FindZLIBNG.cmake b/cmake/FindZLIBNG.cmake new file mode 100644 index 000000000..48e3345aa --- /dev/null +++ b/cmake/FindZLIBNG.cmake @@ -0,0 +1,54 @@ +find_path(ZLIBNG_INCLUDE_DIRS NAMES zlib-ng.h) + +if(ZLIB_INCLUDE_DIRS) + set(ZLIBNG_LIBRARY_DIRS ${ZLIBNG_INCLUDE_DIRS}) + + if("${ZLIBNG_LIBRARY_DIRS}" MATCHES "/include$") + # Strip off the trailing "/include" in the path. + GET_FILENAME_COMPONENT(ZLIBNG_LIBRARY_DIRS ${ZLIBNG_LIBRARY_DIRS} PATH) + endif("${ZLIBNG_LIBRARY_DIRS}" MATCHES "/include$") + + if(EXISTS "${ZLIBNG_LIBRARY_DIRS}/lib") + set(ZLIBNG_LIBRARY_DIRS ${ZLIBNG_LIBRARY_DIRS}/lib) + endif(EXISTS "${ZLIBNG_LIBRARY_DIRS}/lib") +endif() + +find_library(ZLIBNG_LIBRARY NAMES z-ng libz-ng zlib-ng libz-ng.a) + +set(ZLIBNG_LIBRARIES ${ZLIBNG_LIBRARY}) +set(ZLIBNG_INCLUDE_DIRS ${ZLIBNG_INCLUDE_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ZLIBNG DEFAULT_MSG ZLIBNG_LIBRARY ZLIBNG_INCLUDE_DIRS) + +if(ZLIBNG_INCLUDE_DIRS AND ZLIBNG_LIBRARIES) + set(ZLIBNG_FOUND TRUE) +else(ZLIBNG_INCLUDE_DIRS AND ZLIBNG_LIBRARIES) + set(ZLIBNG_FOUND FALSE) +endif(ZLIBNG_INCLUDE_DIRS AND ZLIBNG_LIBRARIES) + +if(ZLIBNG_FOUND) + message(STATUS "Found zlib-ng: ${ZLIBNG_LIBRARIES}, ${ZLIBNG_INCLUDE_DIRS}") +endif(ZLIBNG_FOUND) + +#[[ +Copyright https://github.com/zlib-ng/minizip-ng, 2021 + +Condition of use and distribution are the same as zlib: + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgement in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +]]# diff --git a/compat/CMakeLists.txt b/compat/CMakeLists.txt index f2a4a8202..e3e58bb0b 100644 --- a/compat/CMakeLists.txt +++ b/compat/CMakeLists.txt @@ -1,8 +1,12 @@ # build the filegen utility -link_directories(${PROJECT_BINARY_DIR}/blosc) add_executable(filegen filegen.c) -target_link_libraries(filegen blosc_testing) -add_dependencies(filegen blosc_testing) +if(BUILD_SHARED) + target_link_libraries(filegen blosc2_shared) +elseif(BUILD_STATIC) + target_link_libraries(filegen blosc2_static) +else() + set(BUILD_TESTS OFF FORCE) +endif() # tests if(BUILD_TESTS) diff --git a/tests/Makefile b/tests/Makefile index 7035ba121..e74ab3b2f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -16,13 +16,13 @@ BLOSC_LIB += $(wildcard $(LZ4_DIR)/*.c) # Support for external LZ4 and LZ4HC #LDFLAGS += -llz4 -# Support for external Zlib -LDFLAGS += -DHAVE_ZLIB -lz +# Support for external Zlib-ng +LDFLAGS += -DHAVE_ZLIBNG -lz-ng -# Support for internal Zlib -#ZLIB_DIR = ../internal-complibs/zlib-1.2.8 -#CFLAGS += -DHAVE_ZLIB -I$(ZLIB_DIR) -#BLOSC_LIB += $(wildcard $(ZLIB_DIR)/*.c) +# Support for internal Zlib-ng +#ZLIB_DIR = ../internal-complibs/zlib-ng-2.0.5 +#CFLAGS += -DHAVE_ZLIBNG -I$(ZLIBNG_DIR) +#BLOSC_LIB += $(wildcard $(ZLIBNG_DIR)/*.c) # Support for internal Zstd