# -*- 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         nomaintainer
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 qtwebkit sqlite-plugin

    # Released version does not build with modern Qt5.
    github.setup    jktjkt trojita d6600a058db5a9a224ce47b41dee320df0c75e56
    version         0.7
    revision        1
    checksums       rmd160  aa9fc6fb1d6ec3ce43d96b46d739472d0fa0c0d7 \
                    sha256  24a477f6fdd298e9fb15e6da05b6eec03efc60dee94e0c512fb9df0802c000e7 \
                    size    4688432

    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:zlib

depends_run-append  port:desktop-file-utils

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"
}
