Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use option() here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the README be updated to include the new option?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, updating the readme for that is a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use option() here?

option is boolean - it could be framed as MZ_ZLIB_PREFER_ZLIB-NG or something like that.
Not sure if that's any better but i can do that if you provide the name 😅

With MZ_SANITIZER we already do it with a string "option".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the README be updated to include the new option?

Done

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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
32 changes: 32 additions & 0 deletions cmake/FindZLIB-NG.cmake
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 0 additions & 32 deletions cmake/FindZLIBNG.cmake

This file was deleted.