Ticket #50271: cmake-1.0.diff

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

    old new  
    6767
    6868configure.args      -DCMAKE_VERBOSE_MAKEFILE=ON \
    6969                    -DCMAKE_COLOR_MAKEFILE=ON \
    70                     -DCMAKE_BUILD_TYPE=Release \
     70                    -DCMAKE_BUILD_TYPE=MacPorts \
    7171                    -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
    7272                    -DCMAKE_INSTALL_RPATH=${prefix}/lib \
    7373                    -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
    7474                    -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;/usr" \
    7575                    -DCMAKE_MODULE_PATH=${cmake_share_module_dir} \
    7676                    -DCMAKE_FIND_FRAMEWORK=LAST \
     77                    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    7778                    -Wno-dev
    7879
    7980default configure.post_args {${worksrcpath}}
     
    113114    # from the concerned Release build type so that configure.optflags
    114115    # gets honored (Debug used by the +debug variant does not set
    115116    # optimization flags by default).
    116     if {${configure.optflags} ne ""} {
    117         configure.args-append -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
    118                               -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG"
     117    # NB: more recent CMake versions (>=3?) no longer take the env. variables into
     118    # account, and thus require explicit use of ${configure.c*flags} below:
     119#     if {${configure.optflags} ne ""} {
     120#         configure.args-append   -DCMAKE_C_FLAGS="-DNDEBUG ${configure.cflags}" \
     121#                                 -DCMAKE_CXX_FLAGS="-DNDEBUG ${configure.cxxflags}"
     122#     }
     123    # Using a custom BUILD_TYPE we can simply append to the env. variables,
     124    # but why do we set -DNDEBUG?
     125    configure.cflags-append     -DNDEBUG
     126    configure.cxxflags-append   -DNDEBUG
     127
     128    # process ${configure.cppflags} to extract include directives and other options
     129    if {${configure.cppflags} ne ""} {
     130        set cppflags [split ${configure.cppflags}]
     131        # reset configure.cppflags; we don't want options in double in CPPFLAGS and CFLAGS/CXXFLAGS
     132        configure.cppflags-delete   ${configure.cppflags}
     133        set next_is_path 0
     134        foreach flag ${cppflags} {
     135            if {${next_is_path}} {
     136                # previous option was a lone -I
     137                configure.cppflags-append       -I${flag}
     138                set next_is_path 0
     139            } else {
     140                if {[string match "-I" ${flag}]} {
     141                    # lone -I, store the next argument as a path
     142                    # (or ignore if this is the last argument)
     143                    set next_is_path 1
     144                } elseif {[string match "-I*" ${flag}]} {
     145                    # a -Ipath option
     146                    configure.cppflags-append   ${flag}
     147                } else {
     148                    # everything else must go into CFLAGS and CXXFLAGS
     149                    configure.cflags-append     ${flag}
     150                    configure.cxxflags-append   ${flag}
     151                    # append to the ObjC flags too, even if CMake ignores them:
     152                    configure.objcflags-append  ${flag}
     153                    configure.objcxxflags-append   ${flag}
     154                }
     155            }
     156        }
     157        ui_debug "-DINCLUDE_DIRECTORIES=${configure.cppflags}"
     158        ui_debug "CFLAGS=\"${configure.cflags}\" CXXFLAGS=\"${configure.cxxflags}\""
     159        configure.args-append   -DINCLUDE_DIRECTORIES:PATH="${configure.cppflags}"
    119160    }
    120161}
    121162
    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}
     163post-configure {
     164    # either compile_commands.json was created because of -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
     165    # in which case touch'ing it won't change anything. Or else it wasn't created, in which case
     166    # we'll create a file that corresponds, i.e. containing an empty json array.
     167    if {![file exists ${build.dir}/compile_commands.json]} {
     168            if {![catch {set fd [open "${build.dir}/compile_commands.json" "w"]} err]} {
     169                    puts ${fd} "\[\n\]"
     170                    close ${fd}
     171            }
     172    }
     173    if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} {
     174        foreach var [array names ::env] {
     175            puts ${fd} "${var}=$::env(${var})"
     176        }
     177        puts ${fd} "[join [lrange [split ${configure.env} " "] 0 end] "\n"]\n"
     178        puts ${fd} "cd ${worksrcpath}"
     179        puts ${fd} "${configure.cmd} ${configure.pre_args} ${configure.args} ${configure.post_args}"
     180        close ${fd}
     181        unset fd
     182    }
     183}
    124184
     185platform darwin {
     186    set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags \
     187        universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags}
    125188    pre-configure {
    126189        # cmake will add the correct -arch flag(s) based on the value of CMAKE_OSX_ARCHITECTURES.
    127190        if {[variant_exists universal] && [variant_isset universal]} {
     
    162225            configure.args-append -DCMAKE_OSX_SYSROOT="/"
    163226        }
    164227    }
    165 
    166228    post-configure {
    167229        # Although cmake wants us not to set -arch flags ourselves when we run cmake,
    168230        # ports might have need to access these variables at other times.