# -*- 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

# Boost 1.76 has a bug in multiprecision library,
# which leads to including x86 header on powerpc.
boost.version           1.81

# NOTE: PaPILO is a header-based library, please bump all dependent ports on update
github.setup            scipopt papilo 2.3.0 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  059cd54af22d8bcac5b610de1b791bb9b8778f2e \
                        sha256  7e8727b8fcb9c58712e00276d6c342b0319652d0f1c665472af9d22475bce9c1 \
                        size    1873573
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 {${name} eq ${subport}} {
    # and main port installs binaries, which are linked
    # against HiGHS, soplex and scipt
    depends_lib-append  port:HiGHS \
                        port:scip \
                        port:soplex

    # 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 {
        system "rm -rf ${destroot}${prefix}/lib"
        system "rm -rf ${destroot}${prefix}/include"
    }
}

# 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}]} {
    # ___atomic_fetch_add_8
    configure.ldflags-append \
                        -latomic
}

test.run                yes
