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

github.setup        libKriging libKriging 0.8.3 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            3
categories          math
license             Apache-2
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Kriging library for performance and wide language support
long_description    {*}${description}

fetch.type          git

post-fetch {
    system -W ${worksrcpath} "git submodule update --init"
}

cmake.build_type    MinSizeRel

compilers.choose    cc cxx fc f90
compilers.setup     require_fortran -g95
compiler.cxx_standard 2017

patchfiles-append   patch-CMakeLists.diff

post-patch {
    reinplace "s,__FC__,${configure.fc}," ${worksrcpath}/CMakeLists.txt \
                    ${worksrcpath}/dependencies/lbfgsb_cpp/CMakeLists.txt \
                    ${worksrcpath}/dependencies/lbfgsb_cpp/cmake/ExternalFortranProject.cmake.in
}

depends_build-append \
                    path:bin/pkg-config:pkgconfig
depends_lib-append  port:armadillo \
                    port:hdf5

# Yes, explicitly passing Fortran_COMPILER is needed.
configure.pre_args-append \
                    -DCMAKE_Fortran_COMPILER=${configure.fc}

configure.args-append \
                    -DBUILD_SHARED_LIBS=ON

# Automatic installation fails, since the build system magically pulls out Armadillo duplicates.

configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

test.run            yes
