# -*- 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            google snappy 1.3.1
github.tarball_from     archive
revision                1

categories              archivers
license                 BSD
homepage                https://google.github.io/snappy
maintainers             {sethm.id.au:dev @McDaMastR} \
                        openmaintainer

description             A fast compressor/decompressor
long_description        Snappy is a compression/decompression library.  It \
                        does not aim for maximum compression, or compatibility \
                        with any other compression library.  Instead it aims \
                        for very high speeds and reasonable compression.  For \
                        instance, compared to the fastest mode of zlib, Snappy \
                        is an order of magnitude faster for most inputs, but \
                        the resulting compressed files are anywhere from 20% \
                        to 100% bigger.  On a single core of a Core i7 \
                        processor in 64-bit mode, Snappy compresses at about \
                        250 MB/sec or more and decompresses at about 500 \
                        MB/sec or more.

checksums               rmd160  399ba01225d7ca47eeb0a2efe7fdc048084aeb33 \
                        sha256  893f708a0bf4b5529d555ffcee390e940e932fcf90261f682604475a76cd0247 \
                        size    1116583

# https://github.com/facebook/folly/issues/1583
# https://github.com/Homebrew/homebrew-core/pull/76686#issuecomment-847527483
patchfiles              patch-no-disable-rtti.diff \
                        use-installed-gtest.diff

compiler.cxx_standard   2011
# Disable Xcode clang < 1200, due to the following:
#   error: invalid output constraint '=@ccz' in asm
compiler.blacklist-append \
                        {clang < 1200}

configure.args-append   -DBUILD_SHARED_LIBS=ON \
                        -DSNAPPY_BUILD_BENCHMARKS=OFF \
                        -DSNAPPY_BUILD_TESTS=OFF \
                        -DSNAPPY_FUZZING_BUILD=OFF \
                        -DSNAPPY_INSTALL=ON \
                        -DSNAPPY_REQUIRE_AVX=OFF \
                        -DSNAPPY_REQUIRE_AVX2=OFF

post-destroot {
    set destdocdir  ${destroot}${prefix}/share/doc/${name}

    xinstall -d ${destdocdir}
    xinstall -W ${worksrcpath} -m 644 \
        AUTHORS \
        CONTRIBUTING.md \
        COPYING.notestdata \
        NEWS \
        README.md \
        format_description.txt \
        framing_format.txt \
        ${destdocdir}
}

variant test \
        description {Build tests} {
    depends_build-append    port:gtest \
                            port:lz4 \
                            port:lzo2 \
                            port:zlib
    depends_test-append     port:gtest \
                            port:lz4 \
                            port:lzo2 \
                            port:zlib

    configure.args-append   -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF
    configure.args-replace  -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_TESTS=ON

    test.run                yes
    test.cmd                ctest
    test.target
}
