# -*- 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 91314 2012-03-29 13:58:38Z vince@macports.org $

PortSystem			1.0
PortGroup			cmake 1.0

name				cgal
version				4.0
revision			1
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/30387/

distname			CGAL-${version}
checksums           rmd160  57b3112a511a5c811e1382dfe7cac3b8600c9b56 \
                    sha256  dde1431f56537890666dc6a396bcd591f04397998dfbe20c2897c4ed74da5099

depends_lib-append	port:boost \
					port:mpfr \
					port:zlib \
					port:gmp

configure.args-append   -DCGAL_INSTALL_CMAKE_DIR="lib/cmake" \
                        -DWITH_CGAL_Qt3:BOOL=OFF \
                        -DWITH_CGAL_Qt4:BOOL=OFF

# gcc 4.0 is too old to compile CGAL properly; see <http://www.cgal.org/FAQ.html#mac_optimization_bug>
if {${configure.compiler} == "gcc-4.0"} {
    configure.compiler gcc-4.2
    if {![file executable ${configure.cc}]} {
        depends_build-append port:apple-gcc42
        configure.compiler apple-gcc-4.2
    }
}

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

	patchfiles				patch-CMakeLists.txt.diff

        # The demos don't compile with clang.
        if {${configure.compiler} == "clang"} {
            configure.compiler llvm-gcc-4.2
        }

	configure.args-append	-DWITH_examples=TRUE
	configure.args-append	-DWITH_demos=TRUE

  # MacPorts installs IPE version 7; make sure to use it.
	configure.args-append	-DWITH_IPE_7=TRUE

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

	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
