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

PortSystem              1.0
PortGroup               cmake 1.0
PortGroup               compilers 1.0

name                    freecad
version                 0.14.3702
revision                1
categories              cad
platforms               darwin
maintainers             gmail.com:mark.brethen \
                        openmaintainer
license                 LGPL-2+

description \
    FreeCAD is a general purpose feature-based, parametric 3D modeler.

long_description \
    FreeCAD is a general purpose feature-based, parametric 3D modeler for \
    CAD, MCAD, CAx, CAE and PLM, aimed directly at mechanical engineering \
    and product design but also fits a wider range of uses in engineering, \
    such as architecture or other engineering specialties. It is 100% Open \
    Source (LGPL2+ license) and extremely modular, allowing for very \
    advanced extension and customization.

homepage                http://www.freecadweb.org/
master_sites            sourceforge:project/free-cad/FreeCAD%20Source/

checksums               rmd160 b62582b1283c874f07d9407c7e7a87bb94591f66 \
                        sha256 ee24cf3542bfb1a887a12d2df52458bcc0e3e82679370c449b9d8b5b473b9dc9

depends_lib-append      port:python27 \
                        port:boost \
                        port:xercesc \
                        port:zlib \
                        port:oce \
                        port:swig \
                        port:eigen3 \
                        port:qt4-mac \
                        port:freetype \
                        port:Coin-framework \
                        port:SoQt \
                        port:py27-shiboken \
                        port:py27-pyside \
                        port:swig-python

depends_run             port:qt4-mac-sqlite3-plugin

patchfiles              cMake-FindCoin3D.cmake.diff \
                        src-App-FreeCADInit.py.diff \
                        src-Mod-Sketcher-CMakeLists.txt.diff

post-patch {
    reinplace "s|QLibraryInfo::location.*|QLatin1String\(\"${applications_dir}/Qt4/\"\);|" \
        ${worksrcpath}/src/Gui/Assistant.cpp

    reinplace "s|/Applications|${applications_dir}|" \
        ${worksrcpath}/src/Mod/OpenSCAD/OpenSCADUtils.py
}

compilers.choose        fc
compilers.setup         -dragonegg -g95 -gcc gcc48 require_fortran

configure.args-delete   -DCMAKE_INSTALL_RPATH=${prefix}/lib \
                        -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib

configure.args-append   -DCMAKE_INSTALL_RPATH=${prefix}/libexec/${name}/lib \
                        -DCMAKE_INSTALL_NAME_DIR=${prefix}/libexec/${name}/lib \
                        -DCMAKE_INSTALL_PREFIX=${prefix}/libexec/${name} \
                        -DCMAKE_INSTALL_DATADIR=${prefix}/share/${name} \
                        -DCMAKE_INSTALL_DOCDIR=${prefix}/share/doc/${name} \
                        -DCMAKE_FRAMEWORK_PATH=${frameworks_dir}

pre-configure {
    # The c++ compiler is used for linking instead of fc.
    # -L needs a path to a directory.

    set libgfortran [exec ${configure.fc} --print-file-name libgfortran.a]
    configure.ldflags-append "-L[file dirname ${libgfortran}]"

    set python_prefix [exec ${prefix}/bin/python2.7-config --prefix]
    configure.args-append   -DFREECAD_BUILD_ROBOT=OFF \
        -DPYTHON_LIBRARY=${python_prefix}/Python \
        -DPYTHON_INCLUDE_DIR=${python_prefix}/Headers \
        -DPYTHON_EXECUTABLE=${python_prefix}/bin/python2.7 \
        -DShiboken_DIR=${python_prefix}/lib/cmake/Shiboken-1.2.2 \
        -DPySide_DIR=${python_prefix}/lib/cmake/PySide-1.2.2 \
        -DOCE_DIR=${frameworks_dir}/OCE.framework/Versions/0.15/Resources
}

post-destroot {
    # link the executables back
    ln -s ${prefix}/libexec/${name}/bin/FreeCAD \
        ${destroot}${prefix}/bin

    ln -s ${prefix}/libexec/${name}/bin/FreeCADCmd \
        ${destroot}${prefix}/bin
}

livecheck.regex         ${name}.(\[0-9.\]+)${extract.suffix}