# -*- 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 105914 2013-05-09 19:59:13Z vince@macports.org $

PortSystem			1.0
PortGroup			cmake 1.0

name				cgal
version				4.2
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/32359

distname			CGAL-${version}
checksums           rmd160  90ebc257eb0f84c3d2ee8063e2f4881e5b933091 \
                    sha256  a14268c5dae86e4f2f5c9fd0c12c5fcd36cfd9db2b5e3af34e04a7233bac820d

# currently, the 4.2 bz2 tar ball is actually compressed with gzip
#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 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
