# -*- 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 117487 2014-02-28 20:18:21Z mojca@macports.org $

PortSystem          1.0
PortGroup           muniversal 1.0

name                cmake
version             2.8.12.2
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          devel
license             BSD
installs_libs       no
maintainers         css
description         Cross-platform make
long_description    An extensible, open-source system that manages the build    \
                    process in an operating system and compiler independent manner. \
                    Unlike many cross-platform systems, CMake is designed to be     \
                    used in conjunction with the native build environment.
homepage            http://www.cmake.org/
master_sites        http://www.cmake.org/files/v${branch}/
platforms           darwin freebsd

checksums           rmd160  ee92327c3870f3ae2ea997d0258b0ef141e90525 \
                    sha256  8c6574e9afabcb9fc66f463bb1f2f051958d86c85c37fccf067eb1a44a120e5e

depends_lib-append  port:libidn port:openssl

patchfiles          patch-CMakeFindFrameworks.cmake.diff \
                    patch-Modules-FindFreetype.cmake.diff \
                    patch-Modules-FindQt4.cmake.diff \
                    patch-Modules-noArchCheck.diff

configure.env-append \
                    CMAKE_PREFIX_PATH=${prefix} \
                    CMAKE_INCLUDE_PATH=${prefix}/include/ncurses \
                    CMAKE_LIBRARY_PATH=${prefix}/lib

configure.args      --mandir=/share/man --docdir=/share/doc/cmake \
                    --parallel=${build.jobs} \
                    --init=${worksrcpath}/macports.cmake
configure.universal_args
configure.post_args

# Leopard's Rosetta has some difficulties configuring the ppc slice
platform darwin 9 {
    global universal_archs_supported
    if {${build_arch} eq "i386" || ${build_arch} eq "x86_64"} {
        supported_archs i386 x86_64
    } elseif {${build_arch} eq "ppc" || ${build_arch} eq "ppc64"} {
        supported_archs ppc ppc64
    }
    set universal_archs_supported ${supported_archs}
}

platform darwin 11 {
    # TODO: Figure out why using libc++ fails.
    #       Since nothing links against cmake and cmake is just using
    #       the STL, we're safe to force libstdc++
    if {[info exists configure.cxx_stdlib]} {
        configure.cxx_stdlib libstdc++
    }
}

post-patch {
    # copy cmake init file, ready to be patched below
    copy ${filespath}/macports.cmake ${worksrcpath}

    # patch PREFIX
    reinplace "s|__PREFIX__|${prefix}|g" ${worksrcpath}/macports.cmake
    reinplace "s|__PREFIX__|${prefix}|g" ${worksrcpath}/Modules/CMakeFindFrameworks.cmake
}

post-destroot {
    xinstall -d -m 0755 ${destroot}${prefix}/share/emacs/site-lisp
    xinstall -m 0644 ${worksrcpath}/Docs/cmake-mode.el \
        ${destroot}${prefix}/share/emacs/site-lisp
    foreach type {syntax indent} {
        xinstall -d -m 0755 ${destroot}${prefix}/share/vim/vimfiles/${type}
        xinstall -m 0644 -W ${worksrcpath}/Docs cmake-${type}.vim \
            ${destroot}${prefix}/share/vim/vimfiles/${type}
    }
    if ([variant_isset gui]) {
        set app CMake
        xinstall -d ${destroot}${applications_dir}/${app}.app/Contents/MacOS \
            ${destroot}${applications_dir}/${app}.app/Contents/Resources
        xinstall -m 644 ${filespath}/Info.plist.in ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
        reinplace "s|@VERSION@|${version}|g" ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
        reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
        ln -s ${prefix}/bin/cmake-gui ${destroot}${applications_dir}/${app}.app/Contents/MacOS/cmake-gui
        xinstall -m 644 ${worksrcpath}/Source/QtDialog/CMakeSetup.icns ${destroot}${applications_dir}/${app}.app/Contents/Resources/CMakeSetup.icns
    }
}

variant gui description {Qt4 based cmake-gui} {
    PortGroup qt4 1.0
    patchfiles-append patch-CMakeLists.txt.diff
    configure.args-append --qt-gui --qt-qmake=${qt_qmake_cmd}
}

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