# -*- 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           github 1.0
PortGroup           cmake 1.0

github.setup        libjxl libjxl 0.11.2 v
revision            2
categories          graphics
maintainers         {jmr @jmroot}
license             BSD

description         JPEG XL reference implementation

long_description    A reference implementation of JPEG XL.

github.tarball_from archive
# No option to use external skcms
set skcms_commit    b2e692629c1fb19342517d7fb61f1cf83d075492
master_sites-append sourceforge:project/macports/distfiles/${name}:skcms
# googlesource doesn't provide stable tarballs
# https://skia.googlesource.com/skcms/+archive/${skcms_commit}.tar.gz?dummy=
distfiles-append    skcms-${skcms_commit}${extract.suffix}:skcms
checksums           ${name}-${version}${extract.suffix} \
                        rmd160 56b3c741749bd40e1464303f07f711908c2cdf2d \
                        sha256 ab38928f7f6248e2a98cc184956021acb927b16a0dee71b4d260dc040a4320ea \
                    skcms-${skcms_commit}${extract.suffix} \
                        rmd160 f0590e7d370654a6a6f25e4f45714832491e50ab \
                        sha256 091dee7e841c899bcb7c3cf0b88905140332fd9271b3f5e11d97b74306ca9585

depends_build-append \
                    port:asciidoc \
                    path:bin/pkg-config:pkgconfig
depends_lib         port:brotli \
                    port:giflib5 \
                    port:highway \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libpng \
                    port:openexr

extract.only        ${name}-${version}${extract.suffix}
post-extract {
    system -W ${worksrcpath}/third_party/skcms \
        "tar -xzf ${distpath}/skcms-${skcms_commit}${extract.suffix}"
}

patchfiles          include_order.patch \
                    find_asciidoc.patch

if {${os.platform} eq "darwin" && ${os.major} <= 15} {
    # No support for sized operator delete
    patchfiles-append   sized-deallocation.patch
}

cmake.out_of_source yes
configure.args-append \
                    -DBUILD_TESTING=NO \
                    -DAVIF_FOUND=NO \
                    -DWebP_FOUND=NO \
                    -DJPEGXL_ENABLE_DOXYGEN=NO \
                    -DJPEGXL_ENABLE_JPEGLI=NO \
                    -DJPEGXL_ENABLE_JNI=NO \
                    -DJPEGXL_ENABLE_OPENEXR=YES \
                    -DJPEGXL_ENABLE_SJPEG=NO \
                    -DJPEGXL_ENABLE_SKCMS=YES \
                    -DJPEGXL_FORCE_SYSTEM_BROTLI=YES \
                    -DJPEGXL_FORCE_SYSTEM_HWY=YES \
                    -DASCIIDOC:FILEPATH=${prefix}/bin/a2x \
                    -DGIF_INCLUDE_DIR:FILEPATH=${prefix}/libexec/giflib5/include \
                    -DGIF_LIBRARY:FILEPATH=${prefix}/libexec/giflib5/lib/libgif.dylib

compiler.cxx_standard   2011
# Compilation warning (from highway headers):
# "x86 Clang <= 6: define HWY_COMPILE_ONLY_SCALAR or upgrade."
# (Xcode Clang 10.0.1 ~= llvm.org Clang 7.0)
compiler.blacklist  {clang < 1001}

variant tests description {Enable building of test code} {
    depends_build-append    port:gtest
    configure.args-replace  -DBUILD_TESTING=NO \
                            -DBUILD_TESTING=YES \
                            -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
                            -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF
    configure.args-append   -DJPEGXL_FORCE_SYSTEM_GTEST=YES
    test.run        yes
}

github.livecheck.regex  {([\d.]+)}
