diff --git a/.gitmodules b/.gitmodules index dcbfa616..4d98a3b2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -17,3 +17,7 @@ url = https://github.com/xz-mirror/xz.git branch = master +[submodule "zlib"] + path = external/zlib + url = https://github.com/madler/zlib.git + branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index b54a8ae7..0abd3422 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ cmake_minimum_required(VERSION 3.18) option(BUILD_DEPENDENCIES "Build only libzip dependencies" OFF) option(BUILD_LIBZIP "Build libzip and libZipSharp" OFF) option(ENABLE_XZ "Enable XZ (LZMA compression) in the build" OFF) +option(ENABLE_ZLIBNG "Use zlib-ng instead of zlib" OFF) set(CMAKE_POSITION_INDEPENDENT_CODE True CACHE BOOL "Always build position independent code" FORCE) @@ -53,9 +54,11 @@ endif() # # zlib-ng # -set(ZLIB_COMPAT ON CACHE BOOL "Build zlib-ng for compatibility with zlib" FORCE) -set(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Do not build zlib-ng tests" FORCE) -set(WITH_NEW_STRATEGIES OFF CACHE BOOL "Disable faster, but with worse compression, deflate strategies" FORCE) +if(ENABLE_ZLIBNG) + set(ZLIB_COMPAT ON CACHE BOOL "Build zlib-ng for compatibility with zlib" FORCE) + set(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Do not build zlib-ng tests" FORCE) + set(WITH_NEW_STRATEGIES OFF CACHE BOOL "Disable faster, but with worse compression, deflate strategies" FORCE) +endif() # # Read product version @@ -289,7 +292,11 @@ endforeach() set(LZS_CXX_LINKER_FLAGS "${_CHECKED_FLAGS}") if(BUILD_DEPENDENCIES) - add_subdirectory(external/zlib-ng) + if(ENABLE_ZLIBNG) + add_subdirectory(external/zlib-ng) + else() + add_subdirectory(external/zlib) + endif() target_compile_options( zlib @@ -521,8 +528,14 @@ else() endif() else() if(WIN32) + if(ENABLE_ZLIBNG) + set(ZLIB_NAME "zlib.lib") + else() + set(ZLIB_NAME "zlibstatic.lib") + endif() + set(LIBS - ${ARTIFACTS_ROOT_DIR}/lib/zlib.lib + ${ARTIFACTS_ROOT_DIR}/lib/${ZLIB_NAME} ${ARTIFACTS_ROOT_DIR}/lib/bz2.lib ) diff --git a/LibZipSharp.props b/LibZipSharp.props index 58c72535..e404a301 100644 --- a/LibZipSharp.props +++ b/LibZipSharp.props @@ -1,6 +1,6 @@ - <_LibZipSharpNugetVersion>2.0.0-alpha5 + <_LibZipSharpNugetVersion>2.0.0-alpha6 <_NativeBuildDir>$(MSBuildThisFileDirectory)lzsbuild <_ExternalDir>$(MSBuildThisFileDirectory)external <_MonoPosixNugetVersion>7.0.0-alpha8.21302.6 diff --git a/build.sh b/build.sh index 1a28520a..763aae29 100755 --- a/build.sh +++ b/build.sh @@ -6,6 +6,7 @@ BUILD_DIR_ROOT="${MY_DIR}/lzsbuild" OS=$(uname -s) LZS_BUILD_DIR="${BUILD_DIR_ROOT}/lib/${OS}" DEPS_BASE_BUILD_DIR="${BUILD_DIR_ROOT}/deps/${OS}" +ZLIB_DIR="external/zlib" if [ "${OS}" == "Darwin" ]; then DEPS_BUILD_DIR="${DEPS_BASE_BUILD_DIR}/native" @@ -29,6 +30,7 @@ CONFIGURATION="RelWithDebInfo" REBUILD="no" VERBOSE="no" USE_XZ="no" +USE_ZLIBNG="no" # The color block is pilfered from the dotnet installer script # @@ -77,6 +79,7 @@ where OPTIONS are one or more of: -m|--cmake PATH use cmake at PATH instead of the default of '${CMAKE}' -x|--xz use the XZ library for LZMA support (default: ${USE_XZ}) + -g|--zlib-ng use the zlib-ng library instead of zlib (default: ${USE_ZLIBNG} -c|--configuration NAME build using configuration NAME instead of the default of '${CONFIGURATION}' -j|--jobs NUM run at most this many build jobs in parallel -v|--verbose make cmake and ninja verbose @@ -233,6 +236,8 @@ while (( "$#" )); do -x|--xz) USE_XZ="yes"; shift ;; + -g|--zlib-ng) USE_ZLIBNG="yes"; shift ;; + -v|--verbose) VERBOSE="yes"; shift ;; -r|--rebuild) REBUILD="yes"; shift ;; @@ -254,6 +259,14 @@ if [ -z "${NINJA}" ]; then die ninja binary must be specified fi +if [ "${USE_ZLIBNG}" == "no" ]; then + ZLIB_CMAKELISTS_PATH="${ZLIB_DIR}/CMakeLists.txt" + if ! $(grep 'lzs: disable-examples' "${ZLIB_CMAKELISTS_PATH}" > /dev/null 2>&1); then + print_banner Applying zlib patch + $(cd "${ZLIB_DIR}"; git apply "${MY_DIR}/zlib-changes.patch") + fi +fi + if [ "${REBUILD}" == "yes" ]; then rm -rf "${BUILD_DIR_ROOT}" rm -rf "${ARTIFACTS_DIR_ROOT}" diff --git a/external/zlib b/external/zlib new file mode 160000 index 00000000..cacf7f1d --- /dev/null +++ b/external/zlib @@ -0,0 +1 @@ +Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f diff --git a/native/version.cc b/native/version.cc index 05828383..7f1aad9f 100644 --- a/native/version.cc +++ b/native/version.cc @@ -11,7 +11,11 @@ constexpr char libzipsharp_version[] = LIBZIPSHARP_VERSION; constexpr char libzip_version[] = LIBZIP_VERSION; constexpr char libzlib_version[] = ZLIB_VERSION; +#if defined (ZLIBNG_VERSION) constexpr char libzlibng_version[] = ZLIBNG_VERSION; +#else +constexpr char libzlibng_version[] = "not used"; +#endif // ndef ZLIBNG_VERSION #if defined (HAVE_XZ) constexpr char lzma_version[] = LZMA_VERSION_STRING; #else diff --git a/zlib-changes.patch b/zlib-changes.patch new file mode 100644 index 00000000..37247eb0 --- /dev/null +++ b/zlib-changes.patch @@ -0,0 +1,18 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0fe939d..f3ad0ed 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -229,7 +229,7 @@ endif() + #============================================================================ + # Example binaries + #============================================================================ +- ++if(False) # lzs: disable-examples + add_executable(example test/example.c) + target_link_libraries(example zlib) + add_test(example example) +@@ -247,3 +247,4 @@ if(HAVE_OFF64_T) + target_link_libraries(minigzip64 zlib) + set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + endif() ++endif()