diff --git a/CMakeLists.txt b/CMakeLists.txt index 213d03a3..e18ffc66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,16 @@ message(STATUS "Using CMake version ${CMAKE_VERSION}") option(MZ_COMPAT "Enables compatibility layer" ON) # Compression library options option(MZ_ZLIB "Enables ZLIB compression" ON) + +# Controls to select either zlib-ng or zlib +set(MZ_ZLIB_FLAVOR "auto" CACHE STRING "Select the preferred zlib flavor - auto searches for zlib-ng then zlib") +set(MZ_ZLIB_FLAVORS "auto" "zlib-ng" "zlib") +set_property(CACHE MZ_ZLIB_FLAVOR PROPERTY STRINGS ${MZ_ZLIB_FLAVORS}) + +if(NOT MZ_ZLIB_FLAVOR IN_LIST MZ_ZLIB_FLAVORS) + message(FATAL_ERROR "MZ_ZLIB_FLAVOR must be one of ${MZ_ZLIB_FLAVORS}") +endif() + option(MZ_BZIP2 "Enables BZIP2 compression" ON) option(MZ_LZMA "Enables LZMA & XZ compression" ON) option(MZ_ZSTD "Enables ZSTD compression" ON) @@ -173,17 +183,21 @@ endif() if(MZ_ZLIB) # Check if zlib is present if(NOT MZ_FORCE_FETCH_LIBS) - find_package(ZLIBNG QUIET) - find_package(ZLIB QUIET) + if (MZ_ZLIB_FLAVOR STREQUAL "zlib-ng" OR MZ_ZLIB_FLAVOR STREQUAL "auto") + find_package(ZLIB-NG QUIET) + endif() + if (MZ_ZLIB_FLAVOR STREQUAL "zlib" OR MZ_ZLIB_FLAVOR STREQUAL "auto") + find_package(ZLIB QUIET) + endif() set(ZLIB_VERSION ${ZLIB_VERSION_STRING}) endif() - if(ZLIBNG_FOUND AND NOT MZ_FORCE_FETCH_LIBS) - message(STATUS "Using ZLIBNG") + if(ZLIB-NG_FOUND AND NOT MZ_FORCE_FETCH_LIBS) + message(STATUS "Using ZLIB-NG") - list(APPEND MINIZIP_INC ${ZLIBNG_INCLUDE_DIRS}) - list(APPEND MINIZIP_LIB ${ZLIBNG_LIBRARIES}) - list(APPEND MINIZIP_LBD ${ZLIBNG_LIBRARY_DIRS}) + list(APPEND MINIZIP_INC ${ZLIB-NG_INCLUDE_DIRS}) + list(APPEND MINIZIP_LIB ${ZLIB-NG_LIBRARIES}) + list(APPEND MINIZIP_LBD ${ZLIB-NG_LIBRARY_DIRS}) set(PC_PRIVATE_DEPS "zlib-ng") set(ZLIB_COMPAT OFF) @@ -215,7 +229,7 @@ if(MZ_ZLIB) endif() if(EXISTS "${ZLIB_BINARY_DIR}/zlib-ng.h") - message(STATUS "ZLIB repository detected as ZLIBNG") + message(STATUS "ZLIB repository detected as ZLIB-NG") set(ZLIB_COMPAT OFF) else() set(ZLIB_COMPAT ON) @@ -231,8 +245,8 @@ if(MZ_ZLIB) if(ZLIB_COMPAT) list(APPEND MINIZIP_DEF -DZLIB_COMPAT) endif() - if(ZLIBNG_FOUND OR NOT ZLIB_COMPAT) - list(APPEND MINIZIP_DEP_PKG ZLIBNG) + if(ZLIB-NG_FOUND OR NOT ZLIB_COMPAT) + list(APPEND MINIZIP_DEP_PKG ZLIB-NG) elseif(ZLIB_FOUND) list(APPEND MINIZIP_DEP_PKG ZLIB) endif() diff --git a/README.md b/README.md index b0f6b16b..fbc895c3 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ cmake --build build |:--------------------|:---------------------------------------------------------------|:-------------:| | MZ_COMPAT | Enables compatibility layer | ON | | MZ_ZLIB | Enables ZLIB compression | ON | +| MZ_ZLIB_FLAVOR | Select ZLIB implementation (auto, zlib-ng, zlib) | auto | | MZ_BZIP2 | Enables BZIP2 compression | ON | | MZ_LZMA | Enables LZMA & XZ compression | ON | | MZ_ZSTD | Enables ZSTD compression | ON | diff --git a/cmake/FindZLIB-NG.cmake b/cmake/FindZLIB-NG.cmake new file mode 100644 index 00000000..fd5d924e --- /dev/null +++ b/cmake/FindZLIB-NG.cmake @@ -0,0 +1,32 @@ +find_path(ZLIB-NG_INCLUDE_DIRS NAMES zlib-ng.h) + +if(ZLIB_INCLUDE_DIRS) + set(ZLIB-NG_LIBRARY_DIRS ${ZLIB-NG_INCLUDE_DIRS}) + + if("${ZLIB-NG_LIBRARY_DIRS}" MATCHES "/include$") + # Strip off the trailing "/include" in the path. + get_filename_component(ZLIB-NG_LIBRARY_DIRS ${ZLIB-NG_LIBRARY_DIRS} PATH) + endif() + + if(EXISTS "${ZLIB-NG_LIBRARY_DIRS}/lib") + set(ZLIB-NG_LIBRARY_DIRS ${ZLIB-NG_LIBRARY_DIRS}/lib) + endif() +endif() + +find_library(ZLIB-NG_LIBRARY NAMES z-ng libz-ng libz-ng.a) + +set(ZLIB-NG_LIBRARIES ${ZLIB-NG_LIBRARY}) +set(ZLIB-NG_INCLUDE_DIRS ${ZLIB-NG_INCLUDE_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ZLIB-NG DEFAULT_MSG ZLIB-NG_LIBRARY ZLIB-NG_INCLUDE_DIRS) + +if(ZLIB-NG_INCLUDE_DIRS AND ZLIB-NG_LIBRARIES) + set(ZLIB-NG_FOUND ON) +else(ZLIB-NG_INCLUDE_DIRS AND ZLIB-NG_LIBRARIES) + set(ZLIB-NG_FOUND OFF) +endif() + +if(ZLIB-NG_FOUND) + message(STATUS "Found zlib-ng: ${ZLIB-NG_LIBRARIES}, ${ZLIB-NG_INCLUDE_DIRS}") +endif() diff --git a/cmake/FindZLIBNG.cmake b/cmake/FindZLIBNG.cmake deleted file mode 100644 index 5da91ec0..00000000 --- a/cmake/FindZLIBNG.cmake +++ /dev/null @@ -1,32 +0,0 @@ -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() - - if(EXISTS "${ZLIBNG_LIBRARY_DIRS}/lib") - set(ZLIBNG_LIBRARY_DIRS ${ZLIBNG_LIBRARY_DIRS}/lib) - endif() -endif() - -find_library(ZLIBNG_LIBRARY NAMES z-ng libz-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 ON) -else(ZLIBNG_INCLUDE_DIRS AND ZLIBNG_LIBRARIES) - set(ZLIBNG_FOUND OFF) -endif() - -if(ZLIBNG_FOUND) - message(STATUS "Found zlib-ng: ${ZLIBNG_LIBRARIES}, ${ZLIBNG_INCLUDE_DIRS}") -endif()