Ignore:
Timestamp:
Nov 2, 2013, 5:13:52 PM (6 years ago)
Author:
jeremyhu@…
Message:

Improve the CMake PortGroup so that it handles the configure.*flags. (#40648)

The configure.cppflags, configure.optflags, configure.cflags, configure.cxxflags, configure.ldflags
are handled by setting the equivalent CMAKE_*_FLAGS.

The configure.cppflags are added to the C/C++ compiler flags as CMake does not honor separately
CPPFLAGS (it uses usually add_definitions() for that). The compiler flags for all build types
(CMAKE_C_FLAGS, CMAKE_CXX_FLAGS) are used, as they are usually empty. Cf. also to CMake upstream
ticket #12928 "CMake silently ignores CPPFLAGS" <​http://www.cmake.org/Bug/view.php?id=12928>.

The configure.cflags contain configure.optflags by default. Therefore, they are set via the Release
flags CMAKE_C_FLAGS_RELEASE, which would otherwise overrule the optimization flags, as they are set
by default to "-O3 -NDEBUG". Therefore, be sure to add "-NDEBUG" to the configure.cflags if you
want to turn off assertions in release builds!

The configure.cxxflags contain configure.optflags by default. Therefore, they are set via the
Release flags CMAKE_CXX_FLAGS_RELEASE, which would otherwise overrule the optimization flags, as
they are set by default to "-O3 -NDEBUG". Therefore, be sure to add "-NDEBUG" to the
configure.cflags if you want to turn off assertions in release builds!

A port author has to be aware that a CMake script can always override these flags when it runs, as
they are frequently set internally in function of other CMake build variables!

Attention: If the port author wants to be sure that no compiler flags are passed via configure.args
to CMake, he has to set manually configure.optflags to "", as it is by default "-O2" and added to
all language-specific flags. If he wants to prevent optimization, he should set configure.optflags
to "-O0".

TODO: Handle the compiler flags specific to Objective-C, Fortran, and Java in the CMake PortGroup.

File:
1 edited

Legend:

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

    r104472 r112836  
    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!
     64#
     65# 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".
     69if (${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}
     78if {${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}
     86if {${configure.cxxflags} != ""} {
     87    # The configure.cxxflags contain configure.optflags by default. Therefore,
     88    # we set the Release flags, which would otherwise overrule the optimization
     89    # flags, as they are set by default to "-O3 -NDEBUG". Therefore, be sure
     90    # to add "-NDEBUG" to the configure.cflags if you want to turn off
     91    # assertions in release builds!
     92    configure.args-append -DCMAKE_CXX_FLAGS_RELEASE="${configure.cxxflags}"
     93}
     94if {${configure.ldflags} != ""} {
     95    # CMake supports individual linker flags for executables, modules, and dlls.
     96    # By default, they are empty.
     97    configure.args-append -DCMAKE_EXE_LINKER_FLAGS="${configure.ldflags}"
     98    configure.args-append -DCMAKE_SHARED_LINKER_FLAGS="${configure.ldflags}"
     99    configure.args-append -DCMAKE_MODULE_LINKER_FLAGS="${configure.ldflags}"
     100}
     101
     102# TODO: Handle configure.objcflags (cf. to CMake upstream ticket #4756
     103#       "CMake needs an Objective-C equivalent of CMAKE_CXX_FLAGS"
     104#       <http://public.kitware.com/Bug/view.php?id=4756>)
     105
     106# TODO: Handle the Fortran-specific configure.* variables:
     107#       configure.fflags, configure.fcflags, configure.f90flags
     108
     109# TODO: Handle the Java-specific configure.classpath variable.
     110
    59111platform darwin {
    60112    pre-configure {
Note: See TracChangeset for help on using the changeset viewer.