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

name                trojita

categories          mail
license             GPL-2+
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
homepage            http://trojita.flaska.net
description         Fast and lightweight Qt IMAP e-mail client
long_description    {*}${description}

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # FIXME: for a reason yet unclear it does not see
    # its plugins when built with Qt4.
    PortGroup       qt4 1.0

    github.setup    jktjkt trojita 0.6 v
    checksums       rmd160  05c2d9a0ea599b5656ac4badcbea27ecda0cbe98 \
                    sha256  e2c3f62e655f638c29d93fdab80a99ad5b55861e21d02e485f3bca6a8fc658f9 \
                    size    3184949

    conflicts_build qt4-mimetypes

    depends_lib-append \
                    port:qt4-mac-sqlite3-plugin \
                    port:qtkeychain-qt4

    compiler.cxx_standard   2011

    configure.args-append \
                    -DWITH_QT5=OFF

} else {
    PortGroup       qt5 1.0

    qt5.depends_component qtdeclarative qttools qttranslations qtsvg qtwebkit

    # Released version does not build with modern Qt5.
    github.setup    jktjkt trojita 5e13484fb04d53cbd416846095ec6fe512c75cc3
    version         0.7
    checksums       rmd160  c26c0882e5b7ec559b186a184de686d9051d0489 \
                    sha256  1e85a9c8056f4fe4171986edf055db710f2ebaa1657ef67fb4cf30249f260fe2 \
                    size    4657044

    depends_lib-append \
                    port:qtkeychain-qt5

    compiler.cxx_standard   2014

    patchfiles      0001-CMakeLists-drop-breaking-flag.patch
}

github.tarball_from archive

depends_build-append \
                    port:ragel
depends_lib-append  port:atk \
                    port:dbus \
                    port:desktop-file-utils \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:zlib

configure.args-append \
                    -DBUILD_TESTING=OFF \
                    -DCMAKE_INSTALL_PLUGIN_DIR=${prefix}/lib/${name} \
                    -DWITH_ABOOKADDRESSBOOK_PLUGIN=ON \
                    -DWITH_CLEARTEXT_PLUGIN=ON \
                    -DWITH_DBUS=ON \
                    -DWITH_DESKTOP=ON \
                    -DWITH_GPGMEPP=OFF \
                    -DWITH_KF5_GPGMEPP=OFF \
                    -DWITH_MIMETIC=OFF \
                    -DWITH_QTKEYCHAIN_PLUGIN=ON \
                    -DWITH_RAGEL=ON \
                    -DWITH_SHARED_PLUGINS=ON \
                    -DWITH_ZLIB=ON

# FIXME: one test fails with Qt5 version.
# With Qt4 a number of tests fail, at least on PowerPC,
# though some of those failures may be superficial.
variant tests description "Enable testing" {
    configure.args-replace \
                    -DBUILD_TESTING=OFF -DBUILD_TESTING=ON
    test.run        yes
}

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}
