# -*- 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               conflicts_build 1.0
PortGroup               github 1.0
PortGroup               legacysupport 1.1

# CLOCK_REALTIME
legacysupport.newest_darwin_requires_legacy 15

github.setup            reybits simple-viewer-gl 3.2.4 v
revision                2

categories              graphics gnome
license                 GPL-2
maintainers             {@barracuda156 macos-powerpc.org:barracuda} openmaintainer

description             Simple Viewer GL is a simple and tiny image viewer
long_description        {*}${description} based on OpenGL.
homepage                https://www.ugolnik.info/simple-viewer-gl
checksums               rmd160  e195c7aca7af8346d7ec74d80dac43198955273c \
                        sha256  54406af9dda99b30d94f9bf3fe7e21882bb9b14adbad4e8851cc2b628d1ad459 \
                        size    4458298
github.tarball_from     archive

cmake.build_type        Release

# https://github.com/reybits/simple-viewer-gl/issues/7
patchfiles              patch-main.cpp.diff

# GLFWCustomDelegate.h:29:1: error: struct has no named members [-Wpedantic]
patchfiles-append       patch-no-pedantic.diff

# https://github.com/reybits/simple-viewer-gl/issues/6
conflicts_build         mesa

compiler.cxx_standard   2014

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

depends_lib-append      port:curl \
                        port:giflib \
                        port:glfw \
                        port:ilmbase \
                        port:imlib2 \
                        port:lcms2 \
                        path:include/turbojpeg.h:libjpeg-turbo \
                        port:libpng \
                        port:openexr2 \
                        port:openjpeg \
                        port:tiff \
                        port:webp \
                        port:zlib

configure.pkg_config_path-prepend \
                        ${prefix}/libexec/openexr2/lib/pkgconfig

# https://github.com/reybits/simple-viewer-gl/issues/8
if {[string match *gcc* ${configure.compiler}]} {
    patchfiles-append   patch-cocoa.diff
}

if {${os.platform} eq "darwin" && ${os.major} < 13} {
    configure.cxxflags-append \
                -D_MACPORTS_LEGACY_COMPATIBLE_SCANDIR=1
}

# FIXME: the app works normally, but terminal output complains:
# [00000] [imgui-error] In window 'NULL': stbtt_GetFontOffsetForIndex(): FontData is incorrect, or FontNo cannot be found.

destroot {
    copy ${cmake.build_dir}/sviewgl.app ${destroot}${applications_dir}/
    ln -s ${applications_dir}/sviewgl.app/Contents/MacOS/sviewgl ${destroot}${prefix}/bin/sviewgl
}
