# -*- 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
# $Id: Portfile 107921 2013-07-09 08:56:22Z stromnov@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0
PortGroup           qt4 1.0

name                orfeotoolbox
version             3.18.0
revision            1
categories          gis graphics
platforms           darwin
license             CeCILL

maintainers         gmail.com:julien.malik stromnov openmaintainer

description         OrfeoToolbox - Free library of image processing algorithms

long_description    ORFEO Toolbox (OTB) is distributed as an open source library of image \
                    processing algorithms. OTB is based on the medical image processing library \
                    ITK and offers particular functionalities for remote sensing image processing \
                    in general and for high spatial resolution images in particular. OTB is \
                    distributed under a free software license CeCILL (similar to GNU GPL) to \
                    encourage contribution from users and to promote reproducible research.

homepage            http://www.orfeo-toolbox.org/otb/
master_sites        sourceforge:orfeo-toolbox

distname            OTB-${version}
extract.suffix      .tgz

checksums           rmd160  6e7f79975f4e6856b46306adacb7789874989a09 \
                    sha256  01a866844f7bc1306b52db9584c3f39b19e57fca9a3e30c9c7d82a722689c189

worksrcdir          ${worksrcdir}/build
patch.dir           ${workpath}/${distname}

depends_lib-append  port:tiff \
                    port:jpeg \
                    port:libgeotiff \
                    port:gdal \
                    port:expat \
                    port:fltk-devel \
                    port:boost \
                    port:curl \
                    port:libkml \
                    port:tinyxml \
                    port:muparser \
                    port:gettext \
                    port:opencv

pre-build {
    if { ![catch {set installed [lindex [registry_active libsvm] 0]}]} {
        ui_msg "OrfeoToolbox will fail to build because the 'libsvm' port is active. Deactivate"
        ui_msg "'libsvm' by running 'port deactivate libsvm' and try again. You may reactivate"
        ui_msg "'libsvm' after installing OrfeoToolbox by running 'port activate libsvm'."
        return -code error "check is installed"
    }
}

post-extract {
    file mkdir ${worksrcpath}
}

use_parallel_build      no

configure.args-append   ../ \
                        -DBUILD_APPLICATIONS=ON \
                        -DBUILD_EXAMPLES=OFF \
                        -DBUILD_TESTING=OFF

# The default installation path for library is ${prefix}/lib/otb
# But the cmake PortGroup is using rpath and CMAKE_INSTALL_NAME_DIR=${prefix}/lib
configure.args-delete   -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib
configure.args-append   -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib/otb

# Use external FLTK (internal version is broken)
configure.args-append   -DOTB_USE_EXTERNAL_FLTK=ON

# Use external libs, where available
configure.args-append   -DOTB_USE_EXTERNAL_EXPAT=ON \
                        -DOTB_USE_EXTERNAL_BOOST=ON \
                        -DOTB_USE_EXTERNAL_TINYXML=ON \
                        -DOTB_USE_EXTERNAL_LIBKML=ON \
                        -DOTB_USE_EXTERNAL_MUPARSER=ON \
                        -DOTB_USE_CURL=ON \
                        -DOTB_USE_OPENCV=ON

# Use internal ITK (MacPorts ITK is outdated, and internal ITK is patched)
configure.args-append   -DOTB_USE_EXTERNAL_ITK=OFF \
                        -DITK_USE_REVIEW=ON \
                        -DITK_USE_OPTIMIZED_REGISTRATION_METHODS=ON \
                        -DOTB_USE_PATENTED=OFF \
                        -DITK_USE_PATENTED=OFF

# Use internal openjpeg (OTB needs 2.0 API, but does not support using the external lib yet)
configure.args-append   -DOTB_USE_JPEG2000=ON

# Use internal libs (no MacPorts alternatives available)
configure.args-append   -DOTB_USE_EXTERNAL_OPENTHREADS=OFF \
                        -DOTB_USE_LIBLAS=ON \
                        -DOTB_USE_EXTERNAL_LIBLAS=OFF \
                        -DOTB_USE_EXTERNAL_OSSIM=OFF \
                        -DOTB_USE_SIFTFAST=ON

variant qt4 description {Wrap QT4} {
    depends_lib-append      port:qt4-mac
    configure.args-append   -DOTB_WRAP_QT=ON
}

variant python27 description {Wrap Python 2.7} {
    depends_lib-append      port:python27 \
                            port:swig \
                            port:swig-python

    patchfiles-append       patch-Code-Wrappers-SWIG-__init__.py.in.diff \
                            patch-Code-Wrappers-SWIG-CMakeLists.txt.diff

    configure.args-append   -DOTB_WRAP_PYTHON=ON \
                            -DPYTHON_EXECUTABLE=${prefix}/bin/python2.7 \
                            -DOTB_INSTALL_PYTHON_DIR=${frameworks_dir}/Python.framework/Versions/2.7/lib/python2.7/site-packages
}

livecheck.regex     "OTB-(\\d+(?:\\.\\d+)*)${extract.suffix}"
