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

PortSystem              1.0
PortGroup               cmake 1.1
PortGroup               compilers 1.0
PortGroup               github 1.0
PortGroup               qt4 1.0

github.setup            FreeCAD FreeCAD 0.18.4
revision                0
name                    freecad
categories              cad
platforms               darwin
maintainers             {gmail.com:mark.brethen @mbrethen} {mps @Schamschula} 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                https://www.freecadweb.org

checksums               rmd160  2fdb6bb247571e2ffaffaca1defb02ca0b2e1cc5 \
                        sha256  d2f10f861cbcc9d19b34f79cd1c96baca2f23174f232e834f64a7c4a74f5f1e7 \
                        size    219760632

depends_build-append    port:doxygen

depends_lib-append      port:boost \
                        port:Coin-framework \
                        port:eigen3 \
                        port:freetype \
                        port:opencascade \
                        port:py27-backports-functools_lru_cache \
                        port:py27-matplotlib \
                        port:py27-pivy \
                        port:py27-pyside \
                        port:py27-pyside-tools \
                        port:py27-shiboken \
                        port:SoQt \
                        port:swig \
                        port:swig-python \
                        port:xercesc3 \
                        port:zlib

depends_run             port:qt4-mac-sqlite3-plugin

patchfiles              cMake-FindCoin3D.cmake.diff \
                        patch-src-Main-MainPy.cpp.diff

# disable FreeCAD FEM module, as it requires hdf5 1.8.x
patchfiles-append       patch-CMakeLists.txt.diff

patchfiles-append       FindPySideTools.cmake.patch

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         require_fortran -g95

cmake.install_prefix    ${prefix}/libexec/${name}
cmake.install_rpath     ${cmake.install_prefix}/lib

configure.pre_args-replace \
                        -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
                        -DCMAKE_INSTALL_NAME_DIR=${cmake.install_prefix}/lib

configure.args-append   -DCMAKE_INSTALL_DATADIR=${prefix}/share/${name} \
                        -DCMAKE_INSTALL_DOCDIR=${prefix}/share/doc/${name} \
                        -DCMAKE_FRAMEWORK_PATH=${frameworks_dir} \
                        -DMACPORTS_PREFIX=${prefix} \
                        -DPYSIDEUIC4BINARY=${prefix}/bin/pyside-uic-2.7 \
                        -DPYSIDERCC4BINARY=${prefix}/bin/pyside-rcc-2.7

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 -DBUILD_ROBOT=NO \
        -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.4 \
        -DPySide_DIR=${python_prefix}/lib/cmake/PySide-1.2.4 \
        -DOCE_DIR=${frameworks_dir}/OCE.framework/Versions/0.17/Resources
}

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

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

    # create stub App
    set appdir ${destroot}${applications_dir}/FreeCAD.app
    xinstall -d ${appdir}/Contents/MacOS
    xinstall -d ${appdir}/Contents/Resources

    xinstall -m 644 ${filespath}/Info.plist ${appdir}/Contents/
    xinstall -m 644 ${filespath}/FreeCAD.icns ${appdir}/Contents/Resources/
    xinstall -m 755 ${filespath}/FreeCAD ${appdir}/Contents/MacOS

    reinplace -W ${appdir}/Contents "s,@@VERSION@@,${version},g" Info.plist
    reinplace -W ${appdir}/Contents/MacOS "s,@@PREFIX@@,${prefix},g" FreeCAD
}

variant oce description {use Community Edition version of Open CASCADE} {
     depends_lib-replace port:opencascade port:oce
}

github.livecheck.regex  {(\d\.\d+(\.\d+)?(?!_pre))}