# -*- 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               qt5 1.0
PortGroup               github 1.0
PortGroup               cmake 1.0
PortGroup               compiler_blacklist_versions 1.0

github.setup            keepassxreboot keepassxc 2.3.1
name                    KeePassXC
categories              security aqua
maintainers             {@yan12125 gmail.com:yan12125} openmaintainer

description             KeePassXC is a cross-platform community-driven port \
                        of the Windows application “Keepass Password Safe”.
long_description        KeePassXC is a community fork of KeePassX with the \
                        goal to extend and improve it with new features and \
                        bugfixes to provide a feature-rich, fully \
                        cross-platform and modern open-source password manager.

platforms               darwin
license                 GPL-2+
license_noconflict      openssl

homepage                https://keepassxc.org
github.tarball_from     releases
use_xz                  yes
distname                ${github.project}-${version}-src
worksrcdir              ${github.project}-${version}

checksums               rmd160  10d2094e10383ea9ee91ebda65c46d513524f87f \
                        sha256  ce7d8251d4d5b35f602ff521764910964da6d8a67397399855a6e8c5ff5db9bd \
                        size    4085284

patchfiles              patch-no-deployqt.diff

qt5.depends_component   qtmacextras
qt5.depends_build_component \
                        qttools

depends_lib-append      port:argon2 \
                        port:libgcrypt \
                        port:libsodium \
                        port:zlib

# KeePassXC uses -fstack-protector-strong on Clang [1]. That flag is not
# available until clang 602 [2] or upstream clang 3.5 [3]
# [1] https://github.com/keepassxreboot/keepassxc/blob/develop/CMakeLists.txt
# [2] https://opensource.apple.com/source/clang/clang-600.0.57/src/tools/clang/lib/CodeGen/CodeGenModule.cpp.auto.html
#     https://opensource.apple.com/source/clang/clang-602.0.53/src/tools/clang/lib/CodeGen/CodeGenModule.cpp.auto.html
# [3] https://github.com/llvm-project/clang/blob/release_34/lib/CodeGen/CodeGenModule.cpp
#     https://github.com/llvm-project/clang/blob/release_35/lib/CodeGen/CodeGenModule.cpp
compiler.blacklist-append {clang < 602} macports-clang-3.4 macports-clang-3.3
# XXX: the following line shouldn't be necessary - revisit when libc++ becomes the default and default compiler configurations are updated
compiler.fallback-append macports-clang-5.0 macports-clang-4.0 macports-clang-3.9

cmake.out_of_source     yes
configure.pre_args-append \
    -DCMAKE_INSTALL_PREFIX=${applications_dir} \
    -DCMAKE_INSTALL_MANDIR=${prefix}/share/man \
    -DWITH_XC_HTTP=ON \
    -DWITH_XC_BROWSER=ON \
    -DWITH_XC_SSHAGENT=ON \
    -DWITH_XC_NETWORKING=ON

if {${configure.cxx_stdlib} eq "libstdc++"} {
    configure.pre_args-append   -DWITH_CXX11=OFF
}

if {${os.major} < 12} {
    # autotype does not compile on 10.7
    configure.pre_args-append   -DWITH_XC_AUTOTYPE=OFF
}

variant yubikey description {Enable YubiKey challenge-response support} {
    configure.pre_args-append \
        -DWITH_XC_YUBIKEY=ON
    depends_lib-append port:ykpers
}

pre-configure {
    reinplace "s#/usr/local/bin#${prefix}/bin#" \
        ${worksrcpath}/CMakeLists.txt
}

post-destroot {
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -W ${worksrcpath} COPYING LICENSE.BOOST-1.0 LICENSE.BSD \
             LICENSE.CC0 LICENSE.GPL-2 LICENSE.GPL-3 LICENSE.LGPL-2.1 \
             LICENSE.LGPL-3 LICENSE.NOKIA-LGPL-EXCEPTION \
             ${destroot}${prefix}/share/doc/${name}
}

test.run        yes
test.target     test