# -*- 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           active_variants 1.1
PortGroup           boost 1.0
PortGroup           cmake 1.1
PortGroup           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1

github.setup        kpeeters cadabra2 2.5.14
github.tarball_from archive
revision            1

categories          math
license             GPL-3+
maintainers         nomaintainer

description         A field theory approach to symbolic computer algebra
long_description    Cadabra is a computer algebra system for the \
                    manipulation of what could loosely be called \
                    tensorial expressions. It is aimed at, though not \
                    necessarily restricted to, theoretical high energy \
                    physicists. Because of its target audience, the \
                    program's interface, storage system and underlying \
                    philosophy differ substantially from other computer \
                    algebra systems.

homepage            https://cadabra.science/index.html

checksums           rmd160  012bacf39726c315cb409e6090fb096a4e9bc9e5 \
                    sha256  9e85977f49dae20230f4865a4f879d819cbfaaf3797d22adef1407990eab66ff \
                    size    33370920

# cadabra2-gtk(12276) malloc: *** error for object 0x365c034: Non-aligned pointer being freed
# legacysupport is only used for wrappers with libstdc++ builds.
legacysupport.newest_darwin_requires_legacy 0
legacysupport.redirect_bins cadabra-server cadabra2-cli cadabra2-gtk \
                    cadabra2cadabra cadabra2html cadabra2ipynb \
                    cadabra2latex cadabra2python cdb-nbtool

compiler.cxx_standard 2017

set python.version  313

set python.branch   [string index ${python.version} 0].[string range ${python.version} 1 end]
set python.prefix   ${frameworks_dir}/Python.framework/Versions/${python.branch}

# TODO: Do this automatically via Boost portgroup
cmake.module_path-append \
                    [boost::lib_dir]/cmake

depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    port:pcrexx

depends_lib-append  port:adwaita-icon-theme \
                    port:dvipng \
                    port:gmp \
                    port:gtkmm3 \
                    port:hicolor-icon-theme \
                    port:pcre \
                    port:py${python.version}-sympy \
                    port:sqlite3

platform darwin {
    # memory_resource is still under experimental and incomplete
    if {${os.major} < 23} {
        compiler.blacklist  clang
    }
}

# X11 render issue. See https://github.com/XQuartz/XQuartz/issues/31
require_active_variants     gtk3    quartz

# cadabra2 uses its own bundled version of nlohmann/json.hpp
conflicts_build     nlohmann-json

configure.args      -DENABLE_MATHEMATICA=OFF \
                    -DPYBIND11_PYTHON_VERSION=${python.branch} \
                    -DSQLITE3_INCLUDE_DIR=${prefix}/include

post-destroot {
    ln ${destroot}${python.prefix}/lib/python${python.branch}/site-packages/cadabra2.cpython-${python.version}-darwin.so \
            ${destroot}${prefix}/lib/cadabra2.cpython-${python.version}-darwin.so
}

post-activate {
    system "${prefix}/bin/texhash"
    system "gtk-update-icon-cache ${prefix}/share/icons/hicolor"
}

variant texmacs description {install TeXmacs front end} {
    depends_run-append      port:TeXmacs
}

github.livecheck.regex  {(\d\.\d+(\.\d+))}
