Ticket #52205: cmake-1.0.diff

File cmake-1.0.diff, 7.7 KB (added by RJVB (René Bertin), 8 years ago)
  • /opt/local/

    old new  
    6565
    6666configure.pre_args  -DCMAKE_INSTALL_PREFIX=${prefix}
    6767
     68set cmake_install_rpath ${prefix}/lib
     69
    6870configure.args      -DCMAKE_VERBOSE_MAKEFILE=ON \
    6971                    -DCMAKE_COLOR_MAKEFILE=ON \
    70                     -DCMAKE_BUILD_TYPE=Release \
     72                    -DCMAKE_BUILD_TYPE=MacPorts \
    7173                    -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
    72                     -DCMAKE_INSTALL_RPATH=${prefix}/lib \
     74                    -DCMAKE_INSTALL_RPATH="${cmake_install_rpath}" \
    7375                    -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
    7476                    -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;/usr" \
    7577                    -DCMAKE_MODULE_PATH=${cmake_share_module_dir} \
    7678                    -DCMAKE_FIND_FRAMEWORK=LAST \
     79                    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    7780                    -Wno-dev
    7881
     82proc cmake.install_rpath {mode path} {
     83    upvar #0 cmake_install_rpath rpath
     84    if {${path} ne ""} {
     85        switch -nocase ${mode} {
     86            append  {set newpath "${rpath}\;${path}"}
     87            prepend {set newpath "${path}\;${rpath}"}
     88            reset   {set newpath "${path}"}
     89            default {
     90                ui_error "Usage: cmake.install_rpath <append|prepend|reset> <path>"
     91                return -code error "Invalid invocation of cmake.install_rpath"
     92            }
     93        }
     94        configure.args-replace \
     95                    -DCMAKE_INSTALL_RPATH="${rpath}" \
     96                    -DCMAKE_INSTALL_RPATH="${newpath}"
     97        set rpath ${newpath}
     98    }
     99}
     100
    79101default configure.post_args {${worksrcpath}}
    80102
    81103# CMake honors set environment variables CFLAGS, CXXFLAGS, and LDFLAGS when it
     
    113135    # from the concerned Release build type so that configure.optflags
    114136    # gets honored (Debug used by the +debug variant does not set
    115137    # optimization flags by default).
    116     if {${configure.optflags} ne ""} {
    117         configure.args-append -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
    118                               -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG"
     138    # NB: more recent CMake versions (>=3?) no longer take the env. variables into
     139    # account, and thus require explicit use of ${configure.c*flags} below:
     140#     if {${configure.optflags} ne ""} {
     141#         configure.args-append   -DCMAKE_C_FLAGS="-DNDEBUG ${configure.cflags}" \
     142#                                 -DCMAKE_CXX_FLAGS="-DNDEBUG ${configure.cxxflags}"
     143#     }
     144    # Using a custom BUILD_TYPE we can simply append to the env. variables,
     145    # but why do we set -DNDEBUG?
     146    configure.cflags-append     -DNDEBUG
     147    configure.cxxflags-append   -DNDEBUG
     148    # force newer CMake versions to take a change in compiler choice into account
     149    # even if it is invoked in a build.dir that was configured before.
     150    if {${configure.cc} ne ""} {
     151        configure.args-append \
     152                    -DCMAKE_C_COMPILER=${configure.cc}
     153    }
     154    if {${configure.cxx} ne ""} {
     155        configure.args-append \
     156                    -DCMAKE_CXX_COMPILER=${configure.cxx}
     157    }
     158
     159
     160    # process ${configure.cppflags} to extract include directives and other options
     161    if {${configure.cppflags} ne ""} {
     162        set cppflags [split ${configure.cppflags}]
     163        # reset configure.cppflags; we don't want options in double in CPPFLAGS and CFLAGS/CXXFLAGS
     164        set configure.cppflags ""
     165        set next_is_path 0
     166        foreach flag ${cppflags} {
     167            if {${next_is_path}} {
     168                # previous option was a lone -I
     169                configure.cppflags-append       -I${flag}
     170                set next_is_path 0
     171            } else {
     172                if {[string match "-I" ${flag}]} {
     173                    # lone -I, store the next argument as a path
     174                    # (or ignore if this is the last argument)
     175                    set next_is_path 1
     176                } elseif {[string match "-I*" ${flag}]} {
     177                    # a -Ipath option
     178                    configure.cppflags-append   ${flag}
     179                } else {
     180                    # everything else must go into CFLAGS and CXXFLAGS
     181                    configure.cflags-append     ${flag}
     182                    configure.cxxflags-append   ${flag}
     183                    # append to the ObjC flags too, even if CMake ignores them:
     184                    configure.objcflags-append  ${flag}
     185                    configure.objcxxflags-append   ${flag}
     186                }
     187            }
     188        }
     189        if {${configure.cppflags} ne ""} {
     190            ui_debug "-DINCLUDE_DIRECTORIES=${configure.cppflags}"
     191            configure.args-append   -DINCLUDE_DIRECTORIES:PATH="${configure.cppflags}"
     192        }
     193        ui_debug "CFLAGS=\"${configure.cflags}\" CXXFLAGS=\"${configure.cxxflags}\""
    119194    }
    120195}
    121196
    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}
     197post-configure {
     198    # either compile_commands.json was created because of -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
     199    # in which case touch'ing it won't change anything. Or else it wasn't created, in which case
     200    # we'll create a file that corresponds, i.e. containing an empty json array.
     201    if {![file exists ${build.dir}/compile_commands.json]} {
     202        if {![catch {set fd [open "${build.dir}/compile_commands.json" "w"]} err]} {
     203            puts ${fd} "\[\n\]"
     204            close ${fd}
     205        }
     206    }
     207    if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} {
     208        foreach var [array names ::env] {
     209            puts ${fd} "${var}=$::env(${var})"
     210        }
     211        puts ${fd} "[join [lrange [split ${configure.env} " "] 0 end] "\n"]"
     212        # the following variables are no longer set in the environment at this point:
     213        puts ${fd} "CPP=\"${configure.cpp}\""
     214        puts ${fd} "CC=\"${configure.cc}\""
     215        puts ${fd} "CXX=\"${configure.cxx}\""
     216        if {${configure.objcxx} ne ${configure.cxx}} {
     217            puts ${fd} "OBJCXX=\"${configure.objcxx}\""
     218        }
     219        puts ${fd} "CFLAGS=\"${configure.cflags}\""
     220        puts ${fd} "CXXFLAGS=\"${configure.cxxflags}\""
     221        if {${configure.objcflags} ne ${configure.cflags}} {
     222            puts ${fd} "OBJCFLAGS=\"${configure.objcflags}\""
     223        }
     224        if {${configure.objcxxflags} ne ${configure.cxxflags}} {
     225            puts ${fd} "OBJCXXFLAGS=\"${configure.objcxxflags}\""
     226        }
     227        puts ${fd} "LDFLAGS=\"${configure.ldflags}\""
     228        if {${configure.optflags} ne ""} {
     229            puts ${fd} "configure.optflags=\"${configure.optflags}\""
     230        }
     231        puts ${fd} "\ncd ${worksrcpath}"
     232        puts ${fd} "${configure.cmd} ${configure.pre_args} ${configure.args} ${configure.post_args}"
     233        close ${fd}
     234        unset fd
     235    }
     236}
    124237
     238platform darwin {
     239    set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags \
     240        universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags}
    125241    pre-configure {
    126242        # cmake will add the correct -arch flag(s) based on the value of CMAKE_OSX_ARCHITECTURES.
    127243        if {[variant_exists universal] && [variant_isset universal]} {
     
    162278            configure.args-append -DCMAKE_OSX_SYSROOT="/"
    163279        }
    164280    }
    165 
    166281    post-configure {
    167282        # Although cmake wants us not to set -arch flags ourselves when we run cmake,
    168283        # ports might have need to access these variables at other times.