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

name                qtkeychain
version             0.13.2

description         QtKeyChain stores passwords securely
long_description    {*}${description}

categories          security
license             BSD
maintainers         nomaintainer

depends_lib-append  port:pkgconfig

use_parallel_build  no

foreach qt_major {4 5 6} {
    subport ${name}-qt${qt_major} {
        PortGroup cmake         1.1
        PortGroup qt${qt_major} 1.0

        # Only versions older than 0.12.0 support Qt4
        if {${qt_major} eq 4} {
            github.setup frankosterfeld qtkeychain 0.11.1 v

            checksums   rmd160  9f587e90344fe2661f967a29ec7464a1977c2af1 \
                        sha256  77fc6841c1743d9e6bd499989481cd9239c21bc9bf0760d41a4f4068d2f0a49d \
                        size    41001

            livecheck.type none
        } else {
            github.setup frankosterfeld qtkeychain ${version} v

            checksums   rmd160  15931f1356fb7109882eb89bf69332a3cc27f19d \
                        sha256  20beeb32de7c4eb0af9039b21e18370faf847ac8697ab3045906076afbc4caa5 \
                        size    43494
        }

        github.tarball_from archive

        switch ${qt_major} {
            6 {
                qt6.depends_build-append qttools
                qt6.depends_lib-append  qttranslations
                configure.args-append -DBUILD_WITH_QT6=ON
                configure.args-append -DBUILD_WITH_QT4=OFF
            }

            5 {
                qt5.depends_build_component qttools
                qt5.depends_component qttranslations
                configure.args-append -DBUILD_WITH_QT4=OFF
            }

            4 {
                configure.args-append -DBUILD_WITH_QT4=ON
            }
        }

        if {${qt_major} ne 6} {
            # correct module directory is not found for either Qt4 or Qt5
            # see cmake/Modules/ECMGeneratePriFile.cmake
            configure.args-append \
                -DECM_MKSPECS_INSTALL_DIR=${qt_mkspecs_dir}/modules
        } else {
            # $qt_mkspecs_dir is not defined by the Qt6 portgroups
            configure.args-append \
                -DECM_MKSPECS_INSTALL_DIR=${prefix}/libexec/qt6/mkspecs/modules
        }
    }
}

platform darwin {
    # Qt 5.7+ is used on Darwin 12 (10.8) or newer (see qt5 portgruop
    # definition), thus C++ 11 is required
    if {${os.major} >= 12} {
        compiler.cxx_standard   2011
    }
}

if {${subport} eq ${name}} {
    PortGroup stub 1.0

    platforms   any

    variant qt4 description "build Qt4 version of ${name}" {
        depends_lib-append port:${name}-qt4
    }

    variant qt5 description "build Qt5 version of ${name}" {
        depends_lib-append port:${name}-qt5
    }

    variant qt6 description "build Qt6 version of ${name}" {
        depends_lib-append port:${name}-qt6
    }

    default_variants +qt6
}