diff --git a/.cmake-format.yaml b/.cmake-format.yaml
new file mode 100644
index 000000000..9c554da15
--- /dev/null
+++ b/.cmake-format.yaml
@@ -0,0 +1,245 @@
+_help_parse: Options affecting listfile parsing
+parse:
+  _help_additional_commands:
+  - Specify structure for custom cmake functions
+  additional_commands:
+    foo:
+      flags:
+      - BAR
+      - BAZ
+      kwargs:
+        HEADERS: '*'
+        SOURCES: '*'
+        DEPENDS: '*'
+  _help_override_spec:
+  - Override configurations per-command where available
+  override_spec: {}
+  _help_vartags:
+  - Specify variable tags.
+  vartags: []
+  _help_proptags:
+  - Specify property tags.
+  proptags: []
+_help_format: Options affecting formatting.
+format:
+  _help_disable:
+  - Disable formatting entirely, making cmake-format a no-op
+  disable: false
+  _help_line_width:
+  - How wide to allow formatted cmake files
+  line_width: 80
+  _help_tab_size:
+  - How many spaces to tab for indent
+  tab_size: 4
+  _help_use_tabchars:
+  - If true, lines are indented using tab characters (utf-8
+  - 0x09) instead of <tab_size> space characters (utf-8 0x20).
+  - In cases where the layout would require a fractional tab
+  - character, the behavior of the  fractional indentation is
+  - governed by <fractional_tab_policy>
+  use_tabchars: false
+  _help_fractional_tab_policy:
+  - If <use_tabchars> is True, then the value of this variable
+  - indicates how fractional indentions are handled during
+  - whitespace replacement. If set to 'use-space', fractional
+  - indentation is left as spaces (utf-8 0x20). If set to
+  - '`round-up` fractional indentation is replaced with a single'
+  - tab character (utf-8 0x09) effectively shifting the column
+  - to the next tabstop
+  fractional_tab_policy: use-space
+  _help_max_subgroups_hwrap:
+  - If an argument group contains more than this many sub-groups
+  - (parg or kwarg groups) then force it to a vertical layout.
+  max_subgroups_hwrap: 2
+  _help_max_pargs_hwrap:
+  - If a positional argument group contains more than this many
+  - arguments, then force it to a vertical layout.
+  max_pargs_hwrap: 6
+  _help_max_rows_cmdline:
+  - If a cmdline positional group consumes more than this many
+  - lines without nesting, then invalidate the layout (and nest)
+  max_rows_cmdline: 2
+  _help_separate_ctrl_name_with_space:
+  - If true, separate flow control names from their parentheses
+  - with a space
+  separate_ctrl_name_with_space: false
+  _help_separate_fn_name_with_space:
+  - If true, separate function names from parentheses with a
+  - space
+  separate_fn_name_with_space: false
+  _help_dangle_parens:
+  - If a statement is wrapped to more than one line, than dangle
+  - the closing parenthesis on its own line.
+  dangle_parens: false
+  _help_dangle_align:
+  - If the trailing parenthesis must be 'dangled' on its on
+  - 'line, then align it to this reference: `prefix`: the start'
+  - 'of the statement,  `prefix-indent`: the start of the'
+  - 'statement, plus one indentation  level, `child`: align to'
+  - the column of the arguments
+  dangle_align: prefix
+  _help_min_prefix_chars:
+  - If the statement spelling length (including space and
+  - parenthesis) is smaller than this amount, then force reject
+  - nested layouts.
+  min_prefix_chars: 4
+  _help_max_prefix_chars:
+  - If the statement spelling length (including space and
+  - parenthesis) is larger than the tab width by more than this
+  - amount, then force reject un-nested layouts.
+  max_prefix_chars: 10
+  _help_max_lines_hwrap:
+  - If a candidate layout is wrapped horizontally but it exceeds
+  - this many lines, then reject the layout.
+  max_lines_hwrap: 2
+  _help_line_ending:
+  - What style line endings to use in the output.
+  line_ending: unix
+  _help_command_case:
+  - Format command names consistently as 'lower' or 'upper' case
+  command_case: canonical
+  _help_keyword_case:
+  - Format keywords consistently as 'lower' or 'upper' case
+  keyword_case: unchanged
+  _help_always_wrap:
+  - A list of command names which should always be wrapped
+  always_wrap: []
+  _help_enable_sort:
+  - If true, the argument lists which are known to be sortable
+  - will be sorted lexicographicall
+  enable_sort: true
+  _help_autosort:
+  - If true, the parsers may infer whether or not an argument
+  - list is sortable (without annotation).
+  autosort: false
+  _help_require_valid_layout:
+  - By default, if cmake-format cannot successfully fit
+  - everything into the desired linewidth it will apply the
+  - last, most aggressive attempt that it made. If this flag is
+  - True, however, cmake-format will print error, exit with non-
+  - zero status code, and write-out nothing
+  require_valid_layout: false
+  _help_layout_passes:
+  - A dictionary mapping layout nodes to a list of wrap
+  - decisions. See the documentation for more information.
+  layout_passes: {}
+_help_markup: Options affecting comment reflow and formatting.
+markup:
+  _help_bullet_char:
+  - What character to use for bulleted lists
+  bullet_char: '*'
+  _help_enum_char:
+  - What character to use as punctuation after numerals in an
+  - enumerated list
+  enum_char: .
+  _help_first_comment_is_literal:
+  - If comment markup is enabled, don't reflow the first comment
+  - block in each listfile. Use this to preserve formatting of
+  - your copyright/license statements.
+  first_comment_is_literal: false
+  _help_literal_comment_pattern:
+  - If comment markup is enabled, don't reflow any comment block
+  - which matches this (regex) pattern. Default is `None`
+  - (disabled).
+  literal_comment_pattern: null
+  _help_fence_pattern:
+  - Regular expression to match preformat fences in comments
+  - default= ``r'^\s*([`~]{3}[`~]*)(.*)$'``
+  fence_pattern: ^\s*([`~]{3}[`~]*)(.*)$
+  _help_ruler_pattern:
+  - Regular expression to match rulers in comments default=
+  - '``r''^\s*[^\w\s]{3}.*[^\w\s]{3}$''``'
+  ruler_pattern: ^\s*[^\w\s]{3}.*[^\w\s]{3}$
+  _help_explicit_trailing_pattern:
+  - If a comment line matches starts with this pattern then it
+  - is explicitly a trailing comment for the preceding argument.
+  - Default is '#<'
+  explicit_trailing_pattern: '#<'
+  _help_hashruler_min_length:
+  - If a comment line starts with at least this many consecutive
+  - hash characters, then don't lstrip() them off. This allows
+  - for lazy hash rulers where the first hash char is not
+  - separated by space
+  hashruler_min_length: 10
+  _help_canonicalize_hashrulers:
+  - If true, then insert a space between the first hash char and
+  - remaining hash chars in a hash ruler, and normalize its
+  - length to fill the column
+  canonicalize_hashrulers: true
+  _help_enable_markup:
+  - enable comment markup parsing and reflow
+  enable_markup: true
+_help_lint: Options affecting the linter
+lint:
+  _help_disabled_codes:
+  - a list of lint codes to disable
+  disabled_codes: []
+  _help_function_pattern:
+  - regular expression pattern describing valid function names
+  function_pattern: '[0-9a-z_]+'
+  _help_macro_pattern:
+  - regular expression pattern describing valid macro names
+  macro_pattern: '[0-9A-Z_]+'
+  _help_global_var_pattern:
+  - regular expression pattern describing valid names for
+  - variables with global (cache) scope
+  global_var_pattern: '[A-Z][0-9A-Z_]+'
+  _help_internal_var_pattern:
+  - regular expression pattern describing valid names for
+  - variables with global scope (but internal semantic)
+  internal_var_pattern: _[A-Z][0-9A-Z_]+
+  _help_local_var_pattern:
+  - regular expression pattern describing valid names for
+  - variables with local scope
+  local_var_pattern: '[a-z][a-z0-9_]+'
+  _help_private_var_pattern:
+  - regular expression pattern describing valid names for
+  - privatedirectory variables
+  private_var_pattern: _[0-9a-z_]+
+  _help_public_var_pattern:
+  - regular expression pattern describing valid names for public
+  - directory variables
+  public_var_pattern: '[A-Z][0-9A-Z_]+'
+  _help_argument_var_pattern:
+  - regular expression pattern describing valid names for
+  - function/macro arguments and loop variables.
+  argument_var_pattern: '[a-z][a-z0-9_]+'
+  _help_keyword_pattern:
+  - regular expression pattern describing valid names for
+  - keywords used in functions or macros
+  keyword_pattern: '[A-Z][0-9A-Z_]+'
+  _help_max_conditionals_custom_parser:
+  - In the heuristic for C0201, how many conditionals to match
+  - within a loop in before considering the loop a parser.
+  max_conditionals_custom_parser: 2
+  _help_min_statement_spacing:
+  - Require at least this many newlines between statements
+  min_statement_spacing: 1
+  _help_max_statement_spacing:
+  - Require no more than this many newlines between statements
+  max_statement_spacing: 2
+  max_returns: 6
+  max_branches: 12
+  max_arguments: 5
+  max_localvars: 15
+  max_statements: 50
+_help_encode: Options affecting file encoding
+encode:
+  _help_emit_byteorder_mark:
+  - If true, emit the unicode byte-order mark (BOM) at the start
+  - of the file
+  emit_byteorder_mark: false
+  _help_input_encoding:
+  - Specify the encoding of the input file. Defaults to utf-8
+  input_encoding: utf-8
+  _help_output_encoding:
+  - Specify the encoding of the output file. Defaults to utf-8.
+  - Note that cmake only claims to support utf-8 so be careful
+  - when using anything else
+  output_encoding: utf-8
+_help_misc: Miscellaneous configurations options.
+misc:
+  _help_per_command:
+  - A dictionary containing any per-command configuration
+  - overrides. Currently only `command_case` is supported.
+  per_command: {}
diff --git a/.github/workflows/c-std.yml b/.github/workflows/c-std.yml
index 44417bfad..a99cdb569 100644
--- a/.github/workflows/c-std.yml
+++ b/.github/workflows/c-std.yml
@@ -133,18 +133,30 @@ jobs:
     - name: Generate project files (cmake)
       if: matrix.builder == 'cmake'
       run: |
-        cmake -S . -B . -D CMAKE_BUILD_TYPE=Release -D ZLIB_BUILD_EXAMPLES=OFF  ${{ matrix.os.cmake-opt }}
+        cmake -S . -B ./build1 -D CMAKE_BUILD_TYPE=Release ${{ matrix.os.cmake-opt }} -DZLIB_BUILD_TESTING=OFF
       env:
         CC: ${{ matrix.compiler }}
         CFLAGS: -std=${{ matrix.std.value }} ${{ matrix.arch.compiler-opt }} -Werror -Wall -Wextra
 
+    - name: Generate project files with tests (cmake)
+      if: matrix.builder == 'cmake'
+      run: |
+        cmake -S . -B ./build2 -D CMAKE_BUILD_TYPE=Release ${{ matrix.os.cmake-opt }} -DZLIB_BUILD_MINIZIP=ON -DMINIZIP_ENABLE_BZIP2=OFF
+      env:
+        CC: ${{ matrix.compiler }}
+        CFLAGS: -std=${{ matrix.std.value }} ${{ matrix.arch.compiler-opt }} -Wall -Wextra
+
     - name: Compile source code (cmake)
       if: matrix.builder == 'cmake'
-      run: cmake --build . --config Release
+      run: cmake --build ./build1 --config Release
+
+    - name: Compile source code with tests (cmake)
+      if: matrix.builder == 'cmake'
+      run: cmake --build ./build2 --config Release
 
     - name: Run test cases (cmake)
       if: matrix.builder == 'cmake'
-      run: ctest -C Release --output-on-failure --max-width 120
+      run: ctest ./build2 -C Release --output-on-failure --max-width 120
 
 
   msvc:
@@ -196,13 +208,23 @@ jobs:
 
     - name: Generate project files (cmake)
       run: |
-        cmake -S . -B . ${{ matrix.arch.value }} -D CMAKE_BUILD_TYPE=Release
+        cmake -S . -B ./build1 ${{ matrix.arch.value }} -D CMAKE_BUILD_TYPE=Release -DZLIB_BUILD_TESTING=OFF
       env:
         CC: ${{ matrix.compiler }}
         CFLAGS: /WX ${{ matrix.std.value }}
 
+    - name: Generate project files with tests (cmake)
+      run: |
+        cmake -S . -B ./build2 ${{ matrix.arch.value }} -D CMAKE_BUILD_TYPE=Release -DZLIB_BUILD_MINIZIP=ON -DMINIZIP_ENABLE_BZIP2=OFF
+      env:
+        CC: ${{ matrix.compiler }}
+        CFLAGS: ${{ matrix.std.value }}
+
     - name: Compile source code (cmake)
-      run: cmake --build . --config Release -v
+      run: cmake --build ./build1 --config Release -v
+
+    - name: Compile source code with tests(cmake)
+      run: cmake --build ./build2 --config Release -v
 
     - name: Run test cases (cmake)
-      run: ctest -C Release --output-on-failure --max-width 120
\ No newline at end of file
+      run: ctest ./build2 -C Release --output-on-failure --max-width 120
diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml
index 36fb2493d..25a3b8124 100644
--- a/.github/workflows/cmake.yml
+++ b/.github/workflows/cmake.yml
@@ -11,59 +11,66 @@ jobs:
           - name: Ubuntu GCC
             os: ubuntu-latest
             compiler: gcc
-            cflags: -Werror -Wall -Wextra
-
-          # Test out of source builds
-          - name: Ubuntu GCC OSB
-            os: ubuntu-latest
-            compiler: gcc
-            cflags: -Werror -Wall -Wextra
-            build-dir: ../build
-            src-dir: ../zlib
+            cflags: -Wall -Wextra
+            pkgtgt: package package_source
+            cmake-args: -DMINIZIP_ENABLE_BZIP2=ON
 
           - name: Ubuntu GCC -O3
             os: ubuntu-latest
             compiler: gcc
-            cflags: -O3 -Werror -Wall -Wextra
+            cflags: -O3 -Wall -Wextra
+            pkgtgt: package package_source
+            cmake-args: -DMINIZIP_ENABLE_BZIP2=ON
 
           - name: Ubuntu Clang
             os: ubuntu-latest
             compiler: clang
-            cflags: -Werror -Wall -Wextra
+            cflags: -Wall -Wextra
+            pkgtgt: package package_source
+            cmake-args: -DMINIZIP_ENABLE_BZIP2=ON
 
           - name: Ubuntu Clang Debug
             os: ubuntu-latest
             compiler: clang
-            cflags: -Werror -Wall -Wextra
+            cflags: -Wall -Wextra
             build-config: Debug
+            pkgtgt: package package_source
+            cmake-args: -DMINIZIP_ENABLE_BZIP2=ON
 
           - name: Windows MSVC Win32
             os: windows-latest
             compiler: cl
-            cflags: /WX /W3
+            cflags: /W3
             cmake-args: -A Win32
+            pkgtgt: PACKAGE
 
           - name: Windows MSVC Win64
             os: windows-latest
             compiler: cl
-            cflags: /WX /W3
-            cmake-args: -A x64
+            cflags: /W3
+            cmake-args: -A x64 -DMINIZIP_ENABLE_BZIP2=OFF
+            pkgtgt: PACKAGE
 
           - name: Windows GCC
             os: windows-latest
             compiler: gcc
-            cflags: -Werror -Wall -Wextra
-            cmake-args: -G Ninja
+            cflags: -Wall -Wextra
+            cmake-args: -G Ninja -DMINIZIP_ENABLE_BZIP2=OFF
+            pkgtgt: package
 
           - name: macOS Clang
             os: macos-latest
             compiler: clang
-            cflags: -Werror -Wall -Wextra
+            cflags: -Wall -Wextra
+            pkgtgt: package
+            cmake-args: -DMINIZIP_ENABLE_BZIP2=ON
 
           - name: macOS GCC
             os: macos-latest
             compiler: gcc-12
-            cflags: -Werror -Wall -Wextra
+            cflags: -Wall -Wextra
+            pkgtgt: package
+            cmake-args: -DMINIZIP_ENABLE_BZIP2=ON
 
     steps:
     - name: Checkout repository
@@ -72,20 +79,27 @@ jobs:
     - name: Install packages (Windows)
       if: runner.os == 'Windows'
       run: |
-        choco install --no-progress ninja ${{ matrix.packages }}
+        choco install --no-progress ninja
 
+    - name: Install packages (Linux)
+      if: runner.os == 'Linux'
+      run: |
+        sudo apt install libbz2-dev
     - name: Generate project files
-      run: cmake -S ${{ matrix.src-dir || '.' }} -B ${{ matrix.build-dir || '.' }} ${{ matrix.cmake-args }} -D CMAKE_BUILD_TYPE=${{ matrix.build-config || 'Release' }}
+      run: cmake -S . -B ../build ${{ matrix.cmake-args }} -D CMAKE_BUILD_TYPE=${{ matrix.build-config || 'Release' }} -DZLIB_BUILD_MINIZIP=ON
       env:
         CC: ${{ matrix.compiler }}
         CFLAGS: ${{ matrix.cflags }}
 
     - name: Compile source code
-      run: cmake --build ${{ matrix.build-dir || '.' }} --config ${{ matrix.build-config || 'Release' }}
+      run: cmake --build ../build --config ${{ matrix.build-config || 'Release' }}
 
     - name: Run test cases
       run: ctest -C Release --output-on-failure --max-width 120
-      working-directory: ${{ matrix.build-dir || '.' }}
+      working-directory: ../build
+
+    - name: create packages
+      run: cmake --build ../build --config ${{ matrix.build-config || 'Release' }} -t ${{ matrix.pkgtgt }}
 
     - name: Upload build errors
       uses: actions/upload-artifact@v4
@@ -93,6 +107,6 @@ jobs:
       with:
         name: ${{ matrix.name }} (cmake)
         path: |
-          **/CMakeFiles/CMakeOutput.log
-          **/CMakeFiles/CMakeError.log
+          ../build/CMakeFiles/CMakeOutput.log
+          ../build/CMakeFiles/CMakeError.log
         retention-days: 7
diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml
index 7789095e2..f19272c72 100644
--- a/.github/workflows/configure.yml
+++ b/.github/workflows/configure.yml
@@ -26,7 +26,7 @@ jobs:
             compiler: arm-linux-gnueabi-gcc
             configure-args: --warn
             chost: arm-linux-gnueabi
-            packages: qemu qemu-user gcc-arm-linux-gnueabi libc-dev-armel-cross
+            packages: qemu-system qemu-user gcc-arm-linux-gnueabi libc-dev-armel-cross
             qemu-run: qemu-arm -L /usr/arm-linux-gnueabi
 
           - name: Ubuntu GCC ARM HF
@@ -34,7 +34,7 @@ jobs:
             compiler: arm-linux-gnueabihf-gcc
             configure-args: --warn
             chost: arm-linux-gnueabihf
-            packages: qemu qemu-user gcc-arm-linux-gnueabihf libc-dev-armhf-cross
+            packages: qemu-system qemu-user gcc-arm-linux-gnueabihf libc-dev-armhf-cross
             qemu-run: qemu-arm -L /usr/arm-linux-gnueabihf
 
           - name: Ubuntu GCC AARCH64
@@ -42,7 +42,7 @@ jobs:
             compiler: aarch64-linux-gnu-gcc
             configure-args: --warn
             chost: aarch64-linux-gnu
-            packages: qemu qemu-user gcc-aarch64-linux-gnu libc-dev-arm64-cross
+            packages: qemu-system qemu-user gcc-aarch64-linux-gnu libc-dev-arm64-cross
             qemu-run: qemu-aarch64 -L /usr/aarch64-linux-gnu
 
           - name: Ubuntu GCC PPC
@@ -50,7 +50,7 @@ jobs:
             compiler: powerpc-linux-gnu-gcc
             configure-args: --warn --static
             chost: powerpc-linux-gnu
-            packages: qemu qemu-user gcc-powerpc-linux-gnu libc-dev-powerpc-cross
+            packages: qemu-system qemu-user gcc-powerpc-linux-gnu libc-dev-powerpc-cross
             qemu-run: qemu-ppc -L /usr/powerpc-linux-gnu
             cflags: -static
             ldflags: -static
@@ -60,7 +60,7 @@ jobs:
             compiler: powerpc64-linux-gnu-gcc
             configure-args: --warn --static
             chost: powerpc-linux-gnu
-            packages: qemu qemu-user gcc-powerpc64-linux-gnu libc-dev-ppc64-cross
+            packages: qemu-system qemu-user gcc-powerpc64-linux-gnu libc-dev-ppc64-cross
             qemu-run: qemu-ppc64 -L /usr/powerpc64-linux-gnu
             cflags: -static
             ldflags: -static
@@ -70,7 +70,7 @@ jobs:
             compiler: powerpc64le-linux-gnu-gcc
             configure-args: --warn
             chost: powerpc64le-linux-gnu
-            packages: qemu qemu-user gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross
+            packages: qemu-system qemu-user gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross
             qemu-run: qemu-ppc64le -L /usr/powerpc64le-linux-gnu
 
           - name: Ubuntu GCC S390X
@@ -78,7 +78,7 @@ jobs:
             compiler: s390x-linux-gnu-gcc
             configure-args: --warn --static
             chost: s390x-linux-gnu
-            packages: qemu qemu-user gcc-s390x-linux-gnu libc-dev-s390x-cross
+            packages: qemu-system qemu-user gcc-s390x-linux-gnu libc-dev-s390x-cross
             qemu-run: qemu-s390x -L /usr/s390x-linux-gnu
             cflags: -static
             ldflags: -static
@@ -110,7 +110,7 @@ jobs:
         ${{ matrix.src-dir || '.' }}/configure ${{ matrix.configure-args }}
       env:
         CC: ${{ matrix.compiler }}
-        CFLAGS: ${{ matrix.cflags }} -Werror
+        CFLAGS: ${{ matrix.cflags }}
         LDFLAGS: ${{ matrix.ldflags }}
         CHOST: ${{ matrix.chost }}
 
diff --git a/.github/workflows/msys-cygwin.yml b/.github/workflows/msys-cygwin.yml
new file mode 100644
index 000000000..e76be9f0d
--- /dev/null
+++ b/.github/workflows/msys-cygwin.yml
@@ -0,0 +1,77 @@
+name: mingw/cygwin
+
+on: [push, pull_request]
+
+jobs:
+  MSys:
+    runs-on: windows-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        sys: [mingw32, mingw64, ucrt64, clang64]
+    name: MSys - ${{ matrix.sys }}
+    defaults:
+      run:
+        shell: msys2 {0}
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v4
+      with:
+        fetch-depth: 0
+    - name: Setup MSYS2
+      uses: msys2/setup-msys2@v2
+      with:
+        msystem: ${{ matrix.sys }}
+        update: true
+        install: >-
+          make
+        pacboy: >-
+          toolchain:p
+          cmake:p
+    - name: Configure
+      run: |
+        cmake -G"Unix Makefiles" \
+          -S . \
+          -B build \
+          -DCMAKE_VERBOSE_MAKEFILE=ON \
+          -DCMAKE_BUILD_TYPE=Release \
+          -DMINIZIP_ENABLE_BZIP2=ON
+    - name: Build
+      run: cmake --build build --config Release
+    - name: Run tests
+      run: ctest --output-on-failure --test-dir build -C Release
+
+  cygwin:
+    strategy:
+      fail-fast: false
+    runs-on: windows-latest
+    defaults:
+      run:
+        shell: C:\cygwin\bin\bash.exe --login -o igncr '{0}'
+    name: Cygwin
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v4
+      with:
+        fetch-depth: 0
+    - name: Setup cygwin
+      uses: cygwin/cygwin-install-action@master
+      with:
+        packages: >-
+          cmake
+          cygwin-devel
+          gcc-core
+          gcc-g++
+          ninja
+    - name: Configure
+      run: |
+        cmake /cygdrive/d/a/zlib/zlib \
+          -B build \
+          -DCMAKE_BUILD_TYPE=Release \
+          -DZLIB_BUILD_MINIZIP=ON \
+          -DMINIZIP_ENABLE_BZIP2=OFF \
+          -G Ninja
+    - name: Build
+      run: cmake --build build --config Release -v -j1
+    - name: Run tests
+      run: ctest --output-on-failure --test-dir build -C Release
diff --git a/.gitignore b/.gitignore
index e86742897..8d069ed38 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,8 @@
 *.gcno
 *.gcov
 
+/zconf.h
+/Makefile
 /example
 /example64
 /examplesh
@@ -35,3 +37,15 @@ contrib/vstudio/vc143/arm64
 contrib/nuget/bin
 contrib/nuget/obj
 *.included
+
+# Bazel directories
+/bazel-*
+/bazel-bin
+/bazel-genfiles
+/bazel-out
+/bazel-testlogs
+user.bazelrc
+
+# MODULE.bazel.lock is ignored for now as per this recommendation:
+# https://github.com/bazelbuild/bazel/issues/20369
+MODULE.bazel.lock
diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 000000000..9a294f2f2
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,134 @@
+# Copied from https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/zlib/1.3.1.bcr.4/patches
+# Adapted from https://github.com/protocolbuffers/protobuf/blob/master/third_party/zlib.BUILD
+
+#  Copyright 2008 Google Inc.  All rights reserved.
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions are
+#  met:
+#
+#      * Redistributions of source code must retain the above copyright
+#  notice, this list of conditions and the following disclaimer.
+#      * Redistributions in binary form must reproduce the above
+#  copyright notice, this list of conditions and the following disclaimer
+#  in the documentation and/or other materials provided with the
+#  distribution.
+#      * Neither the name of Google Inc. nor the names of its
+#  contributors may be used to endorse or promote products derived from
+#  this software without specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#  Code generated by the Protocol Buffer compiler is owned by the owner
+#  of the input file used when generating it.  This code is not
+#  standalone and requires a support library to be linked with it.  This
+#  support library is itself covered by the above license.
+
+load("@rules_cc//cc:defs.bzl", "cc_library")
+load("@rules_license//rules:license.bzl", "license")
+
+package(
+    default_applicable_licenses = [":license"],
+)
+
+license(
+    name = "license",
+    license_kinds = ["@rules_license//licenses/spdx:Zlib"],
+    license_text = "LICENSE",
+)
+
+exports_files([
+    "LICENSE",
+])
+
+_ZLIB_HEADERS = [
+    "crc32.h",
+    "deflate.h",
+    "gzguts.h",
+    "inffast.h",
+    "inffixed.h",
+    "inflate.h",
+    "inftrees.h",
+    "trees.h",
+    "zconf.h",
+    "zlib.h",
+    "zutil.h",
+]
+
+_ZLIB_PREFIXED_HEADERS = ["zlib/include/" + hdr for hdr in _ZLIB_HEADERS]
+
+# In order to limit the damage from the `includes` propagation
+# via `:zlib`, copy the public headers to a subdirectory and
+# expose those.
+genrule(
+    name = "copy_public_headers",
+    srcs = _ZLIB_HEADERS,
+    outs = _ZLIB_PREFIXED_HEADERS,
+    cmd_bash = "cp $(SRCS) $(@D)/zlib/include/",
+    cmd_bat = " && ".join(
+        ["@copy /Y \"$(location %s)\" \"$(@D)\\zlib\\include\\\"  >NUL" %
+         s for s in _ZLIB_HEADERS],
+    ),
+)
+
+config_setting(
+    name = "mingw_gcc_compiler",
+    flag_values = {
+        "@bazel_tools//tools/cpp:compiler": "mingw-gcc",
+    },
+    visibility = [":__subpackages__"],
+)
+
+cc_library(
+    name = "z",
+    srcs = [
+        "adler32.c",
+        "compress.c",
+        "crc32.c",
+        "deflate.c",
+        "gzclose.c",
+        "gzlib.c",
+        "gzread.c",
+        "gzwrite.c",
+        "infback.c",
+        "inffast.c",
+        "inflate.c",
+        "inftrees.c",
+        "trees.c",
+        "uncompr.c",
+        "zutil.c",
+        # Include the un-prefixed headers in srcs to work
+        # around the fact that zlib isn't consistent in its
+        # choice of <> or "" delimiter when including itself.
+    ] + _ZLIB_HEADERS,
+    hdrs = _ZLIB_PREFIXED_HEADERS,
+    copts = select({
+        ":mingw_gcc_compiler": [
+            "-fpermissive",
+        ],
+        "@platforms//os:windows": [],
+        "//conditions:default": [
+            "-Wno-deprecated-non-prototype",
+            "-Wno-unused-variable",
+            "-Wno-implicit-function-declaration",
+        ],
+    }),
+    includes = ["zlib/include/"],
+    visibility = ["//visibility:public"],
+)
+
+alias(
+    name = "zlib",
+    actual = ":z",
+    visibility = ["//visibility:public"],
+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3d9b58df8..aa7359121 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,99 +1,131 @@
-cmake_minimum_required(VERSION 2.4.4...3.15.0)
-set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
+cmake_minimum_required(VERSION 3.12...3.31)
 
-project(zlib C)
+project(
+    zlib
+    LANGUAGES C
+    VERSION 1.4.1.1
+    HOMEPAGE_URL "https://zlib.net/"
+    DESCRIPTION "a general-purpose lossless data-compression library")
 
-set(VERSION "1.3.1.1")
+# ============================================================================
+# CPack
+# ============================================================================
+set(CPACK_PACKAGE_VENDOR "zlib-Project")
+set(CPACK_PACKAGE_DESCRIPTION_FILE ${zlib_SOURCE_DIR}/README)
+set(CPACK_RESOURCE_FILE_LICENSE ${zlib_SOURCE_DIR}/LICENSE)
+set(CPACK_RESOURCE_FILE_README ${zlib_SOURCE_DIR}/README)
 
-option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON)
+# ============================================================================
+# configuration
+# ============================================================================
 
-set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
-set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
-set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
-set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
-set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
+option(ZLIB_BUILD_TESTING "Enable Zlib Examples as tests" ON)
+option(ZLIB_BUILD_SHARED "Enable building zlib shared library" ON)
+option(ZLIB_BUILD_STATIC "Enable building zlib static library" ON)
+option(ZLIB_BUILD_MINIZIP "Enable building libminizip contrib library" OFF)
+option(ZLIB_INSTALL "Enable installation of zlib" ON)
+option(ZLIB_PREFIX "prefix for all types and library functions, see zconf.h.in"
+       OFF)
+mark_as_advanced(ZLIB_PREFIX)
 
-include(CheckTypeSize)
+if(WIN32)
+    option(ZLIB_INSTALL_COMPAT_DLL "Install a copy as zlib1.dll" ON)
+endif(WIN32)
+
+get_property(IS_MULTI GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+
+if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT IS_MULTI)
+    message(STATUS "No CMAKE_BUILD_TYPE set -- using Release")
+    set(CMAKE_BUILD_TYPE Release)
+endif(NOT DEFINED CMAKE_BUILD_TYPE AND NOT IS_MULTI)
+
+include(CheckCSourceCompiles)
 include(CheckFunctionExists)
 include(CheckIncludeFile)
-include(CheckCSourceCompiles)
-enable_testing()
+include(CMakePackageConfigHelpers)
+include(CheckTypeSize)
+include(CPack)
+include(GNUInstallDirs)
+
+set(CPACK_INCLUDED TRUE)
+
+if(NOT ZLIB_CONF_WRITTEN)
+    set(Z_PREFIX ${ZLIB_PREFIX})
+    set(CONF_OUT_FILE ${zlib_BINARY_DIR}/zconf.h.cmakein)
+    file(READ ${zlib_SOURCE_DIR}/zconf.h ZCONF_CONTENT LIMIT 245)
+    file(WRITE ${CONF_OUT_FILE} ${ZCONF_CONTENT})
+    file(APPEND ${CONF_OUT_FILE} "#cmakedefine Z_PREFIX 1\n")
+    file(APPEND ${CONF_OUT_FILE} "#cmakedefine HAVE_STDARG_H 1\n")
+    file(APPEND ${CONF_OUT_FILE} "#cmakedefine HAVE_UNISTD_H 1\n")
+    file(READ ${zlib_SOURCE_DIR}/zconf.h ZCONF_CONTENT OFFSET 244)
+    set(FIRST_ITEM TRUE)
 
-check_include_file(sys/types.h HAVE_SYS_TYPES_H)
-check_include_file(stdint.h    HAVE_STDINT_H)
-check_include_file(stddef.h    HAVE_STDDEF_H)
+    foreach(item IN LISTS ZCONF_CONTENT)
+        if(FIRST_ITEM)
+            string(APPEND OUT_CONTENT ${item})
+            set(FIRST_ITEM FALSE)
+        else(FIRST_ITEM)
+            string(APPEND OUT_CONTENT "\;" ${item})
+        endif(FIRST_ITEM)
+    endforeach(item IN LISTS ${ZCONF_CONTENT})
+
+    file(APPEND ${CONF_OUT_FILE} ${OUT_CONTENT})
+    set(ZLIB_CONF_WRITTEN
+        TRUE
+        CACHE BOOL "zconf.h.cmakein was created")
+    mark_as_advanced(ZLIB_CONF_WRITTEN)
+endif(NOT ZLIB_CONF_WRITTEN)
 
 #
 # Check to see if we have large file support
 #
 set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
-# We add these other definitions here because CheckTypeSize.cmake
-# in CMake 2.4.x does not automatically do so and we want
-# compatibility with CMake 2.4.x.
-if(HAVE_SYS_TYPES_H)
-    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
-endif()
-if(HAVE_STDINT_H)
-    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
-endif()
-if(HAVE_STDDEF_H)
-    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
-endif()
 check_type_size(off64_t OFF64_T)
-if(HAVE_OFF64_T)
-   add_definitions(-D_LARGEFILE64_SOURCE=1)
-endif()
-set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
+unset(CMAKE_REQUIRED_DEFINITIONS) # clear variable
 
 #
 # Check for fseeko
 #
 check_function_exists(fseeko HAVE_FSEEKO)
-if(NOT HAVE_FSEEKO)
-    add_definitions(-DNO_FSEEKO)
-endif()
+
+#
+# Check for stdarg.h
+#
+check_include_file(stdarg.h HAVE_STDARG_H)
 
 #
 # Check for unistd.h
 #
-check_include_file(unistd.h Z_HAVE_UNISTD_H)
+check_include_file(unistd.h HAVE_UNISTD_H)
 
+#
+# Check visibility attribute is supported
+#
 if(MSVC)
-    set(CMAKE_DEBUG_POSTFIX "d")
-    add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
-    add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
-    include_directories(${CMAKE_CURRENT_SOURCE_DIR})
-endif()
-
-option(RENAME_ZCONF "Rename the zconf when building out of source" ON)
-if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND RENAME_ZCONF)
-    # If we're doing an out of source build and the user has a zconf.h
-    # in their source tree...
-    if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
-        message(STATUS "Renaming")
-        message(STATUS "    ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
-        message(STATUS "to 'zconf.h.included' because this file is included with zlib")
-        message(STATUS "but CMake generates it automatically in the build directory.")
-        file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
-  endif()
-endif()
-
-set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
-configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
-		${ZLIB_PC} @ONLY)
-configure_file(	${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
-		${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
-include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
-
-
-#============================================================================
+    set(CMAKE_REQUIRED_FLAGS "-WX")
+else(MSVC)
+    set(CMAKE_REQUIRED_FLAGS "-WError")
+endif(MSVC)
+
+check_c_source_compiles(
+    "
+        #include <stdlib.h>
+        static void f(void) __attribute__ ((visibility(\"hidden\")));
+        int main(void) {return 0;}
+    "
+    HAVE___ATTR__VIS_HIDDEN)
+
+unset(CMAKE_COMPILE_FLAGS)
+set(ZLIB_PC ${zlib_BINARY_DIR}/zlib.pc)
+configure_file(${zlib_SOURCE_DIR}/zlib.pc.cmakein ${ZLIB_PC} @ONLY)
+configure_file(${zlib_BINARY_DIR}/zconf.h.cmakein ${zlib_BINARY_DIR}/zconf.h)
+
+# ============================================================================
 # zlib
-#============================================================================
+# ============================================================================
+
+set(ZLIB_PUBLIC_HDRS ${zlib_BINARY_DIR}/zconf.h zlib.h)
 
-set(ZLIB_PUBLIC_HDRS
-    ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
-    zlib.h
-)
 set(ZLIB_PRIVATE_HDRS
     crc32.h
     deflate.h
@@ -103,8 +135,8 @@ set(ZLIB_PRIVATE_HDRS
     inflate.h
     inftrees.h
     trees.h
-    zutil.h
-)
+    zutil.h)
+
 set(ZLIB_SRCS
     adler32.c
     compress.c
@@ -120,104 +152,179 @@ set(ZLIB_SRCS
     inffast.c
     trees.c
     uncompr.c
-    zutil.c
-)
-
-if(NOT MINGW)
-    set(ZLIB_DLL_SRCS
-        win32/zlib1.rc # If present will override custom build rule below.
-    )
-endif()
-
-# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
-file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
-string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
-    "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
-
-if(MINGW)
-    # This gets us DLL resource information when compiling on MinGW.
-    if(NOT CMAKE_RC_COMPILER)
-        set(CMAKE_RC_COMPILER windres.exe)
-    endif()
-
-    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
-                       COMMAND ${CMAKE_RC_COMPILER}
-                            -D GCC_WINDRES
-                            -I ${CMAKE_CURRENT_SOURCE_DIR}
-                            -I ${CMAKE_CURRENT_BINARY_DIR}
-                            -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
-                            -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
-    set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
-endif(MINGW)
-
-add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
-target_include_directories(zlib PUBLIC
-    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
-    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
-add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
-target_include_directories(zlibstatic PUBLIC
-    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
-    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
-set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
-set_target_properties(zlib PROPERTIES SOVERSION 1)
-
-if(NOT CYGWIN)
-    # This property causes shared libraries on Linux to have the full version
-    # encoded into their final filename.  We disable this on Cygwin because
-    # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
-    # seems to be the default.
-    #
-    # This has no effect with MSVC, on that platform the version info for
-    # the DLL comes from the resource file win32/zlib1.rc
-    set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
-endif()
-
-if(UNIX)
-    # On unix-like platforms the library is almost always called libz
-   set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
-   if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX))
-     set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
-   endif()
-elseif(BUILD_SHARED_LIBS AND WIN32)
-    # Creates zlib1.dll when building shared library version
-    set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
-endif()
-
-if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
-    install(TARGETS zlib zlibstatic
-        RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
-        ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
-        LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
-endif()
-if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
-    install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
-endif()
-if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
-    install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
-endif()
-if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
-    install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
-endif()
-
-#============================================================================
-# Example binaries
-#============================================================================
-if(ZLIB_BUILD_EXAMPLES)
-    add_executable(example test/example.c)
-    target_link_libraries(example zlib)
-    add_test(example example)
-
-    add_executable(minigzip test/minigzip.c)
-    target_link_libraries(minigzip zlib)
-
-    if(HAVE_OFF64_T)
-        add_executable(example64 test/example.c)
-        target_link_libraries(example64 zlib)
-        set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
-        add_test(example64 example64)
-
-        add_executable(minigzip64 test/minigzip.c)
-        target_link_libraries(minigzip64 zlib)
-        set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
-    endif()
-endif()
+    zutil.c)
+
+if(WIN32)
+    set(zlib_static_suffix "s")
+    set(CMAKE_DEBUG_POSTFIX "d")
+endif(WIN32)
+
+if(ZLIB_BUILD_SHARED)
+    add_library(
+        zlib SHARED ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}
+                    $<$<OR:$<BOOL:${WIN32}>,$<BOOL:${CYGWIN}>>:win32/zlib1.rc>)
+    add_library(ZLIB::ZLIB ALIAS zlib)
+    target_include_directories(
+        zlib
+        PUBLIC $<BUILD_INTERFACE:${zlib_BINARY_DIR}>
+               $<BUILD_INTERFACE:${zlib_SOURCE_DIR}>
+               $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+    target_compile_definitions(
+        zlib
+        PRIVATE ZLIB_BUILD
+                $<$<BOOL:NOT:${HAVE_FSEEKO}>:NO_FSEEKO>
+                $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>
+                $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE>
+                $<$<BOOL:${MSVC}>:_CRT_NONSTDC_NO_DEPRECATE>
+        PUBLIC $<$<BOOL:${HAVE_OFF64_T}>:_LARGEFILE64_SOURCE=1>)
+    set(INSTALL_VERSION ${zlib_VERSION})
+
+    if(NOT CYGWIN)
+        set_target_properties(zlib PROPERTIES SOVERSION ${zlib_VERSION_MAJOR}
+                                              VERSION ${INSTALL_VERSION})
+    endif(NOT CYGWIN)
+
+    set_target_properties(
+        zlib
+        PROPERTIES DEFINE_SYMBOL ZLIB_DLL
+                   EXPORT_NAME ZLIB
+                   OUTPUT_NAME z)
+    if(UNIX
+       AND NOT APPLE
+       AND NOT (CMAKE_SYSTEM_NAME STREQUAL AIX))
+        # On unix-like platforms the library is almost always called libz
+        set_target_properties(
+            zlib
+            PROPERTIES LINK_FLAGS
+                       "-Wl,--version-script,\"${zlib_SOURCE_DIR}/zlib.map\"")
+    endif(
+        UNIX
+        AND NOT APPLE
+        AND NOT (CMAKE_SYSTEM_NAME STREQUAL AIX))
+endif(ZLIB_BUILD_SHARED)
+
+if(ZLIB_BUILD_STATIC)
+    add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS}
+                                  ${ZLIB_PRIVATE_HDRS})
+    add_library(ZLIB::ZLIBSTATIC ALIAS zlibstatic)
+    target_include_directories(
+        zlibstatic
+        PUBLIC $<BUILD_INTERFACE:${zlib_BINARY_DIR}>
+               $<BUILD_INTERFACE:${zlib_SOURCE_DIR}>
+               $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+    target_compile_definitions(
+        zlibstatic
+        PRIVATE ZLIB_BUILD
+                $<$<BOOL:NOT:${HAVE_FSEEKO}>:NO_FSEEKO>
+                $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>
+                $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE>
+                $<$<BOOL:${MSVC}>:_CRT_NONSTDC_NO_DEPRECATE>
+        PUBLIC $<$<BOOL:${HAVE_OFF64_T}>:_LARGEFILE64_SOURCE=1>)
+    set_target_properties(
+        zlibstatic PROPERTIES EXPORT_NAME ZLIBSTATIC OUTPUT_NAME
+                                                     z${zlib_static_suffix})
+endif(ZLIB_BUILD_STATIC)
+
+if(ZLIB_INSTALL)
+    if(ZLIB_BUILD_SHARED)
+        install(
+            TARGETS zlib
+            COMPONENT Runtime
+            EXPORT zlibSharedExport
+            RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+            ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+            LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
+        install(
+            EXPORT zlibSharedExport
+            FILE ZLIB-shared.cmake
+            NAMESPACE ZLIB::
+            DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib)
+        if(ZLIB_INSTALL_COMPAT_DLL)
+            install(
+                FILES $<TARGET_FILE:zlib>
+                COMPONENT Runtime
+                RENAME zlib1.dll
+                DESTINATION "${CMAKE_INSTALL_BINDIR}")
+        endif(ZLIB_INSTALL_COMPAT_DLL)
+
+        if(MSVC)
+            install(
+                FILES $<TARGET_PDB_FILE:zlib>
+                COMPONENT Runtime
+                DESTINATION ${CMAKE_INSTALL_BINDIR}
+                CONFIGURATIONS Debug OR RelWithDebInfo
+                OPTIONAL)
+        endif(MSVC)
+    endif(ZLIB_BUILD_SHARED)
+
+    if(ZLIB_BUILD_STATIC)
+        install(
+            TARGETS zlibstatic
+            COMPONENT Development
+            EXPORT zlibStaticExport
+            RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+            ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+            LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
+        install(
+            EXPORT zlibStaticExport
+            FILE ZLIB-static.cmake
+            NAMESPACE ZLIB::
+            DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib)
+
+        if(ZLIB_INSTALL_COMPAT_DLL AND MINGW)
+            install(
+                FILES $<TARGET_FILE:zlibstatic>
+                COMPONENT Development
+                RENAME libz.dll.a
+                DESTINATION "${CMAKE_INSTALL_LIBDIR}")
+        endif(ZLIB_INSTALL_COMPAT_DLL AND MINGW)
+    endif(ZLIB_BUILD_STATIC)
+
+    configure_package_config_file(
+        ${zlib_SOURCE_DIR}/zlibConfig.cmake.in
+        ${zlib_BINARY_DIR}/ZLIBConfig.cmake
+        INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib)
+
+    write_basic_package_version_file(
+        "${zlib_BINARY_DIR}/ZLIBConfigVersion.cmake"
+        VERSION "${zlib_VERSION}"
+        COMPATIBILITY AnyNewerVersion)
+
+    install(FILES ${zlib_BINARY_DIR}/ZLIBConfig.cmake
+                  ${zlib_BINARY_DIR}/ZLIBConfigVersion.cmake
+            DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib)
+    install(
+        FILES ${ZLIB_PUBLIC_HDRS}
+        COMPONENT Development
+        DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+    install(
+        FILES zlib.3
+        COMPONENT Docs
+        DESTINATION "${CMAKE_INSTALL_MANDIR}/man3")
+    install(
+        FILES LICENSE
+              doc/algorithm.txt
+              doc/crc-doc.1.0.pdf
+              doc/rfc1950.txt
+              doc/rfc1951.txt
+              doc/rfc1952.txt
+              doc/txtvsbin.txt
+        COMPONENT Docs
+        DESTINATION "${CMAKE_INSTALL_DOCDIR}/zlib")
+    install(
+        FILES ${ZLIB_PC}
+        COMPONENT Development
+        DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+endif(ZLIB_INSTALL)
+
+# ============================================================================
+# Tests
+# ============================================================================
+if(ZLIB_BUILD_TESTING)
+    enable_testing()
+    add_subdirectory(test)
+endif(ZLIB_BUILD_TESTING)
+
+if(ZLIB_BUILD_MINIZIP)
+    add_subdirectory(contrib/minizip/)
+endif(ZLIB_BUILD_MINIZIP)
diff --git a/MODULE.bazel b/MODULE.bazel
new file mode 100644
index 000000000..cb4c13ef3
--- /dev/null
+++ b/MODULE.bazel
@@ -0,0 +1,9 @@
+module(
+    name = "zlib",
+    version = "0.0.0",
+    compatibility_level = 1,
+)
+
+bazel_dep(name = "platforms", version = "0.0.10")
+bazel_dep(name = "rules_cc", version = "0.0.16")
+bazel_dep(name = "rules_license", version = "1.0.0")
diff --git a/Makefile.in b/Makefile.in
index c00625bb0..7010b25c5 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -13,6 +13,8 @@
 #    make install prefix=$HOME
 
 CC=cc
+GCOV=GCOV
+LLVM_GCOV_FLAG=LLMV_GCOV_FLAG
 
 CFLAGS=-O
 #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
@@ -113,15 +115,19 @@ test64: all64
 	@rm -f tmp64_$$
 
 infcover.o: $(SRCDIR)test/infcover.c $(SRCDIR)zlib.h zconf.h
-	$(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/infcover.c
+	$(CC) $(CFLAGS) $(ZINCOUT) -c -coverage -o $@ $(SRCDIR)test/infcover.c
 
 infcover: infcover.o libz.a
-	$(CC) $(CFLAGS) -o $@ infcover.o libz.a
+	$(CC) $(CFLAGS) -coverage -o $@ infcover.o libz.a
 
 cover: infcover
+ifdef $(GCOV)
 	rm -f *.gcda
 	${QEMU_RUN} ./infcover
-	gcov inf*.c
+	${GCOV} ${LLVM_GCOV_FLAG} inf*.c -o ./infcover.gcda
+else
+	@echo 'cover disabled as no suitable gcov was found'
+endif
 
 libz.a: $(OBJS)
 	$(AR) $(ARFLAGS) $@ $(OBJS)
@@ -349,12 +355,13 @@ docs: zlib.3.pdf
 zlib.3.pdf: $(SRCDIR)zlib.3
 	groff -mandoc -f H -T ps $(SRCDIR)zlib.3 | ps2pdf - $@
 
-zconf.h.cmakein: $(SRCDIR)zconf.h.in
-	-@ TEMPFILE=zconfh_$$; \
-	echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
-	sed -f $$TEMPFILE $(SRCDIR)zconf.h.in > $@ &&\
-	touch -r $(SRCDIR)zconf.h.in $@ &&\
-	rm $$TEMPFILE
+# zconf.h.cmakein: $(SRCDIR)zconf.h.in
+# 	-@ TEMPFILE=zconfh_$$; \
+# 	echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
+# 	sed -f $$TEMPFILE $(SRCDIR)zconf.h.in > $@ &&\
+# 	touch -r $(SRCDIR)zconf.h.in $@ &&\
+# 	rm $$TEMPFILE
+# 
 
 zconf: $(SRCDIR)zconf.h.in
 	cp -p $(SRCDIR)zconf.h.in zconf.h
@@ -378,7 +385,7 @@ clean: minizip-clean
 	rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
 
 maintainer-clean: distclean
-distclean: clean zconf zconf.h.cmakein
+distclean: clean zconf # zconf.h.cmakein
 	rm -f Makefile zlib.pc configure.log
 	-@rm -f .DS_Store
 	@if [ -f Makefile.in ]; then \
diff --git a/README-cmake.md b/README-cmake.md
new file mode 100644
index 000000000..7258f9cad
--- /dev/null
+++ b/README-cmake.md
@@ -0,0 +1,83 @@
+# For building with cmake at least version 3.12 (minizip 3.12) is needed
+
+In most cases the usual
+
+    cmake -S . -B build -D CMAKE_BUILD_TYPE=Release
+
+will create everything you need, however if you want something off default you can adjust several options fit your needs.
+Every option is list below (excluding the cmake-standard options), they can be set via cmake-gui or on cmdline with
+
+    -D<option>=ON/OFF
+
+## ZLIB-options with defaults ##
+
+    ZLIB_BUILD_TESTING=ON -- Enable Zlib Examples as tests
+
+    ZLIB_BUILD_SHARED=ON -- Enable building zlib shared library
+
+    ZLIB_BUILD_STATIC=ON -- Enable building zlib static library
+
+    ZLIB_BUILD_MINIZIP=ON -- Enable building libminizip contrib library
+
+If this option is turned on, additional options are available from minizip (see below)
+
+    ZLIB_INSTALL=ON -- Enable installation of zlib
+
+    ZLIB_PREFIX=OFF -- prefix for all types and library functions, see zconf.h.in
+
+    ZLIB_INSTALL_COMPAT_DLL=ON -- Install a copy as zlib1.dll
+
+This option is only on windows available and may/will be turned off and removed somewhen in the future.
+If you rely cmake for finding and using zlib, this can be turned off, as `zlib1.dll` will never be used.
+
+## minizip-options with defaults ##
+
+    MINIZIP_BUILD_SHARED=ON -- Enable building minizip shared library
+
+    MINIZIP_BUILD_STATIC=ON -- Enable building minizip static library
+
+    MINIZIP_BUILD_TESTING=ON -- Enable testing of minizip
+
+    MINIZIP_ENABLE_BZIP2=ON -- Build minizip withj bzip2 support
+
+A usable installation of bzip2 is needed or config will fail. Turn this option of in this case.
+
+    MINIZIP_INSTALL=ON -- Enable installation of minizip
+
+    MINIZIP_INSTALL_COMPAT_DLL=ON -- Install a copy as libminizip-1.dll
+
+This option is only available on mingw as they tend to name this lib different. Maybe this will also be
+removed in the future as. If you rely cmake for finding and using zlib, this can be turned off, as
+the other file will never be used.
+
+## Using the libs ##
+
+To pull in what you need it's enough to just write
+
+    find_package(ZLIB CONFIG)
+
+or
+
+    find_package(minizip CONFIG)
+
+in your CMakeLists.txt, however it is advised to specify what you really want via:
+
+    find_package(ZLIB CONFIG COMPONENTS shared static REQUIRED)
+
+or
+
+    find_package(minizip CONFIG COMPONENTS shared static REQUIRED)
+
+As it's possible to only build the shared or the static lib, you can make sure that everything you need
+is found. If no COMPONENTS are requested, everything that is found will satisfy your request. If the
+libraries are optional in you project, you can omit the REQUIRED and check yourself if the targets you
+want to link against are created.
+
+When you search for minizip, it will search zlib for you, so only one of both is needed.
+
+## Imported targets ##
+
+When found the following targets are created for you:
+
+    ZLIB::ZLIB and ZLIB::ZLIBSTATIC -- for zlib
+    MINIZIP::minizip and MINIZIP::minizipstatic -- for minizip
diff --git a/configure b/configure
index 54c802e23..1834659fd 100755
--- a/configure
+++ b/configure
@@ -87,6 +87,7 @@ zprefix=0
 zconst=0
 build64=0
 gcc=0
+clang=0
 warn=0
 debug=0
 address=0
@@ -185,14 +186,47 @@ else
 fi
 
 case "$cc" in
-  *gcc*) gcc=1 ;;
-  *clang*) gcc=1 ;;
+  *gcc*) gcc=1
+    GCOV="gcov" ;;
+  *clang*) gcc=1
+    clang=1 ;;
 esac
 case `$cc -v 2>&1` in
-  *gcc*) gcc=1 ;;
-  *clang*) gcc=1 ;;
+  *gcc*) gcc=1
+    GCOV="gcov" ;;
+  *clang*) gcc=1
+    clang=1 ;;
 esac
 
+if test "$clang" -eq 1; then
+  if test "$cc" = "clang"; then
+    if which -s llvm-cov; then
+      GCOV="llvm-cov"
+      LLVM_GCOV_FLAG="gcov"
+      GCOV="llvm-cov"
+      LLVM_GCOV_FLAG="gcov"
+      echo "Using ${GCOV} for coverage"
+    else
+      cover=0
+      GCOV=""
+      LLVM_GCOV_FLAG=""
+      echo "Deactivating cover as no suitable gcov can be found"
+    fi
+  else
+    clangV=`echo "$cc" | sed -e 's/^.*-//'`
+    if which -s llvm-cov-${clangV}; then
+      GCOV="llvm-cov-${clangV}"
+      LLVM_GCOV_FLAG="gcov"
+      echo "Using ${GCOV} for coverage"
+    else
+      cover=0
+      GCOV=""
+      LLVM_GCOV_FLAG=""
+      echo "Deactivating cover as no suitable gcov can be found"
+    fi
+  fi
+fi
+
 show $cc -c $test.c
 if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
   echo ... using gcc >> configure.log
@@ -577,7 +611,7 @@ cat > $test.c <<EOF
 int main() { return 0; }
 EOF
 if try $CC -c $CFLAGS $test.c; then
-  sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
+  sed < zconf.h "/^#if HAVE_UNISTD_H-0.* may be/s/ HAVE_UNISTD_H-0\(.*\) may be/ 1\1 was/" > zconf.temp.h
   mv zconf.temp.h zconf.h
   echo "Checking for unistd.h... Yes." | tee -a configure.log
 else
@@ -592,7 +626,7 @@ cat > $test.c <<EOF
 int main() { return 0; }
 EOF
 if try $CC -c $CFLAGS $test.c; then
-  sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
+  sed < zconf.h "/^#if HAVE_STDARG_H-0.* may be/s/ HAVE_STDARG_H-0\(.*\) may be/ 1\1 was/" > zconf.temp.h
   mv zconf.temp.h zconf.h
   echo "Checking for stdarg.h... Yes." | tee -a configure.log
 else
@@ -620,7 +654,6 @@ fi
 
 # if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
 if test $cover -eq 1; then
-  CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
   if test -n "$GCC_CLASSIC"; then
     CC=$GCC_CLASSIC
   fi
@@ -872,6 +905,8 @@ echo uname = $uname >> configure.log
 # update Makefile with the configure results
 sed < ${SRCDIR}Makefile.in "
 /^CC *=/s#=.*#=$CC#
+/^GCOV *=/s#=.*#=$GCOV#
+/^LLVM_GCOV_FLAG *=/s#=.*#=$LLVM_GCOV_FLAG#
 /^CFLAGS *=/s#=.*#=$CFLAGS#
 /^SFLAGS *=/s#=.*#=$SFLAGS#
 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
diff --git a/contrib/ada/zlib-thin.adb b/contrib/ada/zlib-thin.adb
index 0ca4a7120..b28f922af 100644
--- a/contrib/ada/zlib-thin.adb
+++ b/contrib/ada/zlib-thin.adb
@@ -12,7 +12,8 @@ package body ZLib.Thin is
 
    ZLIB_VERSION  : constant Chars_Ptr := zlibVersion;
 
-   Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit;
+   Dummy : Z_Stream;
+   Z_Stream_Size : constant Int := Dummy'Size / System.Storage_Unit;
 
    --------------
    -- Avail_In --
diff --git a/contrib/minizip/CMakeLists.txt b/contrib/minizip/CMakeLists.txt
new file mode 100644
index 000000000..1aaf4ac74
--- /dev/null
+++ b/contrib/minizip/CMakeLists.txt
@@ -0,0 +1,380 @@
+cmake_minimum_required(VERSION 3.12...3.31)
+
+project(
+    minizip
+    VERSION 1.0.0
+    LANGUAGES C
+    DESCRIPTION "A library for creating zipfiles based in zlib"
+    HOMEPAGE_URL "https://www.winimage.com/zLibDll/minizip.html")
+
+if(CMAKE_SIZEOF_VOID_P LESS 8 AND NOT MINGW)
+    message(WARNING "libminizip needs 64bit - stopping here")
+    return()
+endif(CMAKE_SIZEOF_VOID_P LESS 8 AND NOT MINGW)
+
+# ============================================================================
+# CPack
+# ============================================================================
+set(CPACK_PACKAGE_VENDOR "zlib-Project")
+set(CPACK_PACKAGE_DESCRIPTION_FILE ${minizip_SOURCE_DIR}/MiniZip64_info.txt)
+set(CPACK_RESOURCE_FILE_LICENSE ${minizip_SOURCE_DIR}/../../LICENSE)
+set(CPACK_RESOURCE_FILE_README ${minizip_SOURCE_DIR}/MiniZip64_info.txt)
+
+# ============================================================================
+# configuration
+# ============================================================================
+option(MINIZIP_BUILD_SHARED "Enable building minizip shared library" ON)
+option(MINIZIP_BUILD_STATIC "Enable building minizip static library" ON)
+option(MINIZIP_BUILD_TESTING "Enable testing of minizip" ON)
+option(MINIZIP_ENABLE_BZIP2 "Build minizip withj bzip2 support" ON)
+option(MINIZIP_INSTALL "Enable installation of minizip" ON)
+
+if(MINGW)
+    option(MINIZIP_INSTALL_COMPAT_DLL "Install a copy as libminizip-1.dll" ON)
+endif(MINGW)
+
+include(CheckCSourceCompiles)
+include(CheckFunctionExists)
+include(CheckIncludeFile)
+include(CMakePackageConfigHelpers)
+include(CheckTypeSize)
+include(GNUInstallDirs)
+
+if(NOT CPACK_INCLUDED)
+    include(CPack)
+endif(NOT CPACK_INCLUDED)
+
+if(MINIZIP_ENABLE_BZIP2)
+    find_package(BZip2 REQUIRED)
+endif(MINIZIP_ENABLE_BZIP2)
+
+#
+# Check for fopen64
+#
+check_function_exists(fopen64 HAVE_FOPEN64)
+
+#
+# Check for fseeko
+#
+check_function_exists(fseeko HAVE_FSEEKO)
+
+#
+# Check for unistd.h
+#
+check_include_file(unistd.h HAVE_UNISTD_H)
+
+#
+# Check to see if we have large file support
+#
+set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
+check_type_size(off64_t OFF64_T)
+unset(CMAKE_REQUIRED_DEFINITIONS) # clear variable
+
+#
+# Check visibility attribute is supported
+#
+if(MSVC)
+    set(CMAKE_REQUIRED_FLAGS "-WX")
+else(MSVC)
+    set(CMAKE_REQUIRED_FLAGS "-WError")
+endif(MSVC)
+
+check_c_source_compiles(
+    "
+        #include <stdlib.h>
+        static void f(void) __attribute__ ((visibility(\"hidden\")));
+        int main(void) {return 0;}
+    "
+    HAVE___ATTR__VIS_HIDDEN)
+
+unset(CMAKE_REQUIRED_FLAGS)
+
+if(NOT TARGET ZLIB::ZLIB)
+    find_package(ZLIB REQUIRED CONFIG)
+endif(NOT TARGET ZLIB::ZLIB)
+
+set(LIBMINIZIP_SRCS ioapi.c mztools.c unzip.c zip.c)
+
+set(LIBMINIZIP_HDRS crypt.h ints.h ioapi.h mztools.h unzip.h zip.h)
+
+set(MINIZIP_SRCS ioapi.c $<$<BOOL:${WIN32}>:iowin32.c> minizip.c zip.c)
+
+set(MINIZIP_HDRS crypt.h ints.h ioapi.h $<$<BOOL:${WIN32}>:iowin32.h> skipset.h
+                 zip.h)
+
+set(MINIUNZIP_SRCS ioapi.c $<$<BOOL:${WIN32}>:iowin32.c> miniunz.c unzip.c
+                   zip.c)
+
+set(MINIUNZIP_HDRS
+    crypt.h
+    ints.h
+    ioapi.h
+    $<$<BOOL:${WIN32}>:iowin32.h>
+    skipset.h
+    unzip.h
+    zip.h)
+
+if(WIN32 OR CYGWIN)
+    set(minizip_static_suffix "s")
+    set(CMAKE_DEBUG_POSTFIX "d")
+endif(WIN32 OR CYGWIN)
+
+if(MINIZIP_BUILD_SHARED)
+    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
+    add_library(libminizip SHARED ${LIBMINIZIP_SRCS} ${LIBMINIZIP_HDRS})
+    add_library(MINIZIP::minizip ALIAS libminizip)
+    target_include_directories(
+        libminizip PUBLIC $<BUILD_INTERFACE:${minizip_SOURCE_DIR}>
+                          $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+    target_compile_definitions(
+        libminizip
+        PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>
+                $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>
+                $<$<BOOL:${HAVE_UNISTD_H}>:HAVE_UNISTD_H=1>
+        PUBLIC $<$<BOOL:${HAVE_OFF64_T}>:_LARGEFILE64_SOURCE=1>
+                $<$<BOOL:${BZIP2_FOUND}>:HAVE_BZIP2=1>
+                $<$<BOOL:NOT:${HAVE_FOPEN64}>:USE_FILE32API=1>)
+
+    if(NOT CYGWIN)
+        set_target_properties(libminizip PROPERTIES SOVERSION
+                                                    ${minizip_VERSION_MAJOR})
+    endif(NOT CYGWIN)
+
+    set_target_properties(
+        libminizip
+        PROPERTIES EXPORT_NAME minizip
+                   OUTPUT_NAME minizip
+                   VERSION ${minizip_VERSION}
+                   SOVERSION ${minizip_VERSION_MAJOR})
+
+    target_link_libraries(libminizip
+        PUBLIC ZLIB::ZLIB
+            $<$<BOOL:${BZIP2_FOUND}>:BZip2::BZip2>)
+
+    add_executable(minizip ${MINIZIP_SRCS} ${MINIZIP_HDRS})
+    set_target_properties(minizip PROPERTIES EXPORT_NAME minizip_executable)
+    target_compile_definitions(
+        minizip PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>)
+    target_link_libraries(minizip PRIVATE MINIZIP::minizip)
+    add_executable(miniunzip ${MINIUNZIP_SRCS} ${MINIUNZIP_HDRS})
+    set_target_properties(miniunzip PROPERTIES EXPORT_NAME miniunzip_executable)
+    target_compile_definitions(
+        miniunzip PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>)
+    target_link_libraries(miniunzip PRIVATE MINIZIP::minizip)
+endif(MINIZIP_BUILD_SHARED)
+
+if(MINIZIP_BUILD_STATIC)
+    add_library(libminizipstatic STATIC ${LIBMINIZIP_SRCS} ${LIBMINIZIP_HDRS})
+    add_library(MINIZIP::minizipstatic ALIAS libminizipstatic)
+    target_include_directories(
+        libminizipstatic
+        PUBLIC $<BUILD_INTERFACE:${minizip_SOURCE_DIR}>
+               $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+    target_compile_definitions(
+        libminizipstatic
+        PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>
+                $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>
+                $<$<BOOL:${HAVE_UNISTD_H}>:HAVE_UNISTD_H=1>
+        PUBLIC $<$<BOOL:${HAVE_OFF64_T}>:_LARGEFILE64_SOURCE=1>
+                $<$<BOOL:${BZIP2_FOUND}>:HAVE_BZIP2=1>
+                $<$<BOOL:NOT:${HAVE_FOPEN64}>:USE_FILE32API=1>)
+    set_target_properties(
+        libminizipstatic PROPERTIES EXPORT_NAME minizipstatic
+                                    OUTPUT_NAME minizip${minizip_static_suffix})
+
+    if(CYGWIN)
+        set_target_properties(libminizipstatic PROPERTIES SUFFIX ".dll.a")
+    endif(CYGWIN)
+
+    target_link_libraries(libminizipstatic PUBLIC ZLIB::ZLIBSTATIC
+        $<$<BOOL:${BZIP2_FOUND}>:BZip2::BZip2>)
+
+    add_executable(minizipstatic ${MINIZIP_SRCS} ${MINIZIP_HDRS})
+    set_target_properties(minizipstatic PROPERTIES EXPORT_NAME
+                                                   minizip_static_executable)
+    target_compile_definitions(
+        minizipstatic PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>)
+    target_link_libraries(minizipstatic PRIVATE MINIZIP::minizipstatic)
+    add_executable(miniunzipstatic ${MINIUNZIP_SRCS} ${MINIUNZIP_HDRS})
+    set_target_properties(miniunzipstatic
+                          PROPERTIES EXPORT_NAME miniunzip_static_executable)
+    target_compile_definitions(
+        miniunzipstatic PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>)
+    target_link_libraries(miniunzipstatic PRIVATE MINIZIP::minizipstatic)
+endif(MINIZIP_BUILD_STATIC)
+
+if(MINIZIP_INSTALL)
+    if(MINIZIP_BUILD_SHARED)
+        install(
+            TARGETS libminizip minizip miniunzip
+            COMPONENT Runtime
+            EXPORT minizipSharedExport
+            RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+            ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+            LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
+        install(
+            EXPORT minizipSharedExport
+            FILE minizip-shared.cmake
+            NAMESPACE MINIZIP::
+            DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/minizip)
+        if(MINIZIP_INSTALL_COMPAT_DLL)
+            install(
+                FILES $<TARGET_FILE:libminizip>
+                COMPONENT Runtime
+                RENAME libminizip-${minizip_VERSION_MAJOR}.dll
+                DESTINATION "${CMAKE_INSTALL_BINDIR}")
+        endif(MINIZIP_INSTALL_COMPAT_DLL)
+
+        if(MSVC)
+            install(
+                FILES $<TARGET_PDB_FILE:libminizip>
+                COMPONENT Runtime
+                DESTINATION ${CMAKE_INSTALL_BINDIR}
+                CONFIGURATIONS Debug OR RelWithDebInfo
+                OPTIONAL)
+        endif(MSVC)
+    endif(MINIZIP_BUILD_SHARED)
+
+    if(MINIZIP_BUILD_STATIC)
+        install(
+            TARGETS libminizipstatic
+            COMPONENT Development
+            TARGETS minizipstatic miniunzipstatic
+            COMPONENT Runtime
+            EXPORT minizipStaticExport
+            RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+            ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+            LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
+        install(
+            EXPORT minizipStaticExport
+            FILE minizip-static.cmake
+            NAMESPACE MINIZIP::
+            DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/minizip)
+    endif(MINIZIP_BUILD_STATIC)
+
+    configure_package_config_file(
+        ${minizip_SOURCE_DIR}/minizipConfig.cmake.in
+        ${minizip_BINARY_DIR}/minizipConfig.cmake
+        INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/minizip)
+    write_basic_package_version_file(
+        "${minizip_BINARY_DIR}/minizipConfigVersion.cmake"
+        VERSION "${minizip_VERSION}"
+        COMPATIBILITY AnyNewerVersion)
+    install(FILES ${minizip_BINARY_DIR}/minizipConfig.cmake
+                  ${minizip_BINARY_DIR}/minizipConfigVersion.cmake
+            DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/minizip)
+    install(
+        FILES ${LIBMINIZIP_HDRS}
+        COMPONENT Development
+        DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+endif(MINIZIP_INSTALL)
+
+if(MINIZIP_BUILD_TESTING)
+    enable_testing()
+
+    if(MINIZIP_BUILD_SHARED AND NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL
+                                ".dll")
+        add_test(
+            NAME minizip_prepare_shared_zip
+            COMMAND ${CMAKE_COMMAND} -DCREATE_SHARED=ON -P
+                    ${CMAKE_CURRENT_SOURCE_DIR}/test/test_helper.cm
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_zipping_test_file_shared
+            COMMAND minizip test_file_shared.zip test_file_shared.txt
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_prepare_shared_unzip
+            COMMAND ${CMAKE_COMMAND} -DMOVE_SHARED=ON -P
+                    ${CMAKE_CURRENT_SOURCE_DIR}/test/test_helper.cm
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_miniunzipping_test_file_shared.zip
+            COMMAND miniunzip test_file_shared.zip
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_compare_shared
+            COMMAND ${CMAKE_COMMAND} -E compare_files test_file_shared.txt
+                    test_file_shared.orig
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_clean_shared_zip
+            COMMAND ${CMAKE_COMMAND} -DDELETE_SHARED=ON -P
+                    ${CMAKE_CURRENT_SOURCE_DIR}/test/test_helper.cm
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        set_tests_properties(minizip_prepare_shared_zip
+                             PROPERTIES FIXTURES_SETUP prepare_shared)
+        set_tests_properties(
+            minizip_zipping_test_file_shared
+            PROPERTIES FIXTURES_REQUIRED prepare_shared FIXTURES_SETUP
+                       zip_shared)
+        set_tests_properties(
+            minizip_prepare_shared_unzip
+            PROPERTIES FIXTURES_REQUIRED zip_shared FIXTURES_SETUP
+                       prepare_unzip_shared)
+        set_tests_properties(
+            minizip_miniunzipping_test_file_shared.zip
+            PROPERTIES FIXTURES_REQUIRED prepare_unzip_shared FIXTURES_SETUP
+                       prepare_compare_shared)
+        set_tests_properties(
+            minizip_compare_shared
+            PROPERTIES FIXTURES_REQUIRED prepare_compare_shared FIXTURES_SETUP
+                       compared_shared)
+        set_tests_properties(minizip_clean_shared_zip
+                             PROPERTIES FIXTURES_CLEANUP compared_shared)
+    endif(MINIZIP_BUILD_SHARED AND NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL
+                                   ".dll")
+
+    if(MINIZIP_BUILD_STATIC)
+        add_test(
+            NAME minizip_prepare_static_zip
+            COMMAND ${CMAKE_COMMAND} -DCREATE_STATIC=ON -P
+                    ${CMAKE_CURRENT_SOURCE_DIR}/test/test_helper.cm
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_zipping_test_file_static
+            COMMAND minizipstatic test_file_static.zip test_file_static.txt
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_prepare_static_unzip
+            COMMAND ${CMAKE_COMMAND} -DMOVE_STATIC=ON -P
+                    ${CMAKE_CURRENT_SOURCE_DIR}/test/test_helper.cm
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_miniunzipping_test_file_static.zip
+            COMMAND miniunzipstatic test_file_static.zip
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_compare_static
+            COMMAND ${CMAKE_COMMAND} -E compare_files test_file_static.txt
+                    test_file_static.orig
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        add_test(
+            NAME minizip_clean_static_zip
+            COMMAND ${CMAKE_COMMAND} -DDELETE_STATIC=ON -P
+                    ${CMAKE_CURRENT_SOURCE_DIR}/test/test_helper.cm
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test)
+        set_tests_properties(minizip_prepare_static_zip
+                             PROPERTIES FIXTURES_SETUP prepare_static)
+        set_tests_properties(
+            minizip_zipping_test_file_static
+            PROPERTIES FIXTURES_REQUIRED prepare_static FIXTURES_SETUP
+                       zip_static)
+        set_tests_properties(
+            minizip_prepare_static_unzip
+            PROPERTIES FIXTURES_REQUIRED zip_static FIXTURES_SETUP
+                       prepare_unzip_static)
+        set_tests_properties(
+            minizip_miniunzipping_test_file_static.zip
+            PROPERTIES FIXTURES_REQUIRED prepare_unzip_static FIXTURES_SETUP
+                       prepare_compare_static)
+        set_tests_properties(
+            minizip_compare_static
+            PROPERTIES FIXTURES_REQUIRED prepare_compare_static FIXTURES_SETUP
+                       compared_static)
+        set_tests_properties(minizip_clean_static_zip
+                             PROPERTIES FIXTURES_CLEANUP compared_static)
+    endif(MINIZIP_BUILD_STATIC)
+
+    add_subdirectory(test)
+endif(MINIZIP_BUILD_TESTING)
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c
index 782d32469..3dbefe48c 100644
--- a/contrib/minizip/ioapi.c
+++ b/contrib/minizip/ioapi.c
@@ -15,7 +15,7 @@
 #endif
 
 #if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
-// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
+/* In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions */
 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
 #define FTELLO_FUNC(stream) ftello(stream)
 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h
index f3b193d80..6b9968c73 100644
--- a/contrib/minizip/ioapi.h
+++ b/contrib/minizip/ioapi.h
@@ -23,8 +23,8 @@
 
 #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
 
-  // Linux needs this to support file operation on files larger then 4+GB
-  // But might need better if/def to select just the platforms that needs them.
+  /* Linux needs this to support file operation on files larger then 4+GB */
+  /* But might need better if/def to select just the platforms that needs them.*/
 
         #ifndef __USE_FILE_OFFSET64
                 #define __USE_FILE_OFFSET64
@@ -161,8 +161,8 @@ typedef struct zlib_filefunc64_32_def_s
 
 #define ZREAD64(filefunc,filestream,buf,size)     ((*((filefunc).zfile_func64.zread_file))   ((filefunc).zfile_func64.opaque,filestream,buf,size))
 #define ZWRITE64(filefunc,filestream,buf,size)    ((*((filefunc).zfile_func64.zwrite_file))  ((filefunc).zfile_func64.opaque,filestream,buf,size))
-//#define ZTELL64(filefunc,filestream)            ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
-//#define ZSEEK64(filefunc,filestream,pos,mode)   ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
+/*#define ZTELL64(filefunc,filestream)            ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) */
+/*#define ZSEEK64(filefunc,filestream,pos,mode)   ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) */
 #define ZCLOSE64(filefunc,filestream)             ((*((filefunc).zfile_func64.zclose_file))  ((filefunc).zfile_func64.opaque,filestream))
 #define ZERROR64(filefunc,filestream)             ((*((filefunc).zfile_func64.zerror_file))  ((filefunc).zfile_func64.opaque,filestream))
 
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c
index 49f5ba1b1..65095663a 100644
--- a/contrib/minizip/iowin32.c
+++ b/contrib/minizip/iowin32.c
@@ -26,7 +26,7 @@
 #endif
 
 
-// see Include/shared/winapifamily.h in the Windows Kit
+/* see Include/shared/winapifamily.h in the Windows Kit */
 #if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
 
 #if !defined(WINAPI_FAMILY_ONE_PARTITION)
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c
index a44e36a01..18d866b6f 100644
--- a/contrib/minizip/minizip.c
+++ b/contrib/minizip/minizip.c
@@ -435,7 +435,7 @@ int main(int argc, char *argv[]) {
                      }
                      if( lastslash != NULL )
                      {
-                         savefilenameinzip = lastslash+1; // base filename follows last slash.
+                         savefilenameinzip = lastslash+1; /* base filename follows last slash. */
                      }
                  }
 
diff --git a/contrib/minizip/minizip.pc.txt b/contrib/minizip/minizip.pc.txt
new file mode 100644
index 000000000..060ab091c
--- /dev/null
+++ b/contrib/minizip/minizip.pc.txt
@@ -0,0 +1,13 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+sharedlibdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${exec_prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+
+Name: minizip
+Description: minizip compression library
+Version: @minizip_VERSION@
+
+Requires:
+Libs: -L${libdir} -L${sharedlibdir} -lz -lminizip
+Cflags: -I${includedir}
diff --git a/contrib/minizip/minizipConfig.cmake.in b/contrib/minizip/minizipConfig.cmake.in
new file mode 100644
index 000000000..88ea0a080
--- /dev/null
+++ b/contrib/minizip/minizipConfig.cmake.in
@@ -0,0 +1,35 @@
+@PACKAGE_INIT@
+
+set(_minizip_supported_components "")
+include(CMakeFindDependencyMacro)
+
+if(@MINIZIP_BUILD_SHARED@)
+    list(APPEND _minizip_supported_components shared)
+endif(@MINIZIP_BUILD_SHARED@)
+
+if(@MINIZIP_BUILD_STATIC@)
+    list(APPEND _minizip_supported_components static)
+endif(@MINIZIP_BUILD_STATIC@)
+
+if(@MINIZIP_ENABLE_BZIP2@)
+    find_dependency(BZip2)
+endif(@MINIZIP_ENABLE_BZIP2@)
+
+if(minizip_FIND_COMPONENTS)
+    find_dependency(ZLIB CONFIG COMPONENTS ${minizip_FIND_COMPONENTS})
+
+    foreach(_comp ${minizip_FIND_COMPONENTS})
+        if(NOT _comp IN_LIST _MINIZIP_supported_components)
+            set(minizip_FOUND False)
+            set(minizip_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
+        endif(NOT _comp IN_LIST _MINIZIP_supported_components)
+
+        include("${CMAKE_CURRENT_LIST_DIR}/minizip-${_comp}.cmake")
+    endforeach(_comp ${ZLIB_FIND_COMPONENTS})
+else(minizip_FIND_COMPONENTS)
+    find_dependency(ZLIB CONFIG)
+
+    foreach(_component_config IN LISTS _minizip_supported_components)
+        include("${CMAKE_CURRENT_LIST_DIR}/minizip-${_component_config}.cmake")
+    endforeach(_component_config IN LISTS _minizip_supported_components)
+endif(minizip_FIND_COMPONENTS)
diff --git a/contrib/minizip/mztools.c b/contrib/minizip/mztools.c
index f86c1e71b..6260cb0ed 100644
--- a/contrib/minizip/mztools.c
+++ b/contrib/minizip/mztools.c
@@ -219,7 +219,7 @@ extern int ZEXPORT unzRepair(const char* file, const char* fileOut, const char*
     {
       int entriesZip = entries;
       char end[22];
-      char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
+      char* comment = ""; /* "ZIP File recovered by zlib/minizip/mztools"; */
       int comsize = (int) strlen(comment);
       if (entriesZip > 0xffff) {
         entriesZip = 0xffff;
diff --git a/contrib/minizip/skipset.h b/contrib/minizip/skipset.h
index 5e648b9d2..9f0aad612 100644
--- a/contrib/minizip/skipset.h
+++ b/contrib/minizip/skipset.h
@@ -1,4 +1,4 @@
-// skipset.h -- set operations using a skiplist
+/* skipset.h -- set operations using a skiplist
 // Copyright (C) 2024 Mark Adler
 // See MiniZip_info.txt for the license.
 
@@ -50,20 +50,20 @@
 // Auxiliary functions available to the application:
 // - set_alloc() allocates memory with optional tracking (#define SET_TRACK)
 // - set_free() deallocates memory allocated by set_alloc()
-// - set_rand() returns 32 random bits (seeded by set_start())
+// - set_rand() returns 32 random bits (seeded by set_start()) */
 
 #ifndef SKIPSET_H
 #define SKIPSET_H
 
-#include <stdlib.h>     // realloc(), free(), NULL, size_t
-#include <stddef.h>     // ptrdiff_t
-#include <setjmp.h>     // jmp_buf, longjmp()
-#include <errno.h>      // ENOMEM
-#include <time.h>       // time(), clock()
-#include <assert.h>     // assert.h
-#include "ints.h"       // i16_t, ui32_t, ui64_t
+#include <stdlib.h>     /* realloc(), free(), NULL, size_t */
+#include <stddef.h>     /* ptrdiff_t */
+#include <setjmp.h>     /* jmp_buf, longjmp() */
+#include <errno.h>      /* ENOMEM */
+#include <time.h>       /* time(), clock() */
+#include <assert.h>     /* assert.h */
+#include "ints.h"       /* i16_t, ui32_t, ui64_t */
 
-// Structures and functions below noted as "--private--" should not be used by
+/* Structures and functions below noted as "--private--" should not be used by
 // the application. set_t is partially private and partially public -- see the
 // comments there.
 
@@ -73,18 +73,18 @@
 
 // *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / www.pcg-random.org
 // Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
-// --private-- Random number generator state.
+// --private-- Random number generator state. */
 typedef struct {
-    ui64_t state;       // 64-bit generator state
-    ui64_t inc;         // 63-bit sequence id
+    ui64_t state;       /* 64-bit generator state */
+    ui64_t inc;         /* 63-bit sequence id */
 } set_rand_t;
-// --private-- Initialize the state *gen using seed and seq. seed seeds the
-// advancing 64-bit state. seq is a sequence selection constant.
+/* --private-- Initialize the state *gen using seed and seq. seed seeds the
+// advancing 64-bit state. seq is a sequence selection constant. */
 void set_seed(set_rand_t *gen, ui64_t seed, ui64_t seq) {
     gen->inc = (seq << 1) | 1;
     gen->state = (seed + gen->inc) * 6364136223846793005ULL + gen->inc;
 }
-// Return 32 random bits, advancing the state *gen.
+/* Return 32 random bits, advancing the state *gen. */
 ui32_t set_rand(set_rand_t *gen) {
     ui64_t state = gen->state;
     gen->state = state * 6364136223846793005ULL + gen->inc;
@@ -92,40 +92,40 @@ ui32_t set_rand(set_rand_t *gen) {
     int rot = state >> 59;
     return (mix >> rot) | (mix << ((-rot) & 31));
 }
-// End of PCG32 code.
+/* End of PCG32 code. */
 
-// --private-- Linked-list node.
+/* --private-- Linked-list node. */
 typedef struct set_node_s set_node_t;
 struct set_node_s {
-    set_key_t key;          // the key (not used for head or path)
-    i16_t size;             // number of allocated pointers in right[]
-    i16_t fill;             // number of pointers in right[] filled in
-    set_node_t **right;     // pointer for each level, each to the right
+    set_key_t key;          /* the key (not used for head or path) */
+    i16_t size;             /* number of allocated pointers in right[] */
+    i16_t fill;             /* number of pointers in right[] filled in */
+    set_node_t **right;     /* pointer for each level, each to the right */
 };
 
-// A set. The application sets env, may use gen with set_rand(), and may read
-// allocs and memory. The remaining variables are --private-- .
+/* A set. The application sets env, may use gen with set_rand(), and may read
+// allocs and memory. The remaining variables are --private-- . */
 typedef struct set_s {
-    set_node_t *head;       // skiplist head -- no key, just links
-    set_node_t *path;       // right[] is path to key from set_found()
-    set_node_t *node;       // node under construction, in case of longjmp()
-    i16_t depth;            // maximum depth of the skiplist
-    ui64_t ran;             // a precious trove of random bits
-    set_rand_t gen;         // random number generator state
-    jmp_buf env;            // setjmp() environment for allocation errors
+    set_node_t *head;       /* skiplist head -- no key, just links */
+    set_node_t *path;       /* right[] is path to key from set_found() */
+    set_node_t *node;       /* node under construction, in case of longjmp() */
+    i16_t depth;            /* maximum depth of the skiplist */
+    ui64_t ran;             /* a precious trove of random bits */
+    set_rand_t gen;         /* random number generator state */
+    jmp_buf env;            /* setjmp() environment for allocation errors */
 #ifdef SET_TRACK
-    size_t allocs;          // number of allocations
-    size_t memory;          // total amount of allocated memory (>= requests)
+    size_t allocs;          /* number of allocations */
+    size_t memory;          /* total amount of allocated memory (>= requests) */
 #endif
 } set_t;
 
-// Memory allocation and deallocation. set_alloc(set, ptr, size) returns a
+/* Memory allocation and deallocation. set_alloc(set, ptr, size) returns a
 // pointer to an allocation of size bytes if ptr is NULL, or the previous
 // allocation ptr resized to size bytes. set_alloc() will never return NULL.
 // set_free(set, ptr) frees an allocation created by set_alloc(). These may be
-// used by the application. e.g. if allocation tracking is desired.
+// used by the application. e.g. if allocation tracking is desired. */
 #ifdef SET_TRACK
-// Track the number of allocations and the total backing memory size.
+/* Track the number of allocations and the total backing memory size. */
 #  if defined(_WIN32)
 #    include <malloc.h>
 #    define SET_ALLOC_SIZE(ptr) _msize(ptr)
@@ -162,7 +162,7 @@ void set_free(set_t *set, void *ptr) {
     }
 }
 #else
-// Without tracking.
+/* Without tracking. */
 void *set_alloc(set_t *set, void *ptr, size_t size) {
     void *mem = realloc(ptr, size);
     if (mem == NULL)
@@ -175,10 +175,10 @@ void set_free(set_t *set, void *ptr) {
 }
 #endif
 
-// --private-- Grow node's array right[] as needed to be able to hold at least
+/* --private-- Grow node's array right[] as needed to be able to hold at least
 // want links. If fill is true, assure that the first want links are filled in,
 // setting them to set->head if not previously filled in. Otherwise it is
-// assumed that the first want links are about to be filled in.
+// assumed that the first want links are about to be filled in. */
 void set_grow(set_t *set, set_node_t *node, int want, int fill) {
     if (node->size < want) {
         int more = node->size ? node->size : 1;
@@ -194,7 +194,7 @@ void set_grow(set_t *set, set_node_t *node, int want, int fill) {
     node->fill = (i16_t)want;
 }
 
-// --private-- Return a new node. key is left uninitialized.
+/* --private-- Return a new node. key is left uninitialized. */
 set_node_t *set_node(set_t *set) {
     set_node_t *node = set_alloc(set, NULL, sizeof(set_node_t));
     node->size = 0;
@@ -203,11 +203,11 @@ set_node_t *set_node(set_t *set) {
     return node;
 }
 
-// --private-- Free the list linked from head, along with the keys.
+/* --private-- Free the list linked from head, along with the keys. */
 void set_sweep(set_t *set) {
     set_node_t *step = set->head->right[0];
     while (step != set->head) {
-        set_node_t *next = step->right[0];      // save link to next node
+        set_node_t *next = step->right[0];      /* save link to next node */
         set_drop(set, step->key);
         set_free(set, step->right);
         set_free(set, step);
@@ -215,59 +215,59 @@ void set_sweep(set_t *set) {
     }
 }
 
-// Initialize a new set. set->env must be initialized using setjmp() before
+/* Initialize a new set. set->env must be initialized using setjmp() before
 // set_start() is called. A longjmp(set->env, ENOMEM) will be used to handle a
 // memory allocation failure during any of the operations. (See setjmp.h and
 // errno.h.) The set can still be used if this happens, assuming that it didn't
 // happen during set_start(). Whether set_start() completed or not, set_end()
-// can be used to free the set's memory after a longjmp().
+// can be used to free the set's memory after a longjmp(). */
 void set_start(set_t *set) {
 #ifdef SET_TRACK
     set->allocs = 0;
     set->memory = 0;
 #endif
-    set->head = set->path = set->node = NULL;   // in case set_node() fails
+    set->head = set->path = set->node = NULL;   /* in case set_node() fails */
     set->path = set_node(set);
     set->head = set_node(set);
-    set_grow(set, set->head, 1, 1); // one link back to head for an empty set
-    *(unsigned char *)&set->head->key = 137;    // set id
+    set_grow(set, set->head, 1, 1); /* one link back to head for an empty set */
+    *(unsigned char *)&set->head->key = 137;    /* set id */
     set->depth = 0;
     set_seed(&set->gen, ((ui64_t)(ptrdiff_t)set << 32) ^
                         ((ui64_t)time(NULL) << 12) ^ clock(), 0);
     set->ran = 1;
 }
 
-// Return true if *set appears to be in a usable state. If *set has been zeroed
-// out, then set_ok(set) will be false and set_end(set) will be safe.
+/* Return true if *set appears to be in a usable state. If *set has been zeroed
+// out, then set_ok(set) will be false and set_end(set) will be safe. */
 int set_ok(set_t *set) {
     return set->head != NULL &&
            set->head->right != NULL &&
            *(unsigned char *)&set->head->key == 137;
 }
 
-// Empty the set. This frees the memory used for the previous set contents.
-// After set_clear(), *set is ready for use, as if after a set_start().
+/* Empty the set. This frees the memory used for the previous set contents.
+// After set_clear(), *set is ready for use, as if after a set_start(). */
 void set_clear(set_t *set) {
     assert(set_ok(set) && "improper use");
 
-    // Free all the keys and their nodes.
+    /* Free all the keys and their nodes. */
     set_sweep(set);
 
-    // Leave the head and path allocations as is. Clear their contents, with
-    // head pointing to itself and setting depth to zero, for an empty set.
+    /* Leave the head and path allocations as is. Clear their contents, with
+    // head pointing to itself and setting depth to zero, for an empty set. */
     set->head->right[0] = set->head;
     set->head->fill = 1;
     set->path->fill = 0;
     set->depth = 0;
 }
 
-// Done using the set -- free all allocations. The only operation on *set
+/* Done using the set -- free all allocations. The only operation on *set
 // permitted after this is set_start(). Though another set_end() would do no
 // harm. This can be done at any time after a set_start(), or after a longjmp()
-// on any allocation failure, including during a set_start().
+// on any allocation failure, including during a set_start(). */
 void set_end(set_t *set) {
     if (set->head != NULL) {
-        // Empty the set and free the head node.
+        /* Empty the set and free the head node. */
         if (set->head->right != NULL) {
             set_sweep(set);
             set_free(set, set->head->right);
@@ -276,13 +276,13 @@ void set_end(set_t *set) {
         set->head = NULL;
     }
     if (set->path != NULL) {
-        // Free the path work area.
+        /* Free the path work area. */
         set_free(set, set->path->right);
         set_free(set, set->path);
         set->path = NULL;
     }
     if (set->node != NULL) {
-        // Free the node that was under construction when longjmp() hit.
+        /* Free the node that was under construction when longjmp() hit. */
         set_drop(set, set->node->key);
         set_free(set, set->node->right);
         set_free(set, set->node);
@@ -290,12 +290,12 @@ void set_end(set_t *set) {
     }
 }
 
-// Look for key. Return 1 if found or 0 if not. This also puts the path to get
-// there in set->path, for use by set_insert().
+/* Look for key. Return 1 if found or 0 if not. This also puts the path to get
+// there in set->path, for use by set_insert(). */
 int set_found(set_t *set, set_key_t key) {
     assert(set_ok(set) && "improper use");
 
-    // Start at depth and work down and right as determined by key comparisons.
+    /* Start at depth and work down and right as determined by key comparisons. */
     set_node_t *head = set->head, *here = head;
     int i = set->depth;
     set_grow(set, set->path, i + 1, 0);
@@ -306,25 +306,25 @@ int set_found(set_t *set, set_key_t key) {
         set->path->right[i] = here;
     } while (i--);
 
-    // See if the key matches.
+    /* See if the key matches. */
     here = here->right[0];
     return here != head && set_cmp(here->key, key) == 0;
 }
 
-// Insert the key key. Return 0 on success, or 1 if key is already in the set.
+/* Insert the key key. Return 0 on success, or 1 if key is already in the set. */
 int set_insert(set_t *set, set_key_t key) {
     assert(set_ok(set) && "improper use");
 
     if (set_found(set, key))
-        // That key is already in the set.
+        /* That key is already in the set. */
         return 1;
 
-    // Randomly generate a new level-- level 0 with probability 1/2, 1 with
-    // probability 1/4, 2 with probability 1/8, etc.
+    /* Randomly generate a new level-- level 0 with probability 1/2, 1 with
+    // probability 1/4, 2 with probability 1/8, etc. */
     int level = 0;
     for (;;) {
         if (set->ran == 1)
-            // Ran out. Get another 32 random bits.
+            /* Ran out. Get another 32 random bits. */
             set->ran = set_rand(&set->gen) | (1ULL << 32);
         int bit = set->ran & 1;
         set->ran >>= 1;
@@ -335,14 +335,14 @@ int set_insert(set_t *set, set_key_t key) {
         level++;
     }
     if (level > set->depth) {
-        // The maximum depth is now deeper. Update the structures.
+        /* The maximum depth is now deeper. Update the structures. */
         set_grow(set, set->path, level + 1, 1);
         set_grow(set, set->head, level + 1, 1);
         set->depth = (i16_t)level;
     }
 
-    // Make a new node for the provided key, and insert it in the lists up to
-    // and including level.
+    /* Make a new node for the provided key, and insert it in the lists up to
+    // and including level. */
     set->node = set_node(set);
     set->node->key = key;
     set_grow(set, set->node, level + 1, 0);
@@ -357,5 +357,5 @@ int set_insert(set_t *set, set_key_t key) {
 
 #else
 #error ** another skiplist set already created here
-// Would need to implement a prefix in order to support multiple sets.
+/* Would need to implement a prefix in order to support multiple sets. */
 #endif
diff --git a/contrib/minizip/test/CMakeLists.txt b/contrib/minizip/test/CMakeLists.txt
new file mode 100644
index 000000000..2f86ee34b
--- /dev/null
+++ b/contrib/minizip/test/CMakeLists.txt
@@ -0,0 +1,121 @@
+# if we are built from with zlib, use this path's)
+if(DEFINED ZLIB_BUILD_SHARED)
+    set(WORK_DIR ${zlib_BINARY_DIR})
+    set(inst_setup minizip_minizip_install)
+else(DEFINED ZLIB_BUILD_SHARED)
+    set(WORK_DIR ${minizip_BINARY_DIR})
+    set(inst_setup minizip_minizip_install)
+    set(ZLIB_ARG "-DZLIB_DIR=${ZLIB_DIR}")
+
+    add_test(
+        NAME minizip_install
+        COMMAND ${CMAKE_COMMAND} --install ${minizip_BINARY_DIR} --prefix
+                ${CMAKE_CURRENT_BINARY_DIR}/test_install --config $<CONFIG>
+        WORKING_DIRECTORY ${minizip_BINARY_DIR})
+
+    set_tests_properties(minizip_install PROPERTIES FIXTURES_SETUP
+                                                    minizip_install)
+endif(DEFINED ZLIB_BUILD_SHARED)
+
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test)
+
+configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/find_package_test.cmake.in
+    ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test/CMakeLists.txt @ONLY)
+
+configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/add_subdirectory_test.cmake.in
+    ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test/CMakeLists.txt @ONLY)
+
+configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/add_subdirectory_exclude_test.cmake.in
+    ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test/CMakeLists.txt
+    @ONLY)
+
+# CMAKE_GENERATOR_PLATFORM doesn't work in the if
+set(GENERATOR ${CMAKE_GENERATOR_PLATFORM})
+
+if(GENERATOR)
+    set(PLATFORM "-A ${GENERATOR}")
+endif(GENERATOR)
+
+#
+# findpackage_test
+#
+add_test(
+    NAME minizip_find_package_configure
+    COMMAND
+        ${CMAKE_COMMAND} ${PLATFORM}
+        -B${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build
+        -DCMAKE_BUILD_TYPE=$<CONFIG> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+        -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
+        -DCMAKE_INSTALL_PREFIX=${WORK_DIR}/test/test_install ${ZLIB_ARG}
+        --fresh -G "${CMAKE_GENERATOR}"
+        -S${CMAKE_CURRENT_BINARY_DIR}/findpackage_test)
+
+add_test(
+    NAME minizip_find_package_build
+    COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build)
+
+set_tests_properties(
+    minizip_find_package_configure PROPERTIES FIXTURES_REQUIRED ${inst_setup}
+                                              FIXTURES_SETUP mzfp_config)
+
+set_tests_properties(minizip_find_package_build PROPERTIES FIXTURES_REQUIRED
+                                                           mzfp_config)
+
+#
+# add_subdirectory_test
+#
+add_test(
+    NAME minizip_add_subdirectory_configure
+    COMMAND
+        ${CMAKE_COMMAND} ${PLATFORM}
+        -B${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test_build
+        -DCMAKE_BUILD_TYPE=$<CONFIG> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+        -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
+        -DCMAKE_INSTALL_PREFIX=${WORK_DIR}/test/test_install ${ZLIB_ARG}
+        --fresh -G "${CMAKE_GENERATOR}"
+        -S${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test)
+
+add_test(
+    NAME minizip_add_subdirectory_build
+    COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test_build)
+
+set_tests_properties(
+    minizip_add_subdirectory_configure
+    PROPERTIES FIXTURES_REQUIRED ${inst_setup} FIXTURES_SETUP mzas_config)
+
+set_tests_properties(minizip_add_subdirectory_build PROPERTIES FIXTURES_REQUIRED
+                                                               mzas_config)
+
+#
+# add_subdirectory_exclude_test
+#
+add_test(
+    NAME minizip_add_subdirectory_exclude_configure
+    COMMAND
+        ${CMAKE_COMMAND} ${PLATFORM}
+        -B${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test_build
+        -DCMAKE_BUILD_TYPE=$<CONFIG> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+        -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
+        -DCMAKE_INSTALL_PREFIX=${WORK_DIR}/test/test_install ${ZLIB_ARG}
+        --fresh -G "${CMAKE_GENERATOR}"
+        -S${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test)
+
+add_test(
+    NAME minizip_add_subdirectory_exclude_build
+    COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
+    WORKING_DIRECTORY
+        ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test_build)
+
+set_tests_properties(
+    minizip_add_subdirectory_exclude_configure
+    PROPERTIES FIXTURES_REQUIRED ${inst_setup} FIXTURES_SETUP mzasx_config)
+
+set_tests_properties(minizip_add_subdirectory_exclude_build
+                     PROPERTIES FIXTURES_REQUIRED mzasx_config)
diff --git a/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in b/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in
new file mode 100644
index 000000000..2b9fc68f3
--- /dev/null
+++ b/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in
@@ -0,0 +1,29 @@
+cmake_minimum_required(VERSION 3.12...3.31)
+
+project(
+    minizip_add_subdirectory_exclude_from_all
+    LANGUAGES C
+    VERSION @minizip_VERSION@)
+
+option(MINIZIP_BUILD_TESTING "" OFF)
+option(MINIZIP_BUILD_SHARED "" @MINIZIP_BUILD_SHARED@)
+option(MINIZIP_BUILD_STATIC "" @MINIZIP_BUILD_STATIC@)
+option(MINIZIP_ENABLE_BZIP2 "" @MINIZIP_ENABLE_BZIP2@)
+
+add_subdirectory(@minizip_SOURCE_DIR@ ${CMAKE_CURRENT_BINARY_DIR}/minizip
+                 EXCLUDE_FROM_ALL)
+
+set(MINIZIP_SRCS
+    @minizip_SOURCE_DIR@/ioapi.c
+    $<$<BOOL:${WIN32}>:@minizip_SOURCE_DIR@/iowin32.c>
+    @minizip_SOURCE_DIR@/minizip.c @minizip_SOURCE_DIR@/zip.c)
+
+if(MINIZIP_BUILD_SHARED)
+    add_executable(test_example ${MINIZIP_SRCS})
+    target_link_libraries(test_example MINIZIP::minizip)
+endif(MINIZIP_BUILD_SHARED)
+
+if(MINIZIP_BUILD_STATIC)
+    add_executable(test_example_static ${MINIZIP_SRCS})
+    target_link_libraries(test_example_static MINIZIP::minizipstatic)
+endif(MINIZIP_BUILD_STATIC)
diff --git a/contrib/minizip/test/add_subdirectory_test.cmake.in b/contrib/minizip/test/add_subdirectory_test.cmake.in
new file mode 100644
index 000000000..ca49895ba
--- /dev/null
+++ b/contrib/minizip/test/add_subdirectory_test.cmake.in
@@ -0,0 +1,28 @@
+cmake_minimum_required(VERSION 3.12...3.31)
+
+project(
+    minizip_add_subdirectory_exclude_from_all
+    LANGUAGES C
+    VERSION @minizip_VERSION@)
+
+option(MINIZIP_BUILD_TESTING "" OFF)
+option(MINIZIP_BUILD_SHARED "" @MINIZIP_BUILD_SHARED@)
+option(MINIZIP_BUILD_STATIC "" @MINIZIP_BUILD_STATIC@)
+option(MINIZIP_ENABLE_BZIP2 "" @MINIZIP_ENABLE_BZIP2@)
+
+add_subdirectory(@minizip_SOURCE_DIR@ ${CMAKE_CURRENT_BINARY_DIR}/minizip)
+
+set(MINIZIP_SRCS
+    @minizip_SOURCE_DIR@/ioapi.c
+    $<$<BOOL:${WIN32}>:@minizip_SOURCE_DIR@/iowin32.c>
+    @minizip_SOURCE_DIR@/minizip.c @minizip_SOURCE_DIR@/zip.c)
+
+if(MINIZIP_BUILD_SHARED)
+    add_executable(test_example ${MINIZIP_SRCS})
+    target_link_libraries(test_example MINIZIP::minizip)
+endif(MINIZIP_BUILD_SHARED)
+
+if(MINIZIP_BUILD_STATIC)
+    add_executable(test_example_static ${MINIZIP_SRCS})
+    target_link_libraries(test_example_static MINIZIP::minizipstatic)
+endif(MINIZIP_BUILD_STATIC)
diff --git a/contrib/minizip/test/find_package_test.cmake.in b/contrib/minizip/test/find_package_test.cmake.in
new file mode 100644
index 000000000..55272ba72
--- /dev/null
+++ b/contrib/minizip/test/find_package_test.cmake.in
@@ -0,0 +1,25 @@
+cmake_minimum_required(VERSION 3.12...3.31)
+
+project(
+    minizip_find_package
+    LANGUAGES C
+    VERSION @minizip_VERSION@)
+
+option(MINIZIP_BUILD_SHARED "" @MINIZIP_BUILD_SHARED@)
+option(MINIZIP_BUILD_STATIC "" @MINIZIP_BUILD_STATIC@)
+find_package(minizip ${minizip_VERSION} CONFIG REQUIRED)
+
+set(MINIZIP_SRCS
+    @minizip_SOURCE_DIR@/ioapi.c
+    $<$<BOOL:${WIN32}>:@minizip_SOURCE_DIR@/iowin32.c>
+    @minizip_SOURCE_DIR@/minizip.c @minizip_SOURCE_DIR@/zip.c)
+
+if(MINIZIP_BUILD_SHARED)
+    add_executable(test_example ${MINIZIP_SRCS})
+    target_link_libraries(test_example MINIZIP::minizip)
+endif(MINIZIP_BUILD_SHARED)
+
+if(MINIZIP_BUILD_STATIC)
+    add_executable(test_example_static ${MINIZIP_SRCS})
+    target_link_libraries(test_example_static MINIZIP::minizipstatic)
+endif(MINIZIP_BUILD_STATIC)
diff --git a/contrib/minizip/test/test_helper.cm b/contrib/minizip/test/test_helper.cm
new file mode 100644
index 000000000..99ae45e2f
--- /dev/null
+++ b/contrib/minizip/test/test_helper.cm
@@ -0,0 +1,32 @@
+if(CREATE_SHARED)
+    file(REMOVE ./test_file_shared.orig ./test_file_shared.zip)
+    file(WRITE ./test_file_shared.txt "Hello Hello Hello")
+endif(CREATE_SHARED)
+
+if(MOVE_SHARED)
+    file(RENAME ./test_file_shared.txt ./test_file_shared.orig)
+endif(MOVE_SHARED)
+
+if(DELETE_SHARED)
+    file(REMOVE
+        ./test_file_shared.txt
+        ./test_file_shared.orig
+        ./test_file_shared.zip)
+endif(DELETE_SHARED)
+
+if(CREATE_STATIC)
+    file(REMOVE ./test_file_static.orig ./test_file_static.zip)
+    file(WRITE ./test_file_static.txt "Hello Hello Hello")
+endif(CREATE_STATIC)
+
+if(MOVE_STATIC)
+    file(RENAME ./test_file_static.txt ./test_file_static.orig)
+endif(MOVE_STATIC)
+
+if(DELETE_STATIC)
+    file(REMOVE
+        ./test_file_static.txt
+        ./test_file_static.orig
+        ./test_file_static.zip)
+endif(DELETE_STATIC)
+
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
index a2ee14bdd..e9088bd54 100644
--- a/contrib/minizip/unzip.c
+++ b/contrib/minizip/unzip.c
@@ -842,7 +842,7 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file,
     if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
         err=UNZ_ERRNO;
 
-                // relative offset of local header
+                /* relative offset of local header */
     if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
         err=UNZ_ERRNO;
     file_info_internal.offset_curfile = uL;
@@ -865,7 +865,7 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file,
         lSeek -= uSizeRead;
     }
 
-    // Read extrafield
+    /* Read extrafield */
     if ((err==UNZ_OK) && (extraField!=NULL))
     {
         ZPOS64_T uSizeRead ;
@@ -896,7 +896,7 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file,
     {
                                 uLong acc = 0;
 
-        // since lSeek now points to after the extra field we need to move back
+        /* since lSeek now points to after the extra field we need to move back */
         lSeek -= file_info.size_file_extra;
 
         if (lSeek!=0)
@@ -1525,10 +1525,10 @@ extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file) {
     file_in_zip64_read_info_s* pfile_in_zip_read_info;
     s=(unz64_s*)file;
     if (file==NULL)
-        return 0; //UNZ_PARAMERROR;
+        return 0; /* UNZ_PARAMERROR; */
     pfile_in_zip_read_info=s->pfile_in_zip_read;
     if (pfile_in_zip_read_info==NULL)
-        return 0; //UNZ_PARAMERROR;
+        return 0; /* UNZ_PARAMERROR; */
     return pfile_in_zip_read_info->pos_in_zipfile +
                          pfile_in_zip_read_info->byte_before_the_zipfile;
 }
@@ -1697,7 +1697,7 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) {
             if (err!=BZ_OK)
               break;
 #endif
-        } // end Z_BZIP2ED
+        } /* end Z_BZIP2ED */
         else
         {
             ZPOS64_T uTotalOutBefore,uTotalOutAfter;
@@ -1940,7 +1940,7 @@ extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) {
     unz64_s* s;
 
     if (file==NULL)
-          return 0; //UNZ_PARAMERROR;
+          return 0; /* UNZ_PARAMERROR; */
     s=(unz64_s*)file;
     if (!s->current_file_ok)
       return 0;
@@ -1954,7 +1954,7 @@ extern uLong ZEXPORT unzGetOffset(unzFile file) {
     ZPOS64_T offset64;
 
     if (file==NULL)
-          return 0; //UNZ_PARAMERROR;
+          return 0; /* UNZ_PARAMERROR; */
     offset64 = unzGetOffset64(file);
     return (uLong)offset64;
 }
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index 93d2612e2..103f325d3 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -52,7 +52,7 @@
 #endif
 
 #ifndef Z_BUFSIZE
-#define Z_BUFSIZE (64*1024) //(16384)
+#define Z_BUFSIZE (64*1024) /* (16384) */
 #endif
 
 #ifndef Z_MAXFILENAMEINZIP
@@ -71,7 +71,7 @@
 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
 
 
-// NOT sure that this work on ALL platform
+/* NOT sure that this work on ALL platform */
 #define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
 
 #ifndef SEEK_CUR
@@ -125,16 +125,16 @@ typedef struct linkedlist_data_s
 } linkedlist_data;
 
 
-// zipAlreadyThere() set functions for a set of zero-terminated strings, and
-// a block_t type for reading the central directory datablocks.
+/* zipAlreadyThere() set functions for a set of zero-terminated strings, and
+// a block_t type for reading the central directory datablocks. */
 typedef char *set_key_t;
 #define set_cmp(a, b) strcmp(a, b)
 #define set_drop(s, k) set_free(s, k)
 #include "skipset.h"
 typedef struct {
-    unsigned char *next;        // next byte in datablock data
-    size_t left;                // number of bytes left in data (at least)
-    linkedlist_datablock_internal *node;    // current datablock
+    unsigned char *next;        /* next byte in datablock data */
+    size_t left;                /* number of bytes left in data (at least) */
+    linkedlist_datablock_internal *node;    /* current datablock */
 } block_t;
 
 
@@ -189,9 +189,9 @@ typedef struct
     char *globalcomment;
 #endif
 
-    // Support for zipAlreadyThere().
-    set_t set;              // set for detecting name collisions
-    block_t block;          // block for reading the central directory
+    /* Support for zipAlreadyThere(). */
+    set_t set;              /* set for detecting name collisions */
+    block_t block;          /* block for reading the central directory */
 
 } zip64_internal;
 
@@ -283,7 +283,7 @@ local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
     return ZIP_OK;
 }
 
-// zipAlreadyThere() operations. "set" in the zip internal structure keeps the
+/* zipAlreadyThere() operations. "set" in the zip internal structure keeps the
 // set of names that are in the under-construction central directory so far. A
 // skipset provides ~O(log n) time insertion and searching. Central directory
 // records, stored in a linked list of allocated memory datablocks, is read
@@ -295,81 +295,81 @@ local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
 // datablocks.
 
 // Initialize *block to the head of list. This should only be called once the
-// list has at least some data in it, i.e. list->first_block is not NULL.
+// list has at least some data in it, i.e. list->first_block is not NULL. */
 local void block_init(block_t *block, linkedlist_data *list) {
     block->node = list->first_block;
     block->next = block->node->data;
     block->left = block->node->filled_in_this_block;
 }
 
-// Mark *block as bad, with all subsequent reads returning end, even if more
+/* Mark *block as bad, with all subsequent reads returning end, even if more
 // data is added to the datablocks. This is invoked if the central directory is
-// invalid, so there is no longer any point in attempting to interpret it.
+// invalid, so there is no longer any point in attempting to interpret it. */
 local void block_stop(block_t *block) {
     block->left = 0;
     block->next = NULL;
 }
 
-// Return true if *block has reached the end of the data in the datablocks.
+/* Return true if *block has reached the end of the data in the datablocks. */
 local int block_end(block_t *block) {
     linkedlist_datablock_internal *node = block->node;
     if (node == NULL)
-        // This block was previously terminated with extreme prejudice.
+        /* This block was previously terminated with extreme prejudice. */
         return 1;
     if (block->next < node->data + node->filled_in_this_block)
-        // There are more bytes to read in the current datablock.
+        /* There are more bytes to read in the current datablock. */
         return 0;
     while (node->next_datablock != NULL) {
         if (node->filled_in_this_block != 0)
-            // There are some bytes in a later datablock.
+            /* There are some bytes in a later datablock. */
             return 0;
         node = node->next_datablock;
     }
-    // Reached the end of the list of datablocks. There's nothing.
+    /* Reached the end of the list of datablocks. There's nothing. */
     return 1;
 }
 
-// Return one byte from *block, or -1 if the end is reached.
+/* Return one byte from *block, or -1 if the end is reached. */
 local int block_get(block_t *block) {
     while (block->left == 0) {
         if (block->node == NULL)
-            // We've been marked bad. Return end.
+            /* We've been marked bad. Return end. */
             return -1;
-        // Update left in case more was filled in since we were last here.
+        /* Update left in case more was filled in since we were last here. */
         block->left = block->node->filled_in_this_block -
                       (block->next - block->node->data);
         if (block->left != 0)
-            // There was indeed more data appended in the current datablock.
+            /* There was indeed more data appended in the current datablock. */
             break;
         if (block->node->next_datablock == NULL)
-            // No more data here, and there is no next datablock. At the end.
+            /* No more data here, and there is no next datablock. At the end. */
             return -1;
-        // Try the next datablock for more data.
+        /* Try the next datablock for more data. */
         block->node = block->node->next_datablock;
         block->next = block->node->data;
         block->left = block->node->filled_in_this_block;
     }
-    // We have a byte to return.
+    /* We have a byte to return. */
     block->left--;
     return *block->next++;
 }
 
-// Return a 16-bit unsigned little-endian value from block, or a negative value
-// if the end is reached.
+/* Return a 16-bit unsigned little-endian value from block, or a negative value
+// if the end is reached. */
 local long block_get2(block_t *block) {
     long got = block_get(block);
     return got | ((unsigned long)block_get(block) << 8);
 }
 
-// Read up to len bytes from block into buf. Return the number of bytes read.
+/* Read up to len bytes from block into buf. Return the number of bytes read. */
 local size_t block_read(block_t *block, unsigned char *buf, size_t len) {
     size_t need = len;
     while (need) {
         if (block->left == 0) {
-            // Get a byte to update and step through the linked list as needed.
+            /* Get a byte to update and step through the linked list as needed. */
             int got = block_get(block);
             if (got == -1)
-                // Reached the end.
+                /* Reached the end. */
                 break;
             *buf++ = (unsigned char)got;
             need--;
@@ -382,11 +382,11 @@ local size_t block_read(block_t *block, unsigned char *buf, size_t len) {
         buf += take;
         need -= take;
     }
-    return len - need;      // return the number of bytes copied
+    return len - need;      /* return the number of bytes copied */
 }
 
-// Skip n bytes in block. Return 0 on success or -1 if there are less than n
-// bytes to the end.
+/* Skip n bytes in block. Return 0 on success or -1 if there are less than n
+// bytes to the end. */
 local int block_skip(block_t *block, size_t n) {
     while (n > block->left) {
         n -= block->left;
@@ -401,103 +401,103 @@ local int block_skip(block_t *block, size_t n) {
     return 0;
 }
 
-// Process the next central directory record at *block. Return the allocated,
+/* Process the next central directory record at *block. Return the allocated,
 // zero-terminated file name, or NULL for end of input or invalid data. If
-// invalid, *block is marked bad. This uses *set for the allocation of memory.
+// invalid, *block is marked bad. This uses *set for the allocation of memory. */
 local char *block_central_name(block_t *block, set_t *set) {
     char *name = NULL;
     for (;;) {
         if (block_end(block))
-            // At the end of the central directory (so far).
+            /* At the end of the central directory (so far). */
             return NULL;
 
-        // Check for a central directory record signature.
+        /* Check for a central directory record signature. */
         if (block_get2(block) != (CENTRALHEADERMAGIC & 0xffff) ||
             block_get2(block) != (CENTRALHEADERMAGIC >> 16))
-            // Incorrect signature.
+            /* Incorrect signature. */
             break;
 
-        // Go through the remaining fixed-length portion of the record,
-        // extracting the lengths of the three variable-length fields.
+        /* Go through the remaining fixed-length portion of the record,
+        // extracting the lengths of the three variable-length fields. */
         block_skip(block, 24);
-        unsigned flen = block_get2(block);      // file name length
-        unsigned xlen = block_get2(block);      // extra field length
-        unsigned clen = block_get2(block);      // comment field length
+        unsigned flen = block_get2(block);      /* file name length */
+        unsigned xlen = block_get2(block);      /* extra field length */
+        unsigned clen = block_get2(block);      /* comment field length */
         if (block_skip(block, 12) == -1)
-            // Premature end of the record.
+            /* Premature end of the record. */
             break;
 
-        // Extract the name and skip over the extra and comment fields.
+        /* Extract the name and skip over the extra and comment fields. */
         name = set_alloc(set, NULL, flen + 1);
         if (block_read(block, (unsigned char *)name, flen) < flen ||
             block_skip(block, xlen + clen) == -1)
-            // Premature end of the record.
+            /* Premature end of the record. */
             break;
 
-        // Check for embedded nuls in the name.
+        /* Check for embedded nuls in the name. */
         if (memchr(name, 0, flen) != NULL) {
-            // This name can never match the zero-terminated name provided to
+            /* This name can never match the zero-terminated name provided to
             // zipAlreadyThere(), so we discard it and go back to get another
             // name. (Who the heck is putting nuls inside their zip file entry
-            // names anyway?)
+            // names anyway?) */
             set_free(set, name);
             continue;
         }
 
-        // All good. Return the zero-terminated file name.
+        /* All good. Return the zero-terminated file name. */
         name[flen] = 0;
         return name;
     }
 
-    // Invalid signature or premature end of the central directory record.
-    // Abandon trying to process the central directory.
+    /* Invalid signature or premature end of the central directory record.
+    // Abandon trying to process the central directory. */
     set_free(set, name);
     block_stop(block);
     return NULL;
 }
 
-// Return 0 if name is not in the central directory so far, 1 if it is, -1 if
+/* Return 0 if name is not in the central directory so far, 1 if it is, -1 if
 // the central directory is invalid, -2 if out of memory, or ZIP_PARAMERROR if
-// file is NULL.
+// file is NULL. */
 extern int ZEXPORT zipAlreadyThere(zipFile file, char const *name) {
     zip64_internal *zip = file;
     if (zip == NULL)
         return ZIP_PARAMERROR;
     if (zip->central_dir.first_block == NULL)
-        // No central directory yet, so no, name isn't there.
+        /* No central directory yet, so no, name isn't there. */
         return 0;
     if (setjmp(zip->set.env)) {
-        // Memory allocation failure.
+        /* Memory allocation failure. */
         set_end(&zip->set);
         return -2;
     }
     if (!set_ok(&zip->set)) {
-        // This is the first time here with some central directory content. We
-        // construct this set of names only on demand. Prepare set and block.
+        /* This is the first time here with some central directory content. We
+        // construct this set of names only on demand. Prepare set and block. */
         set_start(&zip->set);
         block_init(&zip->block, &zip->central_dir);
     }
 
-    // Update the set of names from the current central directory contents.
+    /* Update the set of names from the current central directory contents.
     // This reads any new central directory records since the last time we were
-    // here.
+    // here. */
     for (;;) {
         char *there = block_central_name(&zip->block, &zip->set);
         if (there == NULL) {
             if (zip->block.next == NULL)
-                // The central directory is invalid.
+                /* The central directory is invalid. */
                 return -1;
             break;
         }
 
-        // Add there to the set.
+        /* Add there to the set. */
         if (set_insert(&zip->set, there))
-            // There's already a duplicate in the central directory! We'll just
-            // let this be and carry on.
+            /* There's already a duplicate in the central directory! We'll just
+            // let this be and carry on. */
             set_free(&zip->set, there);
     }
 
-    // Return true if name is in the central directory.
+    /* Return true if name is in the central directory. */
     size_t len = strlen(name);
     char *copy = set_alloc(&zip->set, NULL, len + 1);
     strcpy(copy, name);
@@ -792,7 +792,7 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
 
     for (i=(int)uReadSize-3; (i--)>0;)
     {
-      // Signature "0x07064b50" Zip64 end of central directory locator
+      /* Signature "0x07064b50" Zip64 end of central directory locator */
       if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
       {
         uPosFound = uReadPos+(unsigned)i;
@@ -840,7 +840,7 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
   if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
     return 0;
 
-  if (uL != 0x06064b50) // signature of 'Zip64 end of central directory'
+  if (uL != 0x06064b50) /* signature of 'Zip64 end of central directory' */
     return 0;
 
   return relativeOffset;
@@ -869,7 +869,7 @@ local int LoadCentralDirectoryRecord(zip64_internal* pziinit) {
 
   int hasZIP64Record = 0;
 
-  // check first if we find a ZIP64 record
+  /* check first if we find a ZIP64 record */
   central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
   if(central_pos > 0)
   {
@@ -935,13 +935,13 @@ local int LoadCentralDirectoryRecord(zip64_internal* pziinit) {
     if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
       err=ZIP_ERRNO;
 
-    // TODO..
-    // read the comment from the standard central header.
+    /* TODO..
+    // read the comment from the standard central header. */
     size_comment = 0;
   }
   else
   {
-    // Read End of central Directory info
+    /* Read End of central Directory info */
     if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
       err=ZIP_ERRNO;
 
@@ -1084,7 +1084,7 @@ extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* glo
     ziinit.number_entry = 0;
     ziinit.add_position_when_writing_offset = 0;
     init_linkedlist(&(ziinit.central_dir));
-    memset(&ziinit.set, 0, sizeof(set_t));  // make sure set appears dormant
+    memset(&ziinit.set, 0, sizeof(set_t));  /* make sure set appears dormant */
 
 
 
@@ -1100,7 +1100,7 @@ extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* glo
     ziinit.globalcomment = NULL;
     if (append == APPEND_STATUS_ADDINZIP)
     {
-      // Read and Cache Central Directory Records
+      /* Read and Cache Central Directory Records */
       err = LoadCentralDirectoryRecord(&ziinit);
     }
 
@@ -1184,7 +1184,7 @@ local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt s
   if (err==ZIP_OK)
     err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
 
-  // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later
+  /* CRC / Compressed size / Uncompressed size will be filled in later and rewritten later */
   if (err==ZIP_OK)
     err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
   if (err==ZIP_OK)
@@ -1228,13 +1228,13 @@ local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt s
 
   if ((err==ZIP_OK) && (zi->ci.zip64))
   {
-      // write the Zip64 extended info
+      /* write the Zip64 extended info */
       short HeaderID = 1;
       short DataSize = 16;
       ZPOS64_T CompressedSize = 0;
       ZPOS64_T UncompressedSize = 0;
 
-      // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file)
+      /* Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) */
       zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
 
       err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)HeaderID,2);
@@ -1284,14 +1284,14 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
       return ZIP_PARAMERROR;
 #endif
 
-    // The filename and comment length must fit in 16 bits.
+    /* The filename and comment length must fit in 16 bits. */
     if ((filename!=NULL) && (strlen(filename)>0xffff))
         return ZIP_PARAMERROR;
     if ((comment!=NULL) && (strlen(comment)>0xffff))
         return ZIP_PARAMERROR;
-    // The extra field length must fit in 16 bits. If the member also requires
+    /* The extra field length must fit in 16 bits. If the member also requires
     // a Zip64 extra block, that will also need to fit within that 16-bit
-    // length, but that will be checked for later.
+    // length, but that will be checked for later. */
     if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff))
         return ZIP_PARAMERROR;
 
@@ -1343,7 +1343,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
     zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
 
     zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
-    zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data
+    zi->ci.size_centralExtraFree = 32; /* Extra space we have reserved in case we need to add ZIP64 extra info data */
 
     zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
 
@@ -1438,7 +1438,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
         else if(zi->ci.method == Z_BZIP2ED)
         {
 #ifdef HAVE_BZIP2
-            // Init BZip stuff here
+            /* Init BZip stuff here */
           zi->ci.bstream.bzalloc = 0;
           zi->ci.bstream.bzfree = 0;
           zi->ci.bstream.opaque = (voidpf)0;
@@ -1640,7 +1640,7 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned i
         if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
         {
           uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
-//          uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
+/*          uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; */
           err=BZ2_bzCompress(&zi->ci.bstream,  BZ_RUN);
 
           zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
@@ -1698,7 +1698,7 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned i
                   zi->ci.pos_in_buffered_data += copy_this;
               }
           }
-      }// while(...)
+      }/* while(...) */
     }
 
     return err;
@@ -1804,7 +1804,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
     compressed_size += zi->ci.crypt_header_size;
 #    endif
 
-    // update Current Item crc and sizes,
+    /* update Current Item crc and sizes, */
     if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
     {
       /*version Made by*/
@@ -1822,7 +1822,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
     else
       zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
 
-    /// set internal file attributes field
+    /* set internal file attributes field */
     if (zi->ci.stream.data_type == Z_ASCII)
         zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
 
@@ -1831,15 +1831,15 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
     else
       zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
 
-    // Add ZIP64 extra info field for uncompressed size
+    /* Add ZIP64 extra info field for uncompressed size */
     if(uncompressed_size >= 0xffffffff)
       datasize += 8;
 
-    // Add ZIP64 extra info field for compressed size
+    /* Add ZIP64 extra info field for compressed size */
     if(compressed_size >= 0xffffffff)
       datasize += 8;
 
-    // Add ZIP64 extra info field for relative offset to local file header of current file
+    /* Add ZIP64 extra info field for relative offset to local file header of current file */
     if(zi->ci.pos_local_header >= 0xffffffff)
       datasize += 8;
 
@@ -1849,16 +1849,16 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
 
       if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
       {
-        // we cannot write more data to the buffer that we have room for.
+        /* we cannot write more data to the buffer that we have room for. */
         return ZIP_BADZIPFILE;
       }
 
       p = zi->ci.central_header + zi->ci.size_centralheader;
 
-      // Add Extra Information Header for 'ZIP64 information'
-      zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID
+      /* Add Extra Information Header for 'ZIP64 information' */
+      zip64local_putValue_inmemory(p, 0x0001, 2); /* HeaderID */
       p += 2;
-      zip64local_putValue_inmemory(p, datasize, 2); // DataSize
+      zip64local_putValue_inmemory(p, datasize, 2); /* DataSize */
       p += 2;
 
       if(uncompressed_size >= 0xffffffff)
@@ -1879,13 +1879,13 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
         p += 8;
       }
 
-      // Update how much extra free space we got in the memory buffer
+      /* Update how much extra free space we got in the memory buffer
       // and increase the centralheader size so the new ZIP64 fields are included
-      // ( 4 below is the size of HeaderID and DataSize field )
+      // ( 4 below is the size of HeaderID and DataSize field ) */
       zi->ci.size_centralExtraFree -= datasize + 4;
       zi->ci.size_centralheader += datasize + 4;
 
-      // Update the extra info size field
+      /* Update the extra info size field */
       zi->ci.size_centralExtra += datasize + 4;
       zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
     }
@@ -1897,7 +1897,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
 
     if (err==ZIP_OK)
     {
-        // Update the LocalFileHeader with the new values.
+        /* Update the LocalFileHeader with the new values. */
 
         ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
 
@@ -1911,7 +1911,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
         {
           if(zi->ci.pos_zip64extrainfo > 0)
           {
-            // Update the size in the ZIP64 extended field.
+            /* Update the size in the ZIP64 extended field. */
             if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
               err = ZIP_ERRNO;
 
@@ -1922,7 +1922,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
               err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
           }
           else
-              err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal
+              err = ZIP_BADZIPFILE; /* Caller passed zip64 = 0, so no room for zip64 info -> fatal */
         }
         else
         {
@@ -1976,7 +1976,7 @@ local int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_
   err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
 
   if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
-    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ?
+    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); /* why ZPOS64_T of this ? */
 
   if (err==ZIP_OK) /* version made by */
     err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
@@ -2023,7 +2023,7 @@ local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centr
   {
     {
       if(zi->number_entry >= 0xFFFF)
-        err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
+        err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); /* use value in ZIP64 record */
       else
         err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
     }
@@ -2032,7 +2032,7 @@ local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centr
   if (err==ZIP_OK) /* total number of entries in the central dir */
   {
     if(zi->number_entry >= 0xFFFF)
-      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
+      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); /* use value in ZIP64 record */
     else
       err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
   }
@@ -2112,7 +2112,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) {
     }
     free_linkedlist(&(zi->central_dir));
 
-    set_end(&zi->set);          // set was zeroed, so this is safe
+    set_end(&zi->set);          /* set was zeroed, so this is safe */
 
     pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
     if(pos >= 0xffffffff || zi->number_entry >= 0xFFFF)
@@ -2162,13 +2162,13 @@ extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHea
     header = *(short*)p;
     dataSize = *(((short*)p)+1);
 
-    if( header == sHeader ) // Header found.
+    if( header == sHeader ) /* Header found. */
     {
-      p += dataSize + 4; // skip it. do not copy to temp buffer
+      p += dataSize + 4; /* skip it. do not copy to temp buffer */
     }
     else
     {
-      // Extra Info block should not be removed, So copy it to the temp buffer.
+      /* Extra Info block should not be removed, So copy it to the temp buffer. */
       memcpy(pTmp, p, dataSize + 4);
       p += dataSize + 4;
       size += dataSize + 4;
@@ -2178,14 +2178,14 @@ extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHea
 
   if(size < *dataLen)
   {
-    // clean old extra info block.
+    /* clean old extra info block. */
     memset(pData,0, *dataLen);
 
-    // copy the new extra info block over the old
+    /* copy the new extra info block over the old */
     if(size > 0)
       memcpy(pData, pNewHeader, size);
 
-    // set the new extra info size
+    /* set the new extra info size */
     *dataLen = size;
 
     retVal = ZIP_OK;
diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h
index 1f7f0b263..9526eacd1 100644
--- a/contrib/minizip/zip.h
+++ b/contrib/minizip/zip.h
@@ -44,7 +44,7 @@
 extern "C" {
 #endif
 
-//#define HAVE_BZIP2
+/* #define HAVE_BZIP2 */
 
 #ifndef _ZLIB_H
 #include "zlib.h"
diff --git a/infback.c b/infback.c
index fd02e7090..6c7a034a7 100644
--- a/infback.c
+++ b/infback.c
@@ -46,7 +46,7 @@ int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
 #ifdef Z_SOLO
         return Z_STREAM_ERROR;
 #else
-    strm->zfree = zcfree;
+        strm->zfree = zcfree;
 #endif
     state = (struct inflate_state FAR *)ZALLOC(strm, 1,
                                                sizeof(struct inflate_state));
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 000000000..0d2844d8c
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,265 @@
+function(ZLIB_findTestEnv testName)
+    set(testEnv "PATH=")
+
+    if(MSVC OR MINGW)
+        set(separator "\\\;")
+    else()
+        set(separator ":")
+    endif()
+
+    string(APPEND testEnv "$<TARGET_FILE_DIR:ZLIB::ZLIB>${separator}")
+    string(APPEND testEnv "$ENV{PATH}")
+
+    set_tests_properties(${testName} PROPERTIES ENVIRONMENT "${testEnv}")
+endfunction()
+
+if(ZLIB_BUILD_SHARED)
+    add_executable(zlib_example example.c)
+    target_link_libraries(zlib_example ZLIB::ZLIB)
+    target_compile_definitions(zlib_example PRIVATE ZLIB_BUILD)
+    add_test(NAME zlib_example COMMAND zlib_example)
+
+    add_executable(minigzip minigzip.c)
+    target_compile_definitions(
+        minigzip PRIVATE $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>)
+    target_link_libraries(minigzip ZLIB::ZLIB)
+
+    if(MSVC
+       OR MSYS
+       OR MINGW
+       OR CYGWIN)
+        zlib_findtestenv(zlib_example)
+    endif(
+        MSVC
+        OR MSYS
+        OR MINGW
+        OR CYGWIN)
+
+    if(HAVE_OFF64_T)
+        add_executable(zlib_example64 example.c)
+        target_compile_definitions(
+            zlib_example64
+            PRIVATE ZLIB_BUILD
+                    $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>)
+        target_link_libraries(zlib_example64 ZLIB::ZLIB)
+        add_test(NAME zlib_example64 COMMAND zlib_example64)
+
+        if(MSVC
+           OR MSYS
+           OR MINGW
+           OR CYGWIN)
+            zlib_findtestenv(zlib_example64)
+        endif(
+            MSVC
+            OR MSYS
+            OR MINGW
+            OR CYGWIN)
+    endif(HAVE_OFF64_T)
+endif(ZLIB_BUILD_SHARED)
+
+if(ZLIB_BUILD_STATIC)
+    add_executable(zlib_static_example example.c)
+    target_link_libraries(zlib_static_example ZLIB::ZLIBSTATIC)
+    target_compile_definitions(
+        zlib_static_example
+        PRIVATE ZLIB_BUILD
+                $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>)
+    add_test(NAME zlib_static_example COMMAND zlib_static_example)
+
+    add_executable(static_minigzip minigzip.c)
+    target_link_libraries(static_minigzip ZLIB::ZLIBSTATIC)
+
+    if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL
+                                                "Clang")
+        set(CFLAGS_OLD ${CMAKE_C_FLAGS})
+        set({CMAKE_C_FLAGS
+            ""
+            CACHE STRING "" FORCE)
+
+        if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
+            find_program(GCOV_EXECUTABLE gcov)
+        endif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
+
+        if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
+            set(llvm_names llvm_cov)
+            list(APPEND llvm_names llvm-cov)
+
+            foreach(ver RANGE 11 99)
+                list(APPEND llvm_names llvm-cov-${ver})
+            endforeach(ver RANGE 11 99)
+
+            find_program(GCOV_EXECUTABLE NAMES ${llvm_names})
+            set(llvm_option "gcov")
+        endif(${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
+
+        add_executable(infcover infcover.c)
+        target_link_libraries(infcover ZLIB::ZLIBSTATIC)
+        target_compile_options(infcover PRIVATE -coverage)
+        target_link_options(infcover PRIVATE -coverage)
+        target_compile_definitions(
+            infcover PRIVATE $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>)
+        add_test(NAME zlib-coverage COMMAND infcover)
+        set(INFCOVER_DIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/infcover.dir)
+        add_test(
+            NAME zlib-coverage-summary
+            COMMAND
+                ${GCOV_EXECUTABLE} ${llvm_option}
+                ${CMAKE_CURRENT_SOURCE_DIR}/infcover.c -o
+                ${INFCOVER_DIR}/infcover.c.gcda)
+        set_tests_properties(zlib-coverage-summary PROPERTIES DEPENDS
+                                                              zlib-coverage)
+        set({CMAKE_C_FLAGS
+            ${CFLAGS_OLD}
+            CACHE STRING "" FORCE)
+    endif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID}
+                                                   STREQUAL "Clang")
+
+    if(HAVE_OFF64_T)
+        add_executable(zlib_static_example64 example.c)
+        target_compile_definitions(
+            zlib_static_example64
+            PRIVATE ZLIB_BUILD
+                    $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>)
+        target_link_libraries(zlib_static_example64 ZLIB::ZLIBSTATIC)
+        add_test(NAME zlib_static_example64 COMMAND zlib_static_example64)
+    endif(HAVE_OFF64_T)
+endif(ZLIB_BUILD_STATIC)
+
+add_test(
+    NAME zlib_install
+    COMMAND ${CMAKE_COMMAND} --install ${zlib_BINARY_DIR} --prefix
+            ${CMAKE_CURRENT_BINARY_DIR}/test_install --config $<CONFIG>
+    WORKING_DIRECTORY ${zlib_BINARY_DIR})
+
+set_tests_properties(zlib_install PROPERTIES FIXTURES_SETUP zlib_install)
+
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test)
+
+configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/find_package_test.cmake.in
+    ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test/CMakeLists.txt @ONLY)
+
+configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/add_subdirectory_test.cmake.in
+    ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test/CMakeLists.txt @ONLY)
+
+configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/add_subdirectory_exclude_test.cmake.in
+    ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test/CMakeLists.txt
+    @ONLY)
+
+# CMAKE_GENERATOR_PLATFORM doesn't work in the if
+set(GENERATOR ${CMAKE_GENERATOR_PLATFORM})
+
+if(GENERATOR)
+    set(PLATFORM "-A ${GENERATOR}")
+endif(GENERATOR)
+#
+# findpackage_test
+#
+add_test(
+    NAME zlib_find_package_configure
+    COMMAND
+        ${CMAKE_COMMAND} ${PLATFORM}
+        -B${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build
+        -DCMAKE_BUILD_TYPE=$<CONFIG> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+        -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
+        -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_install --fresh
+        -G "${CMAKE_GENERATOR}" -S${CMAKE_CURRENT_BINARY_DIR}/findpackage_test)
+
+add_test(
+    NAME zlib_find_package_build
+    COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build)
+
+add_test(
+    NAME zlib_find_package_test
+    COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG>
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build)
+
+set_tests_properties(
+    zlib_find_package_configure PROPERTIES FIXTURES_REQUIRED zlib_install
+                                           FIXTURES_SETUP fp_config)
+
+set_tests_properties(
+    zlib_find_package_build PROPERTIES FIXTURES_REQUIRED fp_config
+                                       FIXTURES_SETUP fp_build)
+
+set_tests_properties(
+    zlib_find_package_test PROPERTIES FIXTURES_REQUIRED fp_build ENVIRONMENT
+                                      CTEST_OUTPUT_ON_FAILURE=1)
+
+#
+# add_subdirectory_test
+#
+add_test(
+    NAME zlib_add_subdirectory_configure
+    COMMAND
+        ${CMAKE_COMMAND} ${PLATFORM}
+        -B${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test_build
+        -DCMAKE_BUILD_TYPE=$<CONFIG> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+        -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
+        -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_install --fresh
+        -G "${CMAKE_GENERATOR}" -S${CMAKE_CURRENT_BINARY_DIR}/findpackage_test)
+
+add_test(
+    NAME zlib_add_subdirectory_build
+    COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test_build)
+
+add_test(
+    NAME zlib_add_subdirectory_test
+    COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG>
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test_build)
+
+set_tests_properties(
+    zlib_add_subdirectory_configure PROPERTIES FIXTURES_REQUIRED zlib_install
+                                               FIXTURES_SETUP as_config)
+
+set_tests_properties(
+    zlib_add_subdirectory_build PROPERTIES FIXTURES_REQUIRED as_config
+                                           FIXTURES_SETUP as_build)
+
+set_tests_properties(
+    zlib_add_subdirectory_test PROPERTIES FIXTURES_REQUIRED as_build
+                                          ENVIRONMENT CTEST_OUTPUT_ON_FAILURE=1)
+
+#
+# add_subdirectory_exclude_test
+#
+add_test(
+    NAME zlib_add_subdirectory_exclude_configure
+    COMMAND
+        ${CMAKE_COMMAND} ${PLATFORM}
+        -B${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test_build
+        -DCMAKE_BUILD_TYPE=$<CONFIG> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+        -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
+        -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_install --fresh
+        -G "${CMAKE_GENERATOR}" -S${CMAKE_CURRENT_BINARY_DIR}/findpackage_test)
+
+add_test(
+    NAME zlib_add_subdirectory_exclude_build
+    COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
+    WORKING_DIRECTORY
+        ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test_build)
+
+add_test(
+    NAME zlib_add_subdirectory_exclude_test
+    COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG>
+    WORKING_DIRECTORY
+        ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test_build)
+
+set_tests_properties(
+    zlib_add_subdirectory_exclude_configure
+    PROPERTIES FIXTURES_REQUIRED zlib_install FIXTURES_SETUP asx_config)
+
+set_tests_properties(
+    zlib_add_subdirectory_exclude_build PROPERTIES FIXTURES_REQUIRED as_config
+                                                   FIXTURES_SETUP asx_build)
+
+set_tests_properties(
+    zlib_add_subdirectory_exclude_test
+    PROPERTIES FIXTURES_REQUIRED asx_build ENVIRONMENT
+               CTEST_OUTPUT_ON_FAILURE=1)
diff --git a/test/add_subdirectory_exclude_test.cmake.in b/test/add_subdirectory_exclude_test.cmake.in
new file mode 100644
index 000000000..9077ce595
--- /dev/null
+++ b/test/add_subdirectory_exclude_test.cmake.in
@@ -0,0 +1,29 @@
+cmake_minimum_required(VERSION 3.12...3.31)
+
+project(
+    zlib_find_package_test
+    LANGUAGES C
+    VERSION @zlib_VERSION@)
+
+enable_testing()
+option(ZLIB_BUILD_TESTING "" OFF)
+option(ZLIB_BUILD_SHARED "" @ZLIB_BUILD_SHARED@)
+option(ZLIB_BUILD_STATIC "" @ZLIB_BUILD_STATIC@)
+
+add_subdirectory(@zlib_SOURCE_DIR@ ${CMAKE_CURRENT_BINARY_DIR}/zlib
+                 EXCLUDE_FROM_ALL)
+
+if(ZLIB_BUILD_SHARED)
+    add_executable(test_example @zlib_SOURCE_DIR@/test/example.c)
+    target_link_libraries(test_example ZLIB::ZLIB)
+
+    if(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll")
+        add_test(NAME zlib_test_example_shared COMMAND test_example)
+    endif(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll")
+endif(ZLIB_BUILD_SHARED)
+
+if(ZLIB_BUILD_STATIC)
+    add_executable(test_example_static @zlib_SOURCE_DIR@/test/example.c)
+    target_link_libraries(test_example_static ZLIB::ZLIBSTATIC)
+    add_test(NAME zlib_test_example_static COMMAND test_example_static)
+endif(ZLIB_BUILD_STATIC)
diff --git a/test/add_subdirectory_test.cmake.in b/test/add_subdirectory_test.cmake.in
new file mode 100644
index 000000000..4201af82f
--- /dev/null
+++ b/test/add_subdirectory_test.cmake.in
@@ -0,0 +1,28 @@
+cmake_minimum_required(VERSION 3.12...3.31)
+
+project(
+    zlib_find_package_test
+    LANGUAGES C
+    VERSION @zlib_VERSION@)
+
+enable_testing()
+option(ZLIB_BUILD_TESTING "" OFF)
+option(ZLIB_BUILD_SHARED "" @ZLIB_BUILD_SHARED@)
+option(ZLIB_BUILD_STATIC "" @ZLIB_BUILD_STATIC@)
+
+add_subdirectory(@zlib_SOURCE_DIR@ ${CMAKE_CURRENT_BINARY_DIR}/zlib)
+
+if(ZLIB_BUILD_SHARED)
+    add_executable(test_example @zlib_SOURCE_DIR@/test/example.c)
+    target_link_libraries(test_example ZLIB::ZLIB)
+
+    if(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll")
+        add_test(NAME zlib_test_example_shared COMMAND test_example)
+    endif(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll")
+endif(ZLIB_BUILD_SHARED)
+
+if(ZLIB_BUILD_STATIC)
+    add_executable(test_example_static @zlib_SOURCE_DIR@/test/example.c)
+    target_link_libraries(test_example_static ZLIB::ZLIBSTATIC)
+    add_test(NAME zlib_test_example_static COMMAND test_example_static)
+endif(@ZLIB_BUILD_STATIC)
diff --git a/test/find_package_test.cmake.in b/test/find_package_test.cmake.in
new file mode 100644
index 000000000..0f77d4977
--- /dev/null
+++ b/test/find_package_test.cmake.in
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 3.12...3.31)
+
+project(
+    zlib_find_package_test
+    LANGUAGES C
+    VERSION @zlib_VERSION@)
+
+enable_testing()
+find_package(ZLIB @zlib_VERSION@ CONFIG REQUIRED)
+option(ZLIB_BUILD_SHARED "" @ZLIB_BUILD_SHARED@)
+option(ZLIB_BUILD_STATIC "" @ZLIB_BUILD_STATIC@)
+
+if(ZLIB_BUILD_SHARED)
+    add_executable(test_example @zlib_SOURCE_DIR@/test/example.c)
+    target_link_libraries(test_example ZLIB::ZLIB)
+
+    if(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll")
+        add_test(NAME zlib_test_example_shared COMMAND test_example)
+    endif(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll")
+endif(ZLIB_BUILD_SHARED)
+
+if(ZLIB_BUILD_STATIC)
+    add_executable(test_example_static @zlib_SOURCE_DIR@/test/example.c)
+    target_link_libraries(test_example_static ZLIB::ZLIBSTATIC)
+    add_test(NAME zlib_test_example_static COMMAND test_example_static)
+endif(ZLIB_BUILD_STATIC)
diff --git a/win32/Makefile.gcc b/win32/Makefile.gcc
index 081e391eb..35172fb35 100644
--- a/win32/Makefile.gcc
+++ b/win32/Makefile.gcc
@@ -50,7 +50,7 @@ AR = $(PREFIX)ar
 ARFLAGS = rcs
 
 RC = $(PREFIX)windres
-RCFLAGS = --define GCC_WINDRES
+RCFLAGS =
 
 STRIP = $(PREFIX)strip
 
diff --git a/win32/zlib1.rc b/win32/zlib1.rc
index ceb4ee5c6..e4847d85b 100644
--- a/win32/zlib1.rc
+++ b/win32/zlib1.rc
@@ -1,11 +1,8 @@
 #include <winver.h>
 #include "../zlib.h"
 
-#ifdef GCC_WINDRES
 VS_VERSION_INFO		VERSIONINFO
-#else
-VS_VERSION_INFO		VERSIONINFO	MOVEABLE IMPURE LOADONCALL DISCARDABLE
-#endif
+
   FILEVERSION		ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0
   PRODUCTVERSION	ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0
   FILEFLAGSMASK		VS_FFI_FILEFLAGSMASK
diff --git a/zconf.h b/zconf.h
index d6c159a1e..bc3ef079b 100644
--- a/zconf.h
+++ b/zconf.h
@@ -436,11 +436,11 @@ typedef uLong FAR uLongf;
    typedef unsigned long z_crc_t;
 #endif
 
-#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
+#if HAVE_UNISTD_H-0     /* may be set to #if 1 by ./configure */
 #  define Z_HAVE_UNISTD_H
 #endif
 
-#ifdef HAVE_STDARG_H    /* may be set to #if 1 by ./configure */
+#if HAVE_STDARG_H-0     /* may be set to #if 1 by ./configure */
 #  define Z_HAVE_STDARG_H
 #endif
 
diff --git a/zconf.h.cmakein b/zconf.h.cmakein
deleted file mode 100644
index f43a90448..000000000
--- a/zconf.h.cmakein
+++ /dev/null
@@ -1,546 +0,0 @@
-/* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#ifndef ZCONF_H
-#define ZCONF_H
-#cmakedefine Z_PREFIX
-#cmakedefine Z_HAVE_UNISTD_H
-
-/*
- * If you *really* need a unique prefix for all types and library functions,
- * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
- * Even better than compiling with -DZ_PREFIX would be to use configure to set
- * this permanently in zconf.h using "./configure --zprefix".
- */
-#ifdef Z_PREFIX     /* may be set to #if 1 by ./configure */
-#  define Z_PREFIX_SET
-
-/* all linked symbols and init macros */
-#  define _dist_code            z__dist_code
-#  define _length_code          z__length_code
-#  define _tr_align             z__tr_align
-#  define _tr_flush_bits        z__tr_flush_bits
-#  define _tr_flush_block       z__tr_flush_block
-#  define _tr_init              z__tr_init
-#  define _tr_stored_block      z__tr_stored_block
-#  define _tr_tally             z__tr_tally
-#  define adler32               z_adler32
-#  define adler32_combine       z_adler32_combine
-#  define adler32_combine64     z_adler32_combine64
-#  define adler32_z             z_adler32_z
-#  ifndef Z_SOLO
-#    define compress              z_compress
-#    define compress2             z_compress2
-#    define compressBound         z_compressBound
-#  endif
-#  define crc32                 z_crc32
-#  define crc32_combine         z_crc32_combine
-#  define crc32_combine64       z_crc32_combine64
-#  define crc32_combine_gen     z_crc32_combine_gen
-#  define crc32_combine_gen64   z_crc32_combine_gen64
-#  define crc32_combine_op      z_crc32_combine_op
-#  define crc32_z               z_crc32_z
-#  define deflate               z_deflate
-#  define deflateBound          z_deflateBound
-#  define deflateCopy           z_deflateCopy
-#  define deflateEnd            z_deflateEnd
-#  define deflateGetDictionary  z_deflateGetDictionary
-#  define deflateInit           z_deflateInit
-#  define deflateInit2          z_deflateInit2
-#  define deflateInit2_         z_deflateInit2_
-#  define deflateInit_          z_deflateInit_
-#  define deflateParams         z_deflateParams
-#  define deflatePending        z_deflatePending
-#  define deflatePrime          z_deflatePrime
-#  define deflateReset          z_deflateReset
-#  define deflateResetKeep      z_deflateResetKeep
-#  define deflateSetDictionary  z_deflateSetDictionary
-#  define deflateSetHeader      z_deflateSetHeader
-#  define deflateTune           z_deflateTune
-#  define deflateUsed           z_deflateUsed
-#  define deflate_copyright     z_deflate_copyright
-#  define get_crc_table         z_get_crc_table
-#  ifndef Z_SOLO
-#    define gz_error              z_gz_error
-#    define gz_intmax             z_gz_intmax
-#    define gz_strwinerror        z_gz_strwinerror
-#    define gzbuffer              z_gzbuffer
-#    define gzclearerr            z_gzclearerr
-#    define gzclose               z_gzclose
-#    define gzclose_r             z_gzclose_r
-#    define gzclose_w             z_gzclose_w
-#    define gzdirect              z_gzdirect
-#    define gzdopen               z_gzdopen
-#    define gzeof                 z_gzeof
-#    define gzerror               z_gzerror
-#    define gzflush               z_gzflush
-#    define gzfread               z_gzfread
-#    define gzfwrite              z_gzfwrite
-#    define gzgetc                z_gzgetc
-#    define gzgetc_               z_gzgetc_
-#    define gzgets                z_gzgets
-#    define gzoffset              z_gzoffset
-#    define gzoffset64            z_gzoffset64
-#    define gzopen                z_gzopen
-#    define gzopen64              z_gzopen64
-#    ifdef _WIN32
-#      define gzopen_w              z_gzopen_w
-#    endif
-#    define gzprintf              z_gzprintf
-#    define gzputc                z_gzputc
-#    define gzputs                z_gzputs
-#    define gzread                z_gzread
-#    define gzrewind              z_gzrewind
-#    define gzseek                z_gzseek
-#    define gzseek64              z_gzseek64
-#    define gzsetparams           z_gzsetparams
-#    define gztell                z_gztell
-#    define gztell64              z_gztell64
-#    define gzungetc              z_gzungetc
-#    define gzvprintf             z_gzvprintf
-#    define gzwrite               z_gzwrite
-#  endif
-#  define inflate               z_inflate
-#  define inflateBack           z_inflateBack
-#  define inflateBackEnd        z_inflateBackEnd
-#  define inflateBackInit       z_inflateBackInit
-#  define inflateBackInit_      z_inflateBackInit_
-#  define inflateCodesUsed      z_inflateCodesUsed
-#  define inflateCopy           z_inflateCopy
-#  define inflateEnd            z_inflateEnd
-#  define inflateGetDictionary  z_inflateGetDictionary
-#  define inflateGetHeader      z_inflateGetHeader
-#  define inflateInit           z_inflateInit
-#  define inflateInit2          z_inflateInit2
-#  define inflateInit2_         z_inflateInit2_
-#  define inflateInit_          z_inflateInit_
-#  define inflateMark           z_inflateMark
-#  define inflatePrime          z_inflatePrime
-#  define inflateReset          z_inflateReset
-#  define inflateReset2         z_inflateReset2
-#  define inflateResetKeep      z_inflateResetKeep
-#  define inflateSetDictionary  z_inflateSetDictionary
-#  define inflateSync           z_inflateSync
-#  define inflateSyncPoint      z_inflateSyncPoint
-#  define inflateUndermine      z_inflateUndermine
-#  define inflateValidate       z_inflateValidate
-#  define inflate_copyright     z_inflate_copyright
-#  define inflate_fast          z_inflate_fast
-#  define inflate_table         z_inflate_table
-#  ifndef Z_SOLO
-#    define uncompress            z_uncompress
-#    define uncompress2           z_uncompress2
-#  endif
-#  define zError                z_zError
-#  ifndef Z_SOLO
-#    define zcalloc               z_zcalloc
-#    define zcfree                z_zcfree
-#  endif
-#  define zlibCompileFlags      z_zlibCompileFlags
-#  define zlibVersion           z_zlibVersion
-
-/* all zlib typedefs in zlib.h and zconf.h */
-#  define Byte                  z_Byte
-#  define Bytef                 z_Bytef
-#  define alloc_func            z_alloc_func
-#  define charf                 z_charf
-#  define free_func             z_free_func
-#  ifndef Z_SOLO
-#    define gzFile                z_gzFile
-#  endif
-#  define gz_header             z_gz_header
-#  define gz_headerp            z_gz_headerp
-#  define in_func               z_in_func
-#  define intf                  z_intf
-#  define out_func              z_out_func
-#  define uInt                  z_uInt
-#  define uIntf                 z_uIntf
-#  define uLong                 z_uLong
-#  define uLongf                z_uLongf
-#  define voidp                 z_voidp
-#  define voidpc                z_voidpc
-#  define voidpf                z_voidpf
-
-/* all zlib structs in zlib.h and zconf.h */
-#  define gz_header_s           z_gz_header_s
-#  define internal_state        z_internal_state
-
-#endif
-
-#if defined(__MSDOS__) && !defined(MSDOS)
-#  define MSDOS
-#endif
-#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
-#  define OS2
-#endif
-#if defined(_WINDOWS) && !defined(WINDOWS)
-#  define WINDOWS
-#endif
-#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
-#  ifndef WIN32
-#    define WIN32
-#  endif
-#endif
-#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
-#  if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
-#    ifndef SYS16BIT
-#      define SYS16BIT
-#    endif
-#  endif
-#endif
-
-/*
- * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
- * than 64k bytes at a time (needed on systems with 16-bit int).
- */
-#ifdef SYS16BIT
-#  define MAXSEG_64K
-#endif
-#ifdef MSDOS
-#  define UNALIGNED_OK
-#endif
-
-#ifdef __STDC_VERSION__
-#  ifndef STDC
-#    define STDC
-#  endif
-#  if __STDC_VERSION__ >= 199901L
-#    ifndef STDC99
-#      define STDC99
-#    endif
-#  endif
-#endif
-#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
-#  define STDC
-#endif
-#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
-#  define STDC
-#endif
-#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
-#  define STDC
-#endif
-#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
-#  define STDC
-#endif
-
-#if defined(__OS400__) && !defined(STDC)    /* iSeries (formerly AS/400). */
-#  define STDC
-#endif
-
-#ifndef STDC
-#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
-#    define const       /* note: need a more gentle solution here */
-#  endif
-#endif
-
-#ifndef z_const
-#  ifdef ZLIB_CONST
-#    define z_const const
-#  else
-#    define z_const
-#  endif
-#endif
-
-#ifdef Z_SOLO
-#  ifdef _WIN64
-     typedef unsigned long long z_size_t;
-#  else
-     typedef unsigned long z_size_t;
-#  endif
-#else
-#  define z_longlong long long
-#  if defined(NO_SIZE_T)
-     typedef unsigned NO_SIZE_T z_size_t;
-#  elif defined(STDC)
-#    include <stddef.h>
-     typedef size_t z_size_t;
-#  else
-     typedef unsigned long z_size_t;
-#  endif
-#  undef z_longlong
-#endif
-
-/* Maximum value for memLevel in deflateInit2 */
-#ifndef MAX_MEM_LEVEL
-#  ifdef MAXSEG_64K
-#    define MAX_MEM_LEVEL 8
-#  else
-#    define MAX_MEM_LEVEL 9
-#  endif
-#endif
-
-/* Maximum value for windowBits in deflateInit2 and inflateInit2.
- * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
- * created by gzip. (Files created by minigzip can still be extracted by
- * gzip.)
- */
-#ifndef MAX_WBITS
-#  define MAX_WBITS   15 /* 32K LZ77 window */
-#endif
-
-/* The memory requirements for deflate are (in bytes):
-            (1 << (windowBits+2)) +  (1 << (memLevel+9))
- that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
- plus a few kilobytes for small objects. For example, if you want to reduce
- the default memory requirements from 256K to 128K, compile with
-     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
- Of course this will generally degrade compression (there's no free lunch).
-
-   The memory requirements for inflate are (in bytes) 1 << windowBits
- that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
- for small objects.
-*/
-
-                        /* Type declarations */
-
-#ifndef OF /* function prototypes */
-#  ifdef STDC
-#    define OF(args)  args
-#  else
-#    define OF(args)  ()
-#  endif
-#endif
-
-/* The following definitions for FAR are needed only for MSDOS mixed
- * model programming (small or medium model with some far allocations).
- * This was tested only with MSC; for other MSDOS compilers you may have
- * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
- * just define FAR to be empty.
- */
-#ifdef SYS16BIT
-#  if defined(M_I86SM) || defined(M_I86MM)
-     /* MSC small or medium model */
-#    define SMALL_MEDIUM
-#    ifdef _MSC_VER
-#      define FAR _far
-#    else
-#      define FAR far
-#    endif
-#  endif
-#  if (defined(__SMALL__) || defined(__MEDIUM__))
-     /* Turbo C small or medium model */
-#    define SMALL_MEDIUM
-#    ifdef __BORLANDC__
-#      define FAR _far
-#    else
-#      define FAR far
-#    endif
-#  endif
-#endif
-
-#if defined(WINDOWS) || defined(WIN32)
-   /* If building or using zlib as a DLL, define ZLIB_DLL.
-    * This is not mandatory, but it offers a little performance increase.
-    */
-#  ifdef ZLIB_DLL
-#    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
-#      ifdef ZLIB_INTERNAL
-#        define ZEXTERN extern __declspec(dllexport)
-#      else
-#        define ZEXTERN extern __declspec(dllimport)
-#      endif
-#    endif
-#  endif  /* ZLIB_DLL */
-   /* If building or using zlib with the WINAPI/WINAPIV calling convention,
-    * define ZLIB_WINAPI.
-    * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
-    */
-#  ifdef ZLIB_WINAPI
-#    ifdef FAR
-#      undef FAR
-#    endif
-#    ifndef WIN32_LEAN_AND_MEAN
-#      define WIN32_LEAN_AND_MEAN
-#    endif
-#    include <windows.h>
-     /* No need for _export, use ZLIB.DEF instead. */
-     /* For complete Windows compatibility, use WINAPI, not __stdcall. */
-#    define ZEXPORT WINAPI
-#    ifdef WIN32
-#      define ZEXPORTVA WINAPIV
-#    else
-#      define ZEXPORTVA FAR CDECL
-#    endif
-#  endif
-#endif
-
-#if defined (__BEOS__)
-#  ifdef ZLIB_DLL
-#    ifdef ZLIB_INTERNAL
-#      define ZEXPORT   __declspec(dllexport)
-#      define ZEXPORTVA __declspec(dllexport)
-#    else
-#      define ZEXPORT   __declspec(dllimport)
-#      define ZEXPORTVA __declspec(dllimport)
-#    endif
-#  endif
-#endif
-
-#ifndef ZEXTERN
-#  define ZEXTERN extern
-#endif
-#ifndef ZEXPORT
-#  define ZEXPORT
-#endif
-#ifndef ZEXPORTVA
-#  define ZEXPORTVA
-#endif
-
-#ifndef FAR
-#  define FAR
-#endif
-
-#if !defined(__MACTYPES__)
-typedef unsigned char  Byte;  /* 8 bits */
-#endif
-typedef unsigned int   uInt;  /* 16 bits or more */
-typedef unsigned long  uLong; /* 32 bits or more */
-
-#ifdef SMALL_MEDIUM
-   /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
-#  define Bytef Byte FAR
-#else
-   typedef Byte  FAR Bytef;
-#endif
-typedef char  FAR charf;
-typedef int   FAR intf;
-typedef uInt  FAR uIntf;
-typedef uLong FAR uLongf;
-
-#ifdef STDC
-   typedef void const *voidpc;
-   typedef void FAR   *voidpf;
-   typedef void       *voidp;
-#else
-   typedef Byte const *voidpc;
-   typedef Byte FAR   *voidpf;
-   typedef Byte       *voidp;
-#endif
-
-#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
-#  include <limits.h>
-#  if (UINT_MAX == 0xffffffffUL)
-#    define Z_U4 unsigned
-#  elif (ULONG_MAX == 0xffffffffUL)
-#    define Z_U4 unsigned long
-#  elif (USHRT_MAX == 0xffffffffUL)
-#    define Z_U4 unsigned short
-#  endif
-#endif
-
-#ifdef Z_U4
-   typedef Z_U4 z_crc_t;
-#else
-   typedef unsigned long z_crc_t;
-#endif
-
-#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
-#  define Z_HAVE_UNISTD_H
-#endif
-
-#ifdef HAVE_STDARG_H    /* may be set to #if 1 by ./configure */
-#  define Z_HAVE_STDARG_H
-#endif
-
-#ifdef STDC
-#  ifndef Z_SOLO
-#    include <sys/types.h>      /* for off_t */
-#  endif
-#endif
-
-#if defined(STDC) || defined(Z_HAVE_STDARG_H)
-#  ifndef Z_SOLO
-#    include <stdarg.h>         /* for va_list */
-#  endif
-#endif
-
-#ifdef _WIN32
-#  ifndef Z_SOLO
-#    include <stddef.h>         /* for wchar_t */
-#  endif
-#endif
-
-/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
- * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
- * though the former does not conform to the LFS document), but considering
- * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
- * equivalently requesting no 64-bit operations
- */
-#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
-#  undef _LARGEFILE64_SOURCE
-#endif
-
-#ifndef Z_HAVE_UNISTD_H
-#  if defined(__WATCOMC__) || defined(__GO32__) || \
-      (defined(_LARGEFILE64_SOURCE) && !defined(_WIN32))
-#    define Z_HAVE_UNISTD_H
-#  endif
-#endif
-#ifndef Z_SOLO
-#  if defined(Z_HAVE_UNISTD_H)
-#    include <unistd.h>         /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
-#    ifdef VMS
-#      include <unixio.h>       /* for off_t */
-#    endif
-#    ifndef z_off_t
-#      define z_off_t off_t
-#    endif
-#  endif
-#endif
-
-#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
-#  define Z_LFS64
-#endif
-
-#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
-#  define Z_LARGE64
-#endif
-
-#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
-#  define Z_WANT64
-#endif
-
-#if !defined(SEEK_SET) && !defined(Z_SOLO)
-#  define SEEK_SET        0       /* Seek from beginning of file.  */
-#  define SEEK_CUR        1       /* Seek from current position.  */
-#  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
-#endif
-
-#ifndef z_off_t
-#  define z_off_t long long
-#endif
-
-#if !defined(_WIN32) && defined(Z_LARGE64)
-#  define z_off64_t off64_t
-#elif defined(__MINGW32__)
-#  define z_off64_t long long
-#elif defined(_WIN32) && !defined(__GNUC__)
-#  define z_off64_t __int64
-#elif defined(__GO32__)
-#  define z_off64_t offset_t
-#else
-#  define z_off64_t z_off_t
-#endif
-
-/* MVS linker does not support external names larger than 8 bytes */
-#if defined(__MVS__)
-  #pragma map(deflateInit_,"DEIN")
-  #pragma map(deflateInit2_,"DEIN2")
-  #pragma map(deflateEnd,"DEEND")
-  #pragma map(deflateBound,"DEBND")
-  #pragma map(inflateInit_,"ININ")
-  #pragma map(inflateInit2_,"ININ2")
-  #pragma map(inflateEnd,"INEND")
-  #pragma map(inflateSync,"INSY")
-  #pragma map(inflateSetDictionary,"INSEDI")
-  #pragma map(compressBound,"CMBND")
-  #pragma map(inflate_table,"INTABL")
-  #pragma map(inflate_fast,"INFA")
-  #pragma map(inflate_copyright,"INCOPY")
-#endif
-
-#endif /* ZCONF_H */
diff --git a/zconf.h.in b/zconf.h.in
index d6c159a1e..bc3ef079b 100644
--- a/zconf.h.in
+++ b/zconf.h.in
@@ -436,11 +436,11 @@ typedef uLong FAR uLongf;
    typedef unsigned long z_crc_t;
 #endif
 
-#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
+#if HAVE_UNISTD_H-0     /* may be set to #if 1 by ./configure */
 #  define Z_HAVE_UNISTD_H
 #endif
 
-#ifdef HAVE_STDARG_H    /* may be set to #if 1 by ./configure */
+#if HAVE_STDARG_H-0     /* may be set to #if 1 by ./configure */
 #  define Z_HAVE_STDARG_H
 #endif
 
diff --git a/zlib.h b/zlib.h
index ad33815f1..c75090b0f 100644
--- a/zlib.h
+++ b/zlib.h
@@ -31,7 +31,11 @@
 #ifndef ZLIB_H
 #define ZLIB_H
 
-#include "zconf.h"
+#ifdef ZLIB_BUILD
+#  include <zconf.h>
+#else
+# include "zconf.h"
+#endif
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/zlib.pc.cmakein b/zlib.pc.cmakein
index a5e642938..6da9e49fd 100644
--- a/zlib.pc.cmakein
+++ b/zlib.pc.cmakein
@@ -1,12 +1,12 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@INSTALL_LIB_DIR@
-sharedlibdir=@INSTALL_LIB_DIR@
-includedir=@INSTALL_INC_DIR@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+sharedlibdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${exec_prefix}/@CMAKE_INSTALL_INCLUDEDIR@
 
 Name: zlib
 Description: zlib compression library
-Version: @VERSION@
+Version: @zlib_VERSION@
 
 Requires:
 Libs: -L${libdir} -L${sharedlibdir} -lz
diff --git a/zlibConfig.cmake.in b/zlibConfig.cmake.in
new file mode 100644
index 000000000..713cac458
--- /dev/null
+++ b/zlibConfig.cmake.in
@@ -0,0 +1,26 @@
+@PACKAGE_INIT@
+
+set(_ZLIB_supported_components "")
+
+if(@ZLIB_BUILD_SHARED@)
+    list(APPEND _ZLIB_supported_components shared)
+endif(@ZLIB_BUILD_SHARED@)
+
+if(@ZLIB_BUILD_STATIC@)
+    list(APPEND _ZLIB_supported_components static)
+endif(@ZLIB_BUILD_STATIC@)
+
+if(ZLIB_FIND_COMPONENTS)
+    foreach(_comp ${ZLIB_FIND_COMPONENTS})
+        if(NOT _comp IN_LIST _ZLIB_supported_components)
+            set(ZLIB_FOUND False)
+            set(ZLIB_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
+        endif(NOT _comp IN_LIST _ZLIB_supported_components)
+
+        include("${CMAKE_CURRENT_LIST_DIR}/ZLIB-${_comp}.cmake")
+    endforeach(_comp ${ZLIB_FIND_COMPONENTS})
+else(ZLIB_FIND_COMPONENTS)
+    foreach(_component_config IN LISTS _ZLIB_supported_components)
+        include("${CMAKE_CURRENT_LIST_DIR}/ZLIB-${_component_config}.cmake")
+    endforeach(_component_config IN LISTS _ZLIB_supported_components)
+endif(ZLIB_FIND_COMPONENTS)
