Ticket #52699: cmake-PortGroup.diff

File cmake-PortGroup.diff, 9.6 KB (added by RJVB (René Bertin), 8 years ago)
  • (a) /opt/local/var/macports/sources/svn.macports.org/trunk/dports/_resources/port1.0/group/cmake-1.0.tcl.orig vs. (b) cmake-1.1.tcl

    a b  
    11# -*- 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
    22# $Id: cmake-1.0.tcl 143801 2015-12-22 01:37:59Z ryandesign@macports.org $
     3# $Id: cmake-1.1.tcl 143801 2016-09-11 16:28:00Z gmail.com:rjvbertin $
    34#
    45# Copyright (c) 2009 Orville Bennett <illogical1 at gmail.com>
    56# Copyright (c) 2010-2015 The MacPorts Project
     7# Copyright (c) 2015, 2016 R.J.V. Bertin
    68# All rights reserved.
    79#
    810# Redistribution and use in source and binary forms, with or without
     
    3234#
    3335#
    3436# Usage:
    35 # PortGroup     cmake 1.0
     37# PortGroup     cmake 1.1
    3638
    37 options cmake.out_of_source cmake.build_dir
     39namespace eval cmake {
     40    # our directory:
     41    variable currentportgroupdir [file dirname [dict get [info frame 0] file]]
     42}
     43
     44options cmake.out_of_source cmake.build_dir cmake.set_osx_architectures
     45options cmake.install_rpath
     46
     47# make out-of-source builds the default (finally)
     48default cmake.out_of_source         yes
     49
     50# set CMAKE_OSX_ARCHITECTURES when necessary.
     51# This can be deactivated when (non-Apple) compilers are used
     52# that don't support the corresponding -arch options.
     53default cmake.set_osx_architectures yes
    3854
    39 default cmake.out_of_source no
    40 default cmake.build_dir {${workpath}/build}
     55default cmake.build_dir             {${workpath}/build}
     56
     57# minimal/initial value for the install rpath:
     58default cmake.install_rpath         ${prefix}/lib
    4159
    4260# standard place to install extra CMake modules
    4361set cmake_share_module_dir ${prefix}/share/cmake/Modules
     
    6583
    6684configure.pre_args  -DCMAKE_INSTALL_PREFIX=${prefix}
    6785
    68 configure.args      -DCMAKE_VERBOSE_MAKEFILE=ON \
     86configure.args \
     87                    -DCMAKE_VERBOSE_MAKEFILE=ON \
    6988                    -DCMAKE_COLOR_MAKEFILE=ON \
    70                     -DCMAKE_BUILD_TYPE=Release \
     89                    -DCMAKE_BUILD_TYPE=MacPorts \
    7190                    -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
    72                     -DCMAKE_INSTALL_RPATH=${prefix}/lib \
    7391                    -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
    7492                    -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;/usr" \
    7593                    -DCMAKE_MODULE_PATH=${cmake_share_module_dir} \
    7694                    -DCMAKE_FIND_FRAMEWORK=LAST \
     95                    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    7796                    -Wno-dev
    7897
    7998default configure.post_args {${worksrcpath}}
     
    113132    # from the concerned Release build type so that configure.optflags
    114133    # gets honored (Debug used by the +debug variant does not set
    115134    # optimization flags by default).
    116     if {${configure.optflags} ne ""} {
    117         configure.args-append -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
    118                               -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG"
     135    # NB: more recent CMake versions (>=3?) no longer take the env. variables into
     136    # account, and thus require explicit use of ${configure.c*flags} below:
     137#     if {${configure.optflags} ne ""} {
     138#         configure.args-append   -DCMAKE_C_FLAGS="-DNDEBUG ${configure.cflags}" \
     139#                                 -DCMAKE_CXX_FLAGS="-DNDEBUG ${configure.cxxflags}"
     140#     }
     141    # Using a custom BUILD_TYPE we can simply append to the env. variables,
     142    # but why do we set -DNDEBUG?
     143    configure.cflags-append     -DNDEBUG
     144    configure.cxxflags-append   -DNDEBUG
     145    # force newer CMake versions to take a change in compiler choice into account
     146    # even if it is invoked in a build.dir that was configured before.
     147    if {${configure.cc} ne ""} {
     148        configure.args-append \
     149                    -DCMAKE_C_COMPILER=${configure.cc}
     150    }
     151    if {${configure.cxx} ne ""} {
     152        configure.args-append \
     153                    -DCMAKE_CXX_COMPILER=${configure.cxx}
     154    }
     155
     156
     157    # process ${configure.cppflags} to extract include directives and other options
     158    if {${configure.cppflags} ne ""} {
     159        set cppflags [split ${configure.cppflags}]
     160        # reset configure.cppflags; we don't want options in double in CPPFLAGS and CFLAGS/CXXFLAGS
     161        set configure.cppflags ""
     162        set next_is_path 0
     163        foreach flag ${cppflags} {
     164            if {${next_is_path}} {
     165                # previous option was a lone -I
     166                configure.cppflags-append       -I${flag}
     167                set next_is_path 0
     168            } else {
     169                if {[string match "-I" ${flag}]} {
     170                    # lone -I, store the next argument as a path
     171                    # (or ignore if this is the last argument)
     172                    set next_is_path 1
     173                } elseif {[string match "-I*" ${flag}]} {
     174                    # a -Ipath option
     175                    configure.cppflags-append   ${flag}
     176                } else {
     177                    # everything else must go into CFLAGS and CXXFLAGS
     178                    configure.cflags-append     ${flag}
     179                    configure.cxxflags-append   ${flag}
     180                    # append to the ObjC flags too, even if CMake ignores them:
     181                    configure.objcflags-append  ${flag}
     182                    configure.objcxxflags-append   ${flag}
     183                }
     184            }
     185        }
     186        if {${configure.cppflags} ne ""} {
     187            ui_debug "-DINCLUDE_DIRECTORIES=${configure.cppflags}"
     188            configure.args-append   -DINCLUDE_DIRECTORIES:PATH="${configure.cppflags}"
     189        }
     190        ui_debug "CFLAGS=\"${configure.cflags}\" CXXFLAGS=\"${configure.cxxflags}\""
     191    }
     192
     193    if {${cmake.install_rpath} ne ""} {
     194        ui_debug "Adding -DCMAKE_INSTALL_RPATH=[join ${cmake.install_rpath} \;] to configure.args"
     195        configure.args-append -DCMAKE_INSTALL_RPATH="[join ${cmake.install_rpath} \;]"
    119196    }
    120197}
    121198
    122 platform darwin {
    123     set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags}
     199post-configure {
     200    # either compile_commands.json was created because of -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
     201    # in which case touch'ing it won't change anything. Or else it wasn't created, in which case
     202    # we'll create a file that corresponds, i.e. containing an empty json array.
     203    if {![file exists ${build.dir}/compile_commands.json]} {
     204        if {![catch {set fd [open "${build.dir}/compile_commands.json" "w"]} err]} {
     205            puts ${fd} "\[\n\]"
     206            close ${fd}
     207        }
     208    }
     209    if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} {
     210        foreach var [array names ::env] {
     211            puts ${fd} "${var}=$::env(${var})"
     212        }
     213        puts ${fd} "[join [lrange [split ${configure.env} " "] 0 end] "\n"]"
     214        # the following variables are no longer set in the environment at this point:
     215        puts ${fd} "CPP=\"${configure.cpp}\""
     216        puts ${fd} "CC=\"${configure.cc}\""
     217        puts ${fd} "CXX=\"${configure.cxx}\""
     218        if {${configure.objcxx} ne ${configure.cxx}} {
     219            puts ${fd} "OBJCXX=\"${configure.objcxx}\""
     220        }
     221        puts ${fd} "CFLAGS=\"${configure.cflags}\""
     222        puts ${fd} "CXXFLAGS=\"${configure.cxxflags}\""
     223        if {${configure.objcflags} ne ${configure.cflags}} {
     224            puts ${fd} "OBJCFLAGS=\"${configure.objcflags}\""
     225        }
     226        if {${configure.objcxxflags} ne ${configure.cxxflags}} {
     227            puts ${fd} "OBJCXXFLAGS=\"${configure.objcxxflags}\""
     228        }
     229        puts ${fd} "LDFLAGS=\"${configure.ldflags}\""
     230        if {${configure.optflags} ne ""} {
     231            puts ${fd} "configure.optflags=\"${configure.optflags}\""
     232        }
     233        puts ${fd} "\ncd ${worksrcpath}"
     234        puts ${fd} "${configure.cmd} ${configure.pre_args} ${configure.args} ${configure.post_args}"
     235        close ${fd}
     236        unset fd
     237    }
     238}
    124239
     240platform darwin {
     241    set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags \
     242        universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags}
    125243    pre-configure {
    126244        # cmake will add the correct -arch flag(s) based on the value of CMAKE_OSX_ARCHITECTURES.
    127245        if {[variant_exists universal] && [variant_isset universal]} {
    128246            if {[info exists universal_archs_supported]} {
    129247                merger_arch_compiler no
    130248                merger_arch_flag no
    131                 global merger_configure_args
    132                 foreach arch ${universal_archs_to_use} {
    133                     lappend merger_configure_args(${arch}) -DCMAKE_OSX_ARCHITECTURES=${arch}
     249                if {${cmake.set_osx_architectures}} {
     250                    global merger_configure_args
     251                    foreach arch ${universal_archs_to_use} {
     252                        lappend merger_configure_args(${arch}) -DCMAKE_OSX_ARCHITECTURES=${arch}
     253                    }
    134254                }
    135             } else {
     255            } elseif {${cmake.set_osx_architectures}} {
    136256                configure.universal_args-append \
    137257                    -DCMAKE_OSX_ARCHITECTURES="[join ${configure.universal_archs} \;]"
    138258            }
    139         } else {
     259        } elseif {${cmake.set_osx_architectures}} {
    140260            configure.args-append \
    141261                -DCMAKE_OSX_ARCHITECTURES="${configure.build_arch}"
    142262        }
     
    162282            configure.args-append -DCMAKE_OSX_SYSROOT="/"
    163283        }
    164284    }
    165 
    166285    post-configure {
    167286        # Although cmake wants us not to set -arch flags ourselves when we run cmake,
    168287        # ports might have need to access these variables at other times.