# -*- 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

github.setup        rodlie cyan b78f14b33a2a7f9640fcf085f5546ca6fd6c03f8
version             1.2.99.1
revision            0
categories          graphics
license             CeCILL-2.1
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Cyan Graphics
long_description    ${name} is an open-source cross-platform image viewer \
                    and converter, designed for prepress (print) work.
homepage            https://cyan.graphics
checksums           rmd160  b28ce6741c676b3a5cc1c584b5931a8b0bd778ed \
                    sha256  03c329163143007b0792de9928824fee35be9ae67b278c4cecc32ec93e8b71c6 \
                    size    16304765
github.tarball_from archive

if {${os.platform} eq "darwin" && ${os.arch} ne "arm"} {
    PortGroup       qmake 1.0

    depends_lib-append  port:qt4-mimetypes

    configure.cxxflags-append \
                    -I${prefix}/include/QtMimeTypes
    configure.ldflags-append \
                    -lQtMimeTypes
} else {
    PortGroup       qmake5 1.0

}

compiler.cxx_standard   2011
compiler.openmp_version 2.5

patch.pre_args-replace  -p0 -p1

patchfiles-append   0001-Support-Qt4.patch

if {[string match *gcc* ${configure.compiler}]} {
    patchfiles-append   patch-no-libomp.diff
} elseif {[string match *clang* ${configure.compiler}]} {
    patchfiles-append   patch-libomp.diff
}

post-patch {
    reinplace "s|@PREFIX@|${prefix}|" ${worksrcpath}/${name}.pro
}

if {${macosx_deployment_target} eq ""} {
    set macosx_deployment_target 10.6
}

post-patch {
    reinplace "s|OSX_COMPAT = 10.13|OSX_COMPAT = ${macosx_deployment_target}|" ${worksrcpath}/${name}.pro
}

depends_lib-append  port:ImageMagick \
                    port:lcms2 \
                    port:libiconv

# While it builds against ImageMagick7,
# it fails to work: https://github.com/rodlie/cyan/issues/116
# configure.pkg_config_path-prepend \
                    ${prefix}/lib/ImageMagick7/lib/pkgconfig

configure.args-append \
                    ${worksrcpath}/${name}.pro

# Force C++11, avoid newer standards:
configure.cxxflags-append \
                    -std=c++11

destroot {
    copy ${worksrcpath}/build/Cyan.app ${destroot}${applications_dir}

    xinstall -d ${destroot}${prefix}/share/${name}
    copy ${worksrcpath}/docs ${destroot}${prefix}/share/${name}/
}
