Ticket #49108: cmake-1.0.diff

File cmake-1.0.diff, 6.3 KB (added by RJVB (René Bertin), 8 years ago)
  • _resources/port1.0/group/cmake-1.0.tcl

    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
     149    # process ${configure.cppflags} to extract include directives and other options
     150    if {${configure.cppflags} ne ""} {
     151        set cppflags [split ${configure.cppflags}]
     152        # reset configure.cppflags; we don't want options in double in CPPFLAGS and CFLAGS/CXXFLAGS
     153        configure.cppflags-delete   ${configure.cppflags}
     154        set next_is_path 0
     155        foreach flag ${cppflags} {
     156            if {${next_is_path}} {
     157                # previous option was a lone -I
     158                configure.cppflags-append       -I${flag}
     159                set next_is_path 0
     160            } else {
     161                if {[string match "-I" ${flag}]} {
     162                    # lone -I, store the next argument as a path
     163                    # (or ignore if this is the last argument)
     164                    set next_is_path 1
     165                } elseif {[string match "-I*" ${flag}]} {
     166                    # a -Ipath option
     167                    configure.cppflags-append   ${flag}
     168                } else {
     169                    # everything else must go into CFLAGS and CXXFLAGS
     170                    configure.cflags-append     ${flag}
     171                    configure.cxxflags-append   ${flag}
     172                    # append to the ObjC flags too, even if CMake ignores them:
     173                    configure.objcflags-append  ${flag}
     174                    configure.objcxxflags-append   ${flag}
     175                }
     176            }
     177        }
     178        ui_debug "-DINCLUDE_DIRECTORIES=${configure.cppflags}"
     179        ui_debug "CFLAGS=\"${configure.cflags}\" CXXFLAGS=\"${configure.cxxflags}\""
     180        configure.args-append   -DINCLUDE_DIRECTORIES:PATH="${configure.cppflags}"
    119181    }
    120182}
    121183
    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}
     184post-configure {
     185    # either compile_commands.json was created because of -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
     186    # in which case touch'ing it won't change anything. Or else it wasn't created, in which case
     187    # we'll create a file that corresponds, i.e. containing an empty json array.
     188    if {![file exists ${build.dir}/compile_commands.json]} {
     189            if {![catch {set fd [open "${build.dir}/compile_commands.json" "w"]} err]} {
     190                    puts ${fd} "\[\n\]"
     191                    close ${fd}
     192            }
     193    }
     194    if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} {
     195        foreach var [array names ::env] {
     196            puts ${fd} "${var}=$::env(${var})"
     197        }
     198        puts ${fd} "[join [lrange [split ${configure.env} " "] 0 end] "\n"]\n"
     199        puts ${fd} "cd ${worksrcpath}"
     200        puts ${fd} "${configure.cmd} ${configure.pre_args} ${configure.args} ${configure.post_args}"
     201        close ${fd}
     202        unset fd
     203    }
     204}
    124205
     206platform darwin {
     207    set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags \
     208        universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags}
    125209    pre-configure {
    126210        # cmake will add the correct -arch flag(s) based on the value of CMAKE_OSX_ARCHITECTURES.
    127211        if {[variant_exists universal] && [variant_isset universal]} {
     
    162246            configure.args-append -DCMAKE_OSX_SYSROOT="/"
    163247        }
    164248    }
    165 
    166249    post-configure {
    167250        # Although cmake wants us not to set -arch flags ourselves when we run cmake,
    168251        # ports might have need to access these variables at other times.