Ticket #52699: cmake-Portgroup.diff

File cmake-Portgroup.diff, 8.4 KB (added by mkae (Marko Käning), 7 years ago)
  • .tcl

    old new  
    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
     38
     39namespace eval cmake {
     40    # our directory:
     41    variable currentportgroupdir [file dirname [dict get [info frame 0] file]]
     42}
    3643
    3744options cmake.out_of_source cmake.build_dir
    3845
     
    6572
    6673configure.pre_args  -DCMAKE_INSTALL_PREFIX=${prefix}
    6774
     75set cmake_install_rpath ${prefix}/lib
     76
    6877configure.args      -DCMAKE_VERBOSE_MAKEFILE=ON \
    6978                    -DCMAKE_COLOR_MAKEFILE=ON \
    70                     -DCMAKE_BUILD_TYPE=Release \
     79                    -DCMAKE_BUILD_TYPE=MacPorts \
    7180                    -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
    72                     -DCMAKE_INSTALL_RPATH=${prefix}/lib \
     81                    -DCMAKE_INSTALL_RPATH="${cmake_install_rpath}" \
    7382                    -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
    7483                    -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;/usr" \
    7584                    -DCMAKE_MODULE_PATH=${cmake_share_module_dir} \
    7685                    -DCMAKE_FIND_FRAMEWORK=LAST \
     86                    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    7787                    -Wno-dev
    7888
     89proc cmake.install_rpath {mode path} {
     90    upvar #0 cmake_install_rpath rpath
     91    if {${path} ne ""} {
     92        switch -nocase ${mode} {
     93            append  {set newpath "${rpath}\;${path}"}
     94            prepend {set newpath "${path}\;${rpath}"}
     95            reset   {set newpath "${path}"}
     96            default {
     97                ui_error "Usage: cmake.install_rpath <append|prepend|reset> <path>"
     98                return -code error "Invalid invocation of cmake.install_rpath"
     99            }
     100        }
     101        configure.args-replace \
     102                    -DCMAKE_INSTALL_RPATH="${rpath}" \
     103                    -DCMAKE_INSTALL_RPATH="${newpath}"
     104        set rpath ${newpath}
     105    }
     106}
     107
    79108default configure.post_args {${worksrcpath}}
    80109
    81110# CMake honors set environment variables CFLAGS, CXXFLAGS, and LDFLAGS when it
     
    113142    # from the concerned Release build type so that configure.optflags
    114143    # gets honored (Debug used by the +debug variant does not set
    115144    # optimization flags by default).
    116     if {${configure.optflags} ne ""} {
    117         configure.args-append -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
    118                               -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG"
     145    # NB: more recent CMake versions (>=3?) no longer take the env. variables into
     146    # account, and thus require explicit use of ${configure.c*flags} below:
     147#     if {${configure.optflags} ne ""} {
     148#         configure.args-append   -DCMAKE_C_FLAGS="-DNDEBUG ${configure.cflags}" \
     149#                                 -DCMAKE_CXX_FLAGS="-DNDEBUG ${configure.cxxflags}"
     150#     }
     151    # Using a custom BUILD_TYPE we can simply append to the env. variables,
     152    # but why do we set -DNDEBUG?
     153    configure.cflags-append     -DNDEBUG
     154    configure.cxxflags-append   -DNDEBUG
     155    # force newer CMake versions to take a change in compiler choice into account
     156    # even if it is invoked in a build.dir that was configured before.
     157    if {${configure.cc} ne ""} {
     158        configure.args-append \
     159                    -DCMAKE_C_COMPILER=${configure.cc}
     160    }
     161    if {${configure.cxx} ne ""} {
     162        configure.args-append \
     163                    -DCMAKE_CXX_COMPILER=${configure.cxx}
     164    }
     165
     166
     167    # process ${configure.cppflags} to extract include directives and other options
     168    if {${configure.cppflags} ne ""} {
     169        set cppflags [split ${configure.cppflags}]
     170        # reset configure.cppflags; we don't want options in double in CPPFLAGS and CFLAGS/CXXFLAGS
     171        set configure.cppflags ""
     172        set next_is_path 0
     173        foreach flag ${cppflags} {
     174            if {${next_is_path}} {
     175                # previous option was a lone -I
     176                configure.cppflags-append       -I${flag}
     177                set next_is_path 0
     178            } else {
     179                if {[string match "-I" ${flag}]} {
     180                    # lone -I, store the next argument as a path
     181                    # (or ignore if this is the last argument)
     182                    set next_is_path 1
     183                } elseif {[string match "-I*" ${flag}]} {
     184                    # a -Ipath option
     185                    configure.cppflags-append   ${flag}
     186                } else {
     187                    # everything else must go into CFLAGS and CXXFLAGS
     188                    configure.cflags-append     ${flag}
     189                    configure.cxxflags-append   ${flag}
     190                    # append to the ObjC flags too, even if CMake ignores them:
     191                    configure.objcflags-append  ${flag}
     192                    configure.objcxxflags-append   ${flag}
     193                }
     194            }
     195        }
     196        if {${configure.cppflags} ne ""} {
     197            ui_debug "-DINCLUDE_DIRECTORIES=${configure.cppflags}"
     198            configure.args-append   -DINCLUDE_DIRECTORIES:PATH="${configure.cppflags}"
     199        }
     200        ui_debug "CFLAGS=\"${configure.cflags}\" CXXFLAGS=\"${configure.cxxflags}\""
    119201    }
    120202}
    121203
    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}
     204post-configure {
     205    # either compile_commands.json was created because of -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
     206    # in which case touch'ing it won't change anything. Or else it wasn't created, in which case
     207    # we'll create a file that corresponds, i.e. containing an empty json array.
     208    if {![file exists ${build.dir}/compile_commands.json]} {
     209        if {![catch {set fd [open "${build.dir}/compile_commands.json" "w"]} err]} {
     210            puts ${fd} "\[\n\]"
     211            close ${fd}
     212        }
     213    }
     214    if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} {
     215        foreach var [array names ::env] {
     216            puts ${fd} "${var}=$::env(${var})"
     217        }
     218        puts ${fd} "[join [lrange [split ${configure.env} " "] 0 end] "\n"]"
     219        # the following variables are no longer set in the environment at this point:
     220        puts ${fd} "CPP=\"${configure.cpp}\""
     221        puts ${fd} "CC=\"${configure.cc}\""
     222        puts ${fd} "CXX=\"${configure.cxx}\""
     223        if {${configure.objcxx} ne ${configure.cxx}} {
     224            puts ${fd} "OBJCXX=\"${configure.objcxx}\""
     225        }
     226        puts ${fd} "CFLAGS=\"${configure.cflags}\""
     227        puts ${fd} "CXXFLAGS=\"${configure.cxxflags}\""
     228        if {${configure.objcflags} ne ${configure.cflags}} {
     229            puts ${fd} "OBJCFLAGS=\"${configure.objcflags}\""
     230        }
     231        if {${configure.objcxxflags} ne ${configure.cxxflags}} {
     232            puts ${fd} "OBJCXXFLAGS=\"${configure.objcxxflags}\""
     233        }
     234        puts ${fd} "LDFLAGS=\"${configure.ldflags}\""
     235        if {${configure.optflags} ne ""} {
     236            puts ${fd} "configure.optflags=\"${configure.optflags}\""
     237        }
     238        puts ${fd} "\ncd ${worksrcpath}"
     239        puts ${fd} "${configure.cmd} ${configure.pre_args} ${configure.args} ${configure.post_args}"
     240        close ${fd}
     241        unset fd
     242    }
     243}
    124244
     245platform darwin {
     246    set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags \
     247        universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags}
    125248    pre-configure {
    126249        # cmake will add the correct -arch flag(s) based on the value of CMAKE_OSX_ARCHITECTURES.
    127250        if {[variant_exists universal] && [variant_isset universal]} {
     
    162285            configure.args-append -DCMAKE_OSX_SYSROOT="/"
    163286        }
    164287    }
    165 
    166288    post-configure {
    167289        # Although cmake wants us not to set -arch flags ourselves when we run cmake,
    168290        # ports might have need to access these variables at other times.