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

# Boost 1.76 has a bug in multiprecision library,
# which leads to including x86 header on powerpc.
boost.version           1.88
# If this port is active, wrong headers get picked.
conflicts_build         boost

# NOTE: PaPILO is a header-based library, please bump all dependent ports on update
github.setup            scipopt papilo 3.0.1 v
revision                0
categories              math
license                 {LGPL-3 GPL-3}

maintainers             nomaintainer

description             Parallel Presolve for Integer and Linear Optimization
long_description        {*}${description}

checksums               rmd160  62aa22b6d9ccf4008ad2b7be1946eba6c5b8e44f \
                        sha256  b7c70e754c23f8bef5843ac02b82f9dc1707a653c867474123e635951305af88 \
                        size    1949915
github.tarball_from     archive

compilers.setup         require_fortran
compiler.cxx_standard   2014

compiler.blacklist-append {clang < 1000}

depends_lib-append      path:lib/libopenblas.dylib:OpenBLAS \
                        port:gmp \
                        port:onetbb

# In fact this has no effect at the moment:
# https://github.com/scipopt/papilo/issues/61
configure.args-append   -DBUILD_SHARED_LIBS=ON

subport libpapilo {
    # PaPILO as a library doesn't need any solver nor binaries
    configure.args-append \
                        -DSCIP=OFF \
                        -DSOPLEX=OFF \
                        -DHIGHS=OFF \
                        -DPAPILO_NO_BINARIES=ON
}

if {${subport} eq ${name}} {
    # If this happens to cause breakages, add legacysupport.redirect_bins papilo
    # papilo(55892,0xa0260620) malloc: *** error for object 0x2e139e8: pointer being freed was not allocated

    # and main port installs binaries, which are linked
    # against HiGHS, soplex and scipt
    depends_lib-append  port:HiGHS \
                        port:mpfr \
                        port:scip \
                        port:soplex \
                        port:zlib

    configure.args-append \
                        -DSCIP=ON \
                        -DSOPLEX=ON \
                        -DHIGHS=ON

    # VersionLogger.hpp: fatal error: Highs.h: No such file or directory
    configure.cppflags-append \
                        -I${prefix}/include/highs

    # but it shouldn't install libraries and headers
    post-destroot {
        delete ${destroot}${prefix}/lib
        delete ${destroot}${prefix}/include
        delete ${destroot}${prefix}/share
    }
}

# PAPILO may be linked against libquadmath, prevent that by using GMP.
configure.args-append   -DGMP=ON \
                        -DQUADMATH=OFF

# https://github.com/scipopt/papilo/issues/60
if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    # ___atomic_fetch_add_8
    configure.ldflags-append \
                        -latomic
}

test.run                yes
