Ignore:
Timestamp:
Nov 4, 2013, 9:14:20 PM (6 years ago)
Author:
ryandesign@…
Message:

cmake-1.0.tcl: fix build failures with universal variants or ports that modify cflags, cxxflags, cppflags or ldflags (#41142)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dports/_resources/port1.0/group/cmake-1.0.tcl

    r112844 r112944  
    5757                    -Wno-dev
    5858
    59 # Handle configure.cppflags, configure.optflags, configure.cflags,
    60 # configure.cxxflags, configure.ldflags by setting the equivalent CMAKE_*_FLAGS.
    61 #
    62 # Be aware that a CMake script can always override these flags when it runs, as
    63 # they are frequently set internally in function of other CMake build variables!
     59# CMake honors set environment variables CFLAGS, CXXFLAGS, and LDFLAGS when it
     60# is first run in a build directory to initialize CMAKE_C_FLAGS,
     61# CMAKE_CXX_FLAGS, CMAKE_[EXE|SHARED|MODULE]_LINKER_FLAGS. However, be aware
     62# that a CMake script can always override these flags when it runs, as they
     63# are frequently set internally in functions of other CMake build variables!
    6464#
    6565# Attention: If you want to be sure that no compiler flags are passed via
    66 # configure.args, you have to set manually configure.optflags to "", as it is by
    67 # default "-O2" and added to all language-specific flags. If you want to turn off
    68 # optimization, explicitly set configue.optflags to "-O0".
    69 if {${configure.cppflags} != ""} {
    70     # Add the preprocessor flags to the C/C++ compiler flags as CMake does not
    71     # honor separately CPPFLAGS (it uses usually add_definitions() for that).
    72     # We use the compiler flags for all build types, as they are usually empty.
    73     # Cf. also to CMake upstream ticket #12928 "CMake silently ignores CPPFLAGS"
    74     # <http://www.cmake.org/Bug/view.php?id=12928>.
    75     configure.args-append -DCMAKE_C_FLAGS="${configure.cppflags}"
    76     configure.args-append -DCMAKE_CXX_FLAGS="${configure.cppflags}"
    77 }
    78 if {${configure.cflags} != ""} {
    79     # The configure.cflags contain configure.optflags by default. Therefore, we
    80     # set the Release flags, which would otherwise overrule the optimization
    81     # flags, as they are set by default to "-O3 -NDEBUG". Therefore, be sure
    82     # to add "-NDEBUG" to the configure.cflags if you want to turn off
    83     # assertions in release builds!
    84     configure.args-append -DCMAKE_C_FLAGS_RELEASE="${configure.cflags}"
    85 }
    86 set cxx_stdlibflags {}
    87 if {[info exists configure.cxx_stdlib] &&
    88     ${configure.cxx_stdlib} ne {} &&
    89     [string match *clang* ${configure.cxx}]} {
    90     set cxx_stdlibflags -stdlib=${configure.cxx_stdlib}
    91 }
    92 if {${configure.cxxflags} != "" || ${cxx_stdlibflags} != ""} {
    93     # The configure.cxxflags contain configure.optflags by default. Therefore,
    94     # we set the Release flags, which would otherwise overrule the optimization
    95     # flags, as they are set by default to "-O3 -NDEBUG". Therefore, be sure
    96     # to add "-NDEBUG" to the configure.cflags if you want to turn off
    97     # assertions in release builds!
    98     configure.args-append -DCMAKE_CXX_FLAGS_RELEASE="${configure.cxxflags} ${cxx_stdlibflags}"
    99 }
    100 if {${configure.ldflags} != ""} {
    101     # CMake supports individual linker flags for executables, modules, and dlls.
    102     # By default, they are empty.
    103     configure.args-append -DCMAKE_EXE_LINKER_FLAGS="${configure.ldflags}"
    104     configure.args-append -DCMAKE_SHARED_LINKER_FLAGS="${configure.ldflags}"
    105     configure.args-append -DCMAKE_MODULE_LINKER_FLAGS="${configure.ldflags}"
    106 }
     66# configure.args, you have to manually clear configure.optflags, as it is set
     67# to "-Os" by default and added to all language-specific flags. If you want to
     68# turn off optimization, explicitly set configure.optflags to "-O0".
    10769
    10870# TODO: Handle configure.objcflags (cf. to CMake upstream ticket #4756
     
    11577# TODO: Handle the Java-specific configure.classpath variable.
    11678
    117 platform darwin {
    118     pre-configure {
     79pre-configure {
     80    # The environment variable CPPFLAGS is not considered by CMake.
     81    # (CMake upstream ticket #12928 "CMake silently ignores CPPFLAGS"
     82    # <http://www.cmake.org/Bug/view.php?id=12928>).
     83    # Thus, we have to add them manually to the CFLAGS and CXXFLAGS in the
     84    # pre-configure phase.
     85    if {${configure.cppflags} ne ""} {
     86        configure.cflags-append ${configure.cppflags}
     87        configure.cxxflags-append ${configure.cppflags}
     88    }
     89
     90    # In addition, CMake provides build-type-specific flags for
     91    # Release (-O3 -DNDEBUG), Debug (-g), MinSizeRel (-Os -DNDEBUG), and
     92    # RelWithDebInfo (-O2 -g -DNDEBUG). If the configure.optflags have been
     93    # set (-Os by default), we have to remove the optimization flags from the
     94    # from the concerned Release build type so that configure.optflags
     95    # gets honored (Debug used by the +debug variant does not set
     96    # optimization flags by default).
     97    if {${configure.optflags} ne ""} {
     98        configure.args-append -DCMAKE_C_FLAGS_RELEASE="-NDEBUG" \
     99                              -DCMAKE_CXX_FLAGS_RELEASE="-NDEBUG"
     100    }
     101
     102    platform darwin {
    119103        if {[variant_exists universal] && [variant_isset universal]} {
    120104            if {[info exists universal_archs_supported]} {
     
    145129    configure.args-delete   -DCMAKE_BUILD_TYPE=Release
    146130    configure.args-append   -DCMAKE_BUILD_TYPE=Debug
    147     # Consider the configure.cflags and configure.cxxflags for Debug builds.
    148     # Attention, they contain configure.optflags by default!
    149     if {${configure.cflags} != ""} {
    150         configure.args-append -DCMAKE_C_FLAGS_DEBUG="-g ${configure.cflags}"
    151     }
    152     if {${configure.cxxflags} != "" || ${cxx_stdlibflags} != ""} {
    153         configure.args-append -DCMAKE_CXX_FLAGS_DEBUG="-g ${configure.cxxflags} ${cxx_stdlibflags}"
    154     }
    155131}
    156132
Note: See TracChangeset for help on using the changeset viewer.