--- /opt/local/var/macports/sources/svn.macports.org/trunk/dports/_resources/port1.0/group/cmake-1.0.tcl.orig	2016-09-11 14:44:49.000000000 +0200
+++ cmake-1.1.tcl	2016-10-27 02:13:08.000000000 +0200
@@ -1,8 +1,10 @@
 # -*- coding: utf-8; mode: tcl; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; truncate-lines: t -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
 # $Id: cmake-1.0.tcl 143801 2015-12-22 01:37:59Z ryandesign@macports.org $
+# $Id: cmake-1.1.tcl 143801 2016-09-11 16:28:00Z gmail.com:rjvbertin $
 #
 # Copyright (c) 2009 Orville Bennett <illogical1 at gmail.com>
 # Copyright (c) 2010-2015 The MacPorts Project
+# Copyright (c) 2015, 2016 R.J.V. Bertin
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -32,12 +34,28 @@
 #
 #
 # Usage:
-# PortGroup     cmake 1.0
+# PortGroup     cmake 1.1
 
-options cmake.out_of_source cmake.build_dir
+namespace eval cmake {
+    # our directory:
+    variable currentportgroupdir [file dirname [dict get [info frame 0] file]]
+}
+
+options cmake.out_of_source cmake.build_dir cmake.set_osx_architectures
+options cmake.install_rpath
+
+# make out-of-source builds the default (finally)
+default cmake.out_of_source         yes
+
+# set CMAKE_OSX_ARCHITECTURES when necessary.
+# This can be deactivated when (non-Apple) compilers are used
+# that don't support the corresponding -arch options.
+default cmake.set_osx_architectures yes
 
-default cmake.out_of_source no
-default cmake.build_dir {${workpath}/build}
+default cmake.build_dir             {${workpath}/build}
+
+# minimal/initial value for the install rpath:
+default cmake.install_rpath         ${prefix}/lib
 
 # standard place to install extra CMake modules
 set cmake_share_module_dir ${prefix}/share/cmake/Modules
@@ -65,15 +83,16 @@
 
 configure.pre_args  -DCMAKE_INSTALL_PREFIX=${prefix}
 
-configure.args      -DCMAKE_VERBOSE_MAKEFILE=ON \
+configure.args \
+                    -DCMAKE_VERBOSE_MAKEFILE=ON \
                     -DCMAKE_COLOR_MAKEFILE=ON \
-                    -DCMAKE_BUILD_TYPE=Release \
+                    -DCMAKE_BUILD_TYPE=MacPorts \
                     -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-                    -DCMAKE_INSTALL_RPATH=${prefix}/lib \
                     -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
                     -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;/usr" \
                     -DCMAKE_MODULE_PATH=${cmake_share_module_dir} \
                     -DCMAKE_FIND_FRAMEWORK=LAST \
+                    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
                     -Wno-dev
 
 default configure.post_args {${worksrcpath}}
@@ -113,30 +132,131 @@
     # from the concerned Release build type so that configure.optflags
     # gets honored (Debug used by the +debug variant does not set
     # optimization flags by default).
-    if {${configure.optflags} ne ""} {
-        configure.args-append -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
-                              -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG"
+    # NB: more recent CMake versions (>=3?) no longer take the env. variables into
+    # account, and thus require explicit use of ${configure.c*flags} below:
+#     if {${configure.optflags} ne ""} {
+#         configure.args-append   -DCMAKE_C_FLAGS="-DNDEBUG ${configure.cflags}" \
+#                                 -DCMAKE_CXX_FLAGS="-DNDEBUG ${configure.cxxflags}"
+#     }
+    # Using a custom BUILD_TYPE we can simply append to the env. variables,
+    # but why do we set -DNDEBUG?
+    configure.cflags-append     -DNDEBUG
+    configure.cxxflags-append   -DNDEBUG
+    # force newer CMake versions to take a change in compiler choice into account
+    # even if it is invoked in a build.dir that was configured before.
+    if {${configure.cc} ne ""} {
+        configure.args-append \
+                    -DCMAKE_C_COMPILER=${configure.cc}
+    }
+    if {${configure.cxx} ne ""} {
+        configure.args-append \
+                    -DCMAKE_CXX_COMPILER=${configure.cxx}
+    }
+
+
+    # process ${configure.cppflags} to extract include directives and other options
+    if {${configure.cppflags} ne ""} {
+        set cppflags [split ${configure.cppflags}]
+        # reset configure.cppflags; we don't want options in double in CPPFLAGS and CFLAGS/CXXFLAGS
+        set configure.cppflags ""
+        set next_is_path 0
+        foreach flag ${cppflags} {
+            if {${next_is_path}} {
+                # previous option was a lone -I
+                configure.cppflags-append       -I${flag}
+                set next_is_path 0
+            } else {
+                if {[string match "-I" ${flag}]} {
+                    # lone -I, store the next argument as a path
+                    # (or ignore if this is the last argument)
+                    set next_is_path 1
+                } elseif {[string match "-I*" ${flag}]} {
+                    # a -Ipath option
+                    configure.cppflags-append   ${flag}
+                } else {
+                    # everything else must go into CFLAGS and CXXFLAGS
+                    configure.cflags-append     ${flag}
+                    configure.cxxflags-append   ${flag}
+                    # append to the ObjC flags too, even if CMake ignores them:
+                    configure.objcflags-append  ${flag}
+                    configure.objcxxflags-append   ${flag}
+                }
+            }
+        }
+        if {${configure.cppflags} ne ""} {
+            ui_debug "-DINCLUDE_DIRECTORIES=${configure.cppflags}"
+            configure.args-append   -DINCLUDE_DIRECTORIES:PATH="${configure.cppflags}"
+        }
+        ui_debug "CFLAGS=\"${configure.cflags}\" CXXFLAGS=\"${configure.cxxflags}\""
+    }
+
+    if {${cmake.install_rpath} ne ""} {
+        ui_debug "Adding -DCMAKE_INSTALL_RPATH=[join ${cmake.install_rpath} \;] to configure.args"
+        configure.args-append -DCMAKE_INSTALL_RPATH="[join ${cmake.install_rpath} \;]"
     }
 }
 
-platform darwin {
-    set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags}
+post-configure {
+    # either compile_commands.json was created because of -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
+    # in which case touch'ing it won't change anything. Or else it wasn't created, in which case
+    # we'll create a file that corresponds, i.e. containing an empty json array.
+    if {![file exists ${build.dir}/compile_commands.json]} {
+        if {![catch {set fd [open "${build.dir}/compile_commands.json" "w"]} err]} {
+            puts ${fd} "\[\n\]"
+            close ${fd}
+        }
+    }
+    if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} {
+        foreach var [array names ::env] {
+            puts ${fd} "${var}=$::env(${var})"
+        }
+        puts ${fd} "[join [lrange [split ${configure.env} " "] 0 end] "\n"]"
+        # the following variables are no longer set in the environment at this point:
+        puts ${fd} "CPP=\"${configure.cpp}\""
+        puts ${fd} "CC=\"${configure.cc}\""
+        puts ${fd} "CXX=\"${configure.cxx}\""
+        if {${configure.objcxx} ne ${configure.cxx}} {
+            puts ${fd} "OBJCXX=\"${configure.objcxx}\""
+        }
+        puts ${fd} "CFLAGS=\"${configure.cflags}\""
+        puts ${fd} "CXXFLAGS=\"${configure.cxxflags}\""
+        if {${configure.objcflags} ne ${configure.cflags}} {
+            puts ${fd} "OBJCFLAGS=\"${configure.objcflags}\""
+        }
+        if {${configure.objcxxflags} ne ${configure.cxxflags}} {
+            puts ${fd} "OBJCXXFLAGS=\"${configure.objcxxflags}\""
+        }
+        puts ${fd} "LDFLAGS=\"${configure.ldflags}\""
+        if {${configure.optflags} ne ""} {
+            puts ${fd} "configure.optflags=\"${configure.optflags}\""
+        }
+        puts ${fd} "\ncd ${worksrcpath}"
+        puts ${fd} "${configure.cmd} ${configure.pre_args} ${configure.args} ${configure.post_args}"
+        close ${fd}
+        unset fd
+    }
+}
 
+platform darwin {
+    set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags \
+        universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags}
     pre-configure {
         # cmake will add the correct -arch flag(s) based on the value of CMAKE_OSX_ARCHITECTURES.
         if {[variant_exists universal] && [variant_isset universal]} {
             if {[info exists universal_archs_supported]} {
                 merger_arch_compiler no
                 merger_arch_flag no
-                global merger_configure_args
-                foreach arch ${universal_archs_to_use} {
-                    lappend merger_configure_args(${arch}) -DCMAKE_OSX_ARCHITECTURES=${arch}
+                if {${cmake.set_osx_architectures}} {
+                    global merger_configure_args
+                    foreach arch ${universal_archs_to_use} {
+                        lappend merger_configure_args(${arch}) -DCMAKE_OSX_ARCHITECTURES=${arch}
+                    }
                 }
-            } else {
+            } elseif {${cmake.set_osx_architectures}} {
                 configure.universal_args-append \
                     -DCMAKE_OSX_ARCHITECTURES="[join ${configure.universal_archs} \;]"
             }
-        } else {
+        } elseif {${cmake.set_osx_architectures}} {
             configure.args-append \
                 -DCMAKE_OSX_ARCHITECTURES="${configure.build_arch}"
         }
@@ -162,7 +282,6 @@
             configure.args-append -DCMAKE_OSX_SYSROOT="/"
         }
     }
-
     post-configure {
         # Although cmake wants us not to set -arch flags ourselves when we run cmake,
         # ports might have need to access these variables at other times.
