# -*- 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                       github 1.0
PortGroup                       legacysupport 1.1

github.setup                    symengine symengine 0.14.0 v
revision                        2
categories                      math science
license                         MIT
maintainers                     {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
description                     a fast symbolic manipulation library
long_description                ${name} is {*}${description}, written in C++.

checksums                       rmd160  1bf42e32dcbe75723dcda00adcb19af4f50e1278 \
                                sha256  11c5f64e9eec998152437f288b8429ec001168277d55f3f5f1df78e3cf129707 \
                                size    944589
github.tarball_from             archive

# LLVM_MINIMUM_REQUIRED_VERSION is set to 3.8
#     see https://github.com/symengine/symengine/blob/master/CMakeLists.txt
# mimic LLVM requirements uses by MacPorts base
#     see https://github.com/macports/macports-ports/blob/master/_resources/port1.0/compilers/clang_compilers.tcl
if {${os.major} >= 12 || ${os.platform} ne "darwin"} {
    set llvm_version            18
} elseif {${configure.build_arch} in [list ppc ppc64]} {
    set llvm_version            7.1.1
} elseif {${os.major} >= 10} {
    set llvm_version            11
} elseif {${os.major} >= 9} {
    set llvm_version            7.0
} else {
    set llvm_version            none
}

# The build uses C++11, why 2014 is being set here?
compiler.cxx_standard           2014

depends_lib-append              port:flint \
                                port:gmp \
                                port:libmpc \
                                port:mpfr
if {${llvm_version} ne "none"} {
    if {${configure.build_arch} in [list ppc ppc64]} {
        depends_lib-append      port:llvm-powerpc
    } else {
        depends_lib-append      port:llvm-${llvm_version}
    }
}

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

# symengine sets its own optimization flags
configure.optflags

configure.args-append           -DBUILD_BENCHMARKS=OFF \
                                -DBUILD_FOR_DISTRIBUTION=ON \
                                -DBUILD_SHARED_LIBS=ON \
                                -DBUILD_TESTS=OFF

# see https://github.com/symengine/symengine/blob/master/README.md#recommended-options-to-build
configure.args-append           -DINTEGER_CLASS=flint \
                                -DWITH_GMP=ON \
                                -DWITH_MPC=ON \
                                -DWITH_MPFR=ON
                                
if {${llvm_version} ne "none"} {
    configure.args-append       -DWITH_LLVM=ON
} else {
    configure.args-append       -DWITH_LLVM=OFF
}
configure.args-append           -DWITH_SYMENGINE_THREAD_SAFE=ON

# see https://github.com/symengine/symengine/issues/1671
configure.args-append           -DWITH_COTIRE=OFF

if {${llvm_version} ne "none"} {
    cmake.prefix_path-append    ${prefix}/libexec/llvm-${llvm_version}
}

# mirrors setings in llvm-11
legacysupport.use_static                     yes
# futimens
legacysupport.newest_darwin_requires_legacy  16

if {[string match *gcc* ${configure.compiler}]} {
    # ___atomic_store_8
    configure.ldflags-append    -latomic
}

variant tests description {Enable tests} {
    test.run                    yes
    configure.args-replace      -DBUILD_TESTS=OFF \
                                -DBUILD_TESTS=ON
    test.args-append            DYLD_LIBRARY_PATH=${cmake.build_dir}/symengine
}
