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

github.setup            imageworks Field3D 1.7.3 v
name                    field3d
revision                8

checksums               rmd160  b540eed98c0c4abf529289e87032d3bdac47be5f \
                        sha256  b4f6e5c6aeb8d014be7d1d9cabc1f9464094f7f287fbfe33a37def2a73549d52 \
                        size    502745

categories              graphics
maintainers             nomaintainer
license                 BSD

description             Library for storing voxel data.
long_description        Field3D is an open source library for storing voxel data.  It \
                        provides C++ classes that handle in-memory storage and a file \
                        format based on HDF5 that allows the C++ objects to be written \
                        to and read from disk. \
                        \
                        The library and file format is both flexible and extendable. \
                        The flexibility comes from supporting heterogeneous storage of \
                        data structures, bit depths, transformations/mappings and \
                        metadata in a single file.  When functionality needs to be \
                        extended, the plugin and class factory architecture allows new \
                        data structures, mappings and file I/O routines to be added.

homepage                https://sites.google.com/site/field3d/home

compiler.cxx_standard   2014
configure.cxxflags-append \
                        -std=c++14 \
                        -Wno-enum-constexpr-conversion \
                        -Wno-unknown-warning-option

depends_build-append    port:scons
depends_lib-append      port:ilmbase \
                        port:hdf5

configure.cxxflags-prepend \
                        -I${prefix}/libexec/openexr2/include \
                        -I${prefix}/libexec/openexr2/include/OpenEXR \
                        -L${prefix}/libexec/openexr2/lib

variant universal       {}

patchfiles              patch-BuildSupport.py \
                        patch-old-OS-new-compiler.diff \
                        python3.patch \
                        patch-SConstruct

# See: https://github.com/imageworks/Field3D/issues/99
configure.cxxflags-append \
                        -DH5_USE_110_API=1 \

configure.cxxflags-append \
                        -Wno-deprecated-declarations

post-patch {
    reinplace "s#@PREFIX@#${prefix}#g" ${worksrcpath}/BuildSupport.py
    reinplace "s#@BOOSTDIR@#[boost::install_area]#g" ${worksrcpath}/BuildSupport.py
    reinplace "s#@CC@#${configure.cc} ${configure.cflags} [get_canonical_archflags cc]#" \
        ${worksrcpath}/SConstruct
    reinplace "s#@CXX@#${configure.cxx} ${configure.cxxflags} [get_canonical_archflags cxx]#" \
        ${worksrcpath}/SConstruct
}

use_configure           no
build.cmd               ${prefix}/bin/scons
build.target
build.args              verbose=1

post-build {
    set releasedir [glob ${worksrcpath}/install/darwin/*/release]
    set dylib lib/libField3D.dylib
    system "install_name_tool -id ${prefix}/${dylib} ${releasedir}/${dylib}"
}

destroot {
    set sharedir ${destroot}${prefix}/share
    set docdir ${sharedir}/doc/${name}
    set releasedir [glob ${worksrcpath}/install/darwin/*/release]

    foreach d {include lib} {
        delete ${destroot}${prefix}/${d}
        copy ${releasedir}/${d} ${destroot}${prefix}
    }

    xinstall -m 755 -d ${docdir}
    xinstall -m 644 -W ${worksrcpath} CHANGES COPYING README ${docdir}
}
