# -*- 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 118648 2014-04-07 06:22:08Z vince@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0

name                cgal
version             4.4
license             LGPL-3+ GPL-3+
categories          gis science
maintainers         vince
description         Computational Geometry Algorithm Library
long_description    \
                    The goal of the CGAL is to provide easy access to\
                    efficient and reliable geometric algorithms in the\
                    form of a C++ library. CGAL is used in various areas\
                    needing geometric computation, such as: computer\
                    graphics, scientific visualization, computer aided\
                    design and modeling, geographic information systems,\
                    molecular biology, medical imaging, robotics and\
                    motion planning, mesh generation, numerical methods...

platforms           darwin
homepage            http://www.cgal.org/

fetch.ignore_sslcert     yes
master_sites        https://gforge.inria.fr/frs/download.php/33524

distname            CGAL-${version}
checksums           rmd160  a00498ee2c5bcf0a4fd482777a617b2ff0013789 \
                    sha256  454633765d2f6c95a539612fad679dab9c24f91dbcb4141bc555e8f21d89ffed

use_bzip2           yes

worksrcdir          CGAL-${version}
depends_lib-append  port:boost \
                    port:mpfr \
                    port:zlib \
                    port:gmp \
                    port:eigen3

configure.args-append   -DCGAL_INSTALL_CMAKE_DIR="share/CGAL/cmake" \
                        -DWITH_CGAL_Qt3:BOOL=OFF \
                        -DWITH_CGAL_Qt4:BOOL=OFF \
                        -DBoost_DIR:PATH=${prefix} \
                        -DWITH_Eigen3:BOOL=ON \
                        -DWITH_ZLIB:BOOL=ON

# gcc 4.0 is too old to compile CGAL properly; see <http://www.cgal.org/FAQ.html#mac_optimization_bug>
compiler.blacklist-append gcc-4.0

variant perf description    {optimize code for current arch} {
    configure.compiler      macports-clang-3.3
    configure.optflags      -O3 -pipe -march=native
}

variant demos description {Create demos} requires qt4 {
    depends_lib-append      port:libQGLViewer \
                            port:ipe \
                            port:metis \
                            port:qt4-mac-sqlite3-plugin

    patchfiles-append       patch-CMakeLists.txt.diff

    configure.args-append   -DWITH_examples:BOOL=ON
    configure.args-append   -DWITH_demos:BOOL=ON
    configure.args-append   -DWITH_QGLViewer:BOOL=ON
    configure.args-append   -DWITH_OpenGL:BOOL=ON

  # MacPorts installs IPE version 7; make sure to use it.
    configure.args-append   -DWITH_IPE:BOOL=ON

  # include Qt's CMake defines, just in case
    configure.args-append   ${qt_cmake_defines}

    post-configure {
        # Workaround a bug in the link.txt files of the ipelets demos
        set ipelink            [glob ${worksrcpath}/demo/CGAL_ipelets/CMakeFiles/*/link.txt]
        foreach    linkfile ${ipelink} {
            reinplace -E "s|(.*)|\\1 -lipe|" ${linkfile}
        }
    }
        
    build.target-append     examples demos
    use_parallel_build      no

    post-destroot {
        xinstall -d ${destroot}${prefix}/share/${name}
        copy ${worksrcpath}/demo ${destroot}${prefix}/share/${name}
        copy ${worksrcpath}/examples ${destroot}${prefix}/share/${name}
        eval move [glob ${destroot}${prefix}/share/${name}/demo/*/*.dylib] ${destroot}${prefix}/lib/
        delete ${destroot}${prefix}/share/${name}/demo/CMakeFiles \
            ${destroot}${prefix}/share/${name}/examples/CMakeFiles 
        eval delete [glob ${destroot}${prefix}/share/${name}/demo/*/CMakeFiles] 
        eval delete [glob ${destroot}${prefix}/share/${name}/demo/*/*/CMakeFiles] 
        eval delete [glob ${destroot}${prefix}/share/${name}/examples/*/CMakeFiles] 
    }
}

variant debug description {Build with debug symbols} {
    configure.args-delete   -DCMAKE_BUILD_TYPE=Release
    configure.args-append   -DCMAKE_BUILD_TYPE=Debug

    post-destroot {
        eval exec dsymutil  [glob ${destroot}${prefix}/lib/*.dylib]
    }
}

variant qt4 description {Build with Qt4 bindings} {
    PortGroup               qt4 1.0

    configure.args-delete   -DWITH_CGAL_Qt3:BOOL=OFF \
                            -DWITH_CGAL_Qt4:BOOL=OFF
}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     CGAL-(\[0-9.\]+)\ is\ released
