# -*- 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            AOMediaCodec libavif 1.3.0 v
revision                1

checksums               rmd160  d1a10904e0b5fd9969847d4232637b77a71de9af \
                        sha256  0a545e953cc049bf5bcf4ee467306a2f113a75110edf59e61248873101cd26c1 \
                        size    14062497

categories              multimedia
license                 BSD
maintainers             {mascguy @mascguy} openmaintainer

description             Portable C implementation of the AV1 Image File Format
long_description        {*}${description}

github.tarball_from     archive

cmake.generator         Ninja

# Patch cmake script to use installed libargparse; to be contributed to upstream
patchfiles-append       patch-cmake-libargparse.diff

post-patch {
    # Remove script which downloads and builds private libargparse
    delete ${worksrcpath}/cmake/Modules/LocalLibargparse.cmake
}

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

depends_lib-append \
                        port:aom \
                        port:dav1d \
                        port:libargparse \
                        path:include/turbojpeg.h:libjpeg-turbo \
                        port:libpng \
                        port:libxml2 \
                        port:libyuv \
                        port:svt-av1 \
                        port:zlib

# Avoid build errors on 10.8 and earlier
compiler.blacklist-append \
                        {clang < 600}

# Needed when compiling with lib dep libargparse
compiler.cxx_standard   2014

configure.args-append \
                        -DAVIF_BUILD_APPS=ON \
                        -DAVIF_BUILD_EXAMPLES=OFF \
                        -DAVIF_BUILD_MAN_PAGES=OFF \
                        -DAVIF_BUILD_TESTS=OFF \
                        -DAVIF_CODEC_AOM=SYSTEM \
                        -DAVIF_CODEC_DAV1D=SYSTEM \
                        -DAVIF_CODEC_LIBGAV1=OFF \
                        -DAVIF_CODEC_RAV1E=OFF \
                        -DAVIF_CODEC_SVT=SYSTEM \
                        -DAVIF_ENABLE_NODISCARD=OFF \
                        -DAVIF_ENABLE_WERROR=OFF \
                        -DAVIF_JPEG=SYSTEM \
                        -DAVIF_LIBSHARPYUV=OFF \
                        -DAVIF_LIBXML2=SYSTEM \
                        -DAVIF_LIBYUV=SYSTEM \
                        -DAVIF_ZLIBPNG=SYSTEM \
                        -DBUILD_SHARED_LIBS=ON

platform darwin {
    if {${os.major} < 10 || (${os.major} == 10 && ${configure.build_arch} eq "ppc")} {
        # TODO: Disable rav1e on <10.6, due to issues with cargo-c; enable if fixed.
        # Do not enable on PPC until Rust is fixed or it becomes possible to build with gccrs.
        # See: https://trac.macports.org/ticket/65434
        if {[variant_isset rav1e]} {
            error "Variant rav1e not supported for macOS 10.5 and earlier, or PPC"
        }
    }

    # pandoc only available/working on 10.8+
    if {${os.major} < 12} {
        if {[variant_isset docs]} {
            error "Variant docs not supported for macOS 10.7 and earlier"
        }
    }
}

variant rav1e description {Enable codec rav1e} {
    depends_lib-append \
                        port:rav1e

    configure.args-replace \
                        -DAVIF_CODEC_RAV1E=OFF \
                        -DAVIF_CODEC_RAV1E=SYSTEM
}

variant docs description {Build man pages} {
    depends_build-append \
                        port:pandoc

    configure.args-replace \
                        -DAVIF_BUILD_MAN_PAGES=OFF \
                        -DAVIF_BUILD_MAN_PAGES=ON
}

variant tests description {Enable testing} {
    # Note: While core lib is C99, tests require C++ 2014
    compiler.cxx_standard 2014

    depends_test-append \
                        port:gtest

    configure.args-replace \
                        -DAVIF_BUILD_TESTS=OFF \
                        -DAVIF_BUILD_TESTS=ON
    configure.args-append \
                        -DAVIF_GTEST=SYSTEM

    test.run            yes
}

if {![variant_isset rav1e]} {
    notes-append "Support for rav1e now disabled by default; enable via +rav1e"
}

# Exclude pre-release candidates in livecheck
github.livecheck.regex  {([0-9.]+)}
