# -*- 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
PortGroup           cmake 1.1

# Ports that depend on this port must be revbump after update:
# - tiledb
github.setup        gabime spdlog 1.16.0 v
github.tarball_from archive
revision            0
epoch               1
conflicts           spdlog0
categories          devel
license             MIT
maintainers         {protomail.com:XNephila @XNephila} \
                    {judaew @judaew} \
                    openmaintainer

description         Very fast, header only, C++ logging library.
long_description    {*}${description}

checksums           rmd160  c514c9e2d9f57d2c93f24db0f739b9d6ffa4bb96 \
                    sha256  8741753e488a78dd0d0024c980e1fb5b5c85888447e309d9cb9d949bdb52aa3e \
                    size    280382

# Default libfmt version, customize when adding subports
set libfmt_ver      10

compiler.cxx_standard           2011
compiler.thread_local_storage   yes

# Clear optflags; controlled by project, via cmake build type
configure.optflags

if {[variant_isset debug]} {
    cmake.build_type Debug
} else {
    cmake.build_type RelWithDebInfo
}

if {[string match *clang* ${configure.compiler}]} {
    configure.cxxflags-append \
                     -Wno-macro-redefined \
                     -Wno-error=unknown-warning-option \
                     -Wno-unknown-warning-option
}

configure.args-append \
                    -DSPDLOG_BUILD_EXAMPLE=OFF \
                    -DSPDLOG_FMT_EXTERNAL=OFF \
                    -DSPDLOG_BUILD_SHARED=ON \
                    -DSPDLOG_BUILD_TESTS=OFF

variant fmt_external description {Use external fmt library instead of bundled} {
    patchfiles-append \
                    patch-spdlog-fmt-external.diff
    cmake.module_path-append \
                    ${prefix}/lib/libfmt${libfmt_ver}/cmake
    depends_lib-append \
                    port:libfmt${libfmt_ver}
    configure.args-replace \
                    -DSPDLOG_FMT_EXTERNAL=OFF \
                    -DSPDLOG_FMT_EXTERNAL=ON
}

# Remove this subport when nheko and mtxclient have a new release.
subport ${name}-fmt8 {
    set libfmt_ver      8
    revision            0
    long_description    {*}${description} This port exists to support stable the \
                        latest stable release of mtxclient and nheko.

    # Allow this subport to coexist with other spdlog interations
    cmake.install_prefix \
                    ${prefix}/libexec/${subport}
}

variant tests description {Enable test support} {
    test.run        yes

    depends_build-append \
                    path:bin/git:git \
                    port:pkgconfig

    configure.args-replace \
                    -DSPDLOG_BUILD_TESTS=OFF \
                    -DSPDLOG_BUILD_TESTS=ON
}

default_variants +fmt_external
