[112836] trunk/dports/_resources/port1.0/group/cmake-1.0.tcl

jeremyhu at macports.org jeremyhu at macports.org
Sat Nov 2 10:13:52 PDT 2013


Revision: 112836
          https://trac.macports.org/changeset/112836
Author:   jeremyhu at macports.org
Date:     2013-11-02 10:13:52 -0700 (Sat, 02 Nov 2013)
Log 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.

Modified Paths:
--------------
    trunk/dports/_resources/port1.0/group/cmake-1.0.tcl

Modified: trunk/dports/_resources/port1.0/group/cmake-1.0.tcl
===================================================================
--- trunk/dports/_resources/port1.0/group/cmake-1.0.tcl	2013-11-02 16:44:49 UTC (rev 112835)
+++ trunk/dports/_resources/port1.0/group/cmake-1.0.tcl	2013-11-02 17:13:52 UTC (rev 112836)
@@ -56,6 +56,58 @@
                     -DCMAKE_FIND_FRAMEWORK=LAST \
                     -Wno-dev
 
+# Handle configure.cppflags, configure.optflags, configure.cflags,
+# configure.cxxflags, configure.ldflags by setting the equivalent CMAKE_*_FLAGS.
+#
+# 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 you want to be sure that no compiler flags are passed via
+# configure.args, you have to set manually configure.optflags to "", as it is by
+# default "-O2" and added to all language-specific flags. If you want to turn off
+# optimization, explicitly set configue.optflags to "-O0".
+if (${configure.cppflags} != "") {
+    # Add the preprocessor flags to the C/C++ compiler flags as CMake does not
+    # honor separately CPPFLAGS (it uses usually add_definitions() for that).
+    # We use the compiler flags for all build types, 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>.
+    configure.args-append -DCMAKE_C_FLAGS="${configure.cppflags}"
+    configure.args-append -DCMAKE_CXX_FLAGS="${configure.cppflags}"
+}
+if {${configure.cflags} != ""} {
+    # The configure.cflags contain configure.optflags by default. Therefore, we
+    # set the Release flags, 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!
+    configure.args-append -DCMAKE_C_FLAGS_RELEASE="${configure.cflags}"
+}
+if {${configure.cxxflags} != ""} {
+    # The configure.cxxflags contain configure.optflags by default. Therefore,
+    # we set the Release flags, 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!
+    configure.args-append -DCMAKE_CXX_FLAGS_RELEASE="${configure.cxxflags}"
+}
+if {${configure.ldflags} != ""} {
+    # CMake supports individual linker flags for executables, modules, and dlls.
+    # By default, they are empty.
+    configure.args-append -DCMAKE_EXE_LINKER_FLAGS="${configure.ldflags}"
+    configure.args-append -DCMAKE_SHARED_LINKER_FLAGS="${configure.ldflags}"
+    configure.args-append -DCMAKE_MODULE_LINKER_FLAGS="${configure.ldflags}"
+}
+
+# TODO: Handle configure.objcflags (cf. to CMake upstream ticket #4756
+#       "CMake needs an Objective-C equivalent of CMAKE_CXX_FLAGS"
+#       <http://public.kitware.com/Bug/view.php?id=4756>)
+
+# TODO: Handle the Fortran-specific configure.* variables:
+#       configure.fflags, configure.fcflags, configure.f90flags
+
+# TODO: Handle the Java-specific configure.classpath variable.
+
 platform darwin {
     pre-configure {
         if {[variant_exists universal] && [variant_isset universal]} {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20131102/71952378/attachment.html>


More information about the macports-changes mailing list