# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           github 1.0

github.setup        zlib-ng minizip-ng 4.0.7
revision            0
checksums           rmd160  f8fa41a8314702ac1f4fe7d605eb43ad399de839 \
                    sha256  a87f1f734f97095fe1ef0018217c149d53d0f78438bcb77af38adc21dff2dfbc \
                    size    770098

categories          archivers
maintainers         {ryandesign @ryandesign} openmaintainer
license             zlib

description         fork of zlib's minizip zip file manipulation library

long_description    ${name} is a {*}${description}.

# Error: Failed to activate minizip-ng: Image error:
# /opt/local/lib/libminizip.dylib is being used by the active minizip port
conflicts           minizip

github.tarball_from archive

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib         port:bzip2 \
                    port:libiconv \
                    path:lib/libssl.dylib:openssl \
                    port:xz \
                    port:zstd

# see https://lists.macports.org/pipermail/macports-dev/2023-May/045008.html
depends_run-append  port:zstdConfig.cmake

configure.args      -DBUILD_SHARED_LIBS=ON \
                    -DMZ_BUILD_TEST=OFF \
                    -DMZ_BUILD_UNIT_TEST=OFF \
                    -DMZ_BZIP2=ON \
                    -DMZ_FETCH_LIBS=OFF \
                    -DMZ_ICONV=ON \
                    -DMZ_LIBCOMP=OFF \
                    -DMZ_LZMA=ON \
                    -DMZ_OPENSSL=ON \
                    -DMZ_ZLIB=OFF \
                    -DMZ_ZSTD=ON

# Change filename suffix to avoid conflict with minizip port.
# https://github.com/zlib-ng/minizip-ng/discussions/452
configure.args-append \
                    -DMZ_PROJECT_SUFFIX=-ng

# Disable minizip compatibility mode to avoid conflict with libzip port.
configure.args-append \
                    -DMZ_COMPAT=OFF

# Disable signing support because its tests fail unless a test
# certificate is installed in the keychain.
# https://github.com/zlib-ng/minizip-ng/issues/580#issuecomment-874894055
configure.args-append \
                    -DMZ_SIGNING=OFF

if {${os.platform} eq "darwin" && ${os.major} >= 15} {
    # Use Apple's libcompression.dylib.
    configure.args-replace \
                    -DMZ_LIBCOMP=OFF    -DMZ_LIBCOMP=ON
} else {
    # libcompression.dylib not available; use zlib.
    depends_lib-append \
                    port:zlib
    configure.args-replace \
                    -DMZ_ZLIB=OFF       -DMZ_ZLIB=ON
}

variant tests description {Enable tests} {
    # if gtest not found, test/CMakeLists.txt helpfully downloads a copy and builds it regardless of MZ_FETCH_LIBS
    depends_test-append \
                    port:gtest

    configure.args-replace \
                    -DMZ_BUILD_TEST=OFF         -DMZ_BUILD_TEST=ON \
                    -DMZ_BUILD_UNIT_TEST=OFF    -DMZ_BUILD_UNIT_TEST=ON

    test.run        yes
    # duplicate ${test.dir}/Makefile with DYLD_LIBRARY_PATH
    test.cmd        DYLD_LIBRARY_PATH=${cmake.build_dir} ctest --force-new-ctest-process
}
