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

name                cmake-bootstrap
categories          devel
license             BSD
installs_libs       no
maintainers         nomaintainer
homepage            http://www.cmake.org/
platforms           darwin
dist_subdir         cmake

set branch          3.9
version             ${branch}.4
distname            cmake-${version}

checksums           rmd160  bb9c30f2726413f0d7d7b92e0294b61438151d62 \
                    sha256  b5d86f12ae0072db520fdbdad67405f799eb728b610ed66043c20a92b4906ca1 \
                    size    7705052

master_sites        https://cmake.org/files/v${branch}/
description         Cross-platform make pegged at version ${version}. No dependencies.
long_description    ${description} This was the last version of cmake to not require c++11.

# save original prefix
set orig_prefix    ${prefix}
prefix             ${prefix}/libexec/${name}

patchfiles-append \
    patch-Modules-FindQt4.cmake.release.diff \
    patch-Modules-FindFreetype.cmake.release.diff \
    patch-Modules-noArchCheck.release.diff \
    patch-CMakeFindFrameworks.cmake.release.diff \
    patch-Source_CMakeVersionCompute.cmake.release.diff \
    patch-Source-kwsys-kwsysPlatformTestsCXX.cxx.diff

post-patch {
    # installed cmake will search first in the main macports prefix for frameworks
    reinplace "s|__ORIG_PREFIX__|${orig_prefix}|g" ${worksrcpath}/Modules/CMakeFindFrameworks.cmake
}

compiler.blacklist-append *clang* gcc-4.0
compiler.whitelist macports-gcc-7
configure.cxx_stdlib

platform darwin {
    configure.env-append   CMAKE_OSX_DEPLOYMENT_TARGET=${macosx_deployment_target}

	if {${configure.sdkroot} eq ""} {
		configure.env-append SDKROOT=/
	}

	if {${os.arch} eq "i386" && ${os.major} <= 10} {
		# The old system headers do some bit shifting on Intel about which newer compilers throw errors:
		# SecKeychain.h:102:46: error: shift expression '(1853123693 << 8)' overflows [-fpermissive]
		configure.cflags-append -fpermissive
		configure.cxxflags-append -fpermissive
	}
}

# Clear CPATH and LIBRARY_PATH as we want to be completely independent of other ports
compiler.cpath
compiler.library_path

configure.args-append --docdir=share/doc/cmake \
                      --parallel=${build.jobs} \
                      --no-system-libs \
                      --no-server

configure.universal_args
configure.post_args

# CMake's configure script doesn't recognize `--host`.
array set merger_host {ppc {} ppc64 {}}

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

build.post_args VERBOSE=ON

notes "
To use this bootstrap version of cmake instead of the usual cmake port, add the\
following lines to the Portfile:

depends_build-replace  path:bin/cmake:cmake port:cmake-bootstrap
configure.cmd          \$\{prefix\}/libexec/cmake-bootstrap/bin/cmake
"

livecheck.type  none
