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

github.setup        rordenlab dcm2niix 1.0.20241208 v
version             ${github.version}

revision            1

categories          science
maintainers         {eborisch @eborisch} openmaintainer

description         DICOM to NifTI converter

long_description    dcm2niix is a designed to convert neuroimaging data from \
                    the DICOM format to the NIfTI format

license             BSD MIT

checksums \
    rmd160  a103c5c64b6e33a01734ca8ee7a622bbb3e3e52f \
    sha256  0bf962778ea924af98eb27dc932f27d7e2ab9ca459bb7537356d2c28ca58307e \
    size    516181

variant docs description {Install man pages} {
    depends_build-append    port:py312-sphinx \
                            port:py312-sphinxcontrib-applehelp \
                            port:py312-sphinxcontrib-devhelp \
                            port:py312-sphinxcontrib-htmlhelp \
                            port:py312-sphinxcontrib-jsmath \
                            port:py312-sphinxcontrib-qthelp \
                            port:py312-sphinxcontrib-serializinghtml
    configure.args-append   -DBUILD_DOCS=ON
}

default_variants        +docs

depends_lib-append      port:openjpeg \
                        port:yaml-cpp \
                        port:zlib

depends_build-append    port:pkgconfig

if {${os.major} <= 10} {
    # Lion+ (with Xcode 4.1+) have git; earlier need to bring their own
    depends_build-append    port:git
}

compiler.cxx_standard   2011

# Linking with yaml-cpp currently broken; haven't chased down; revisit later.
# Disabling BATCH_VERSION until this is resolved.
configure.args-append   -DUSE_OPENJPEG=System \
                        -DBATCH_VERSION=ON \
                        -DZLIB_IMPLEMENTATION=System \
                        -DYAML-CPP_IMPLEMENTATION=System

# cmake re-runs during build; retain configured CC and CXX (Only an issue in
# the default configuration on <= 10.6 where we are not using system clang.)
build.env-append        "CC=${configure.cc} [get_canonical_archflags cc]" \
                        "CXX=${configure.cxx} [get_canonical_archflags cxx]"

patch {
    reinplace "/NAMES/s/$/ sphinx-build-3.12/" docs/CMakeLists.txt
}

post-destroot {
    set docdir ${prefix}/share/doc/${subport}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        README.md \
        VERSIONS.md \
        license.txt \
        ${destroot}${docdir}
}