[MacPorts] #40648: cmake @2.8.11.2 does not set optimization flags in release
MacPorts
noreply at macports.org
Sat Nov 2 07:44:12 PDT 2013
#40648: cmake @2.8.11.2 does not set optimization flags in release
-------------------------+----------------------
Reporter: macports@… | Owner: css@…
Type: defect | Status: assigned
Priority: Normal | Milestone:
Component: ports | Version:
Resolution: | Keywords:
Port: cmake |
-------------------------+----------------------
Comment (by Torsten.Maehne@…):
As a regular CMake user, I'm also affected by this annoying issue.
Therefore, I had a look to the CMake port group to fix the issue with the
following uploaded patches:
{{{0001-Fix-the-CMake-port-specific-part-of-ticket-40648.patch}}}
Fix the CMake-port-specific part of this ticket.
This reverts the changes made to the CMake Portfile in r110069 so that
ports, which are configured by CMake, honor the configure.optflags set
in the Portfile. Thus, Release builds are compiled with optimization
by default again.
{{{0002-Improve-CMake-PortGroup-to-handle-the-configure-flags.patch}}}
Improve the CMake PortGroup so that it handles the configure.*flags.
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.
This patch does not fix the issue in the case of selecting the +debug
variant of the CMake PortGroup for which two additional patches are
necessary:
{{{0003-Fix-CMake-PortGroup-debug-variant.patch}}}
Change the CMAKE_BUILD_TYPE to Debug instead of debugFull for the +debug
variant in the CMake PortGroup.
"debugFull" is not a standard build type in CMake so there are no
default compiler flags set for it, which would turn on the inclusion
of debug symbols. Instead, CMake provides the build type "Debug" for
this purpose. Only KDE provides in its CMake build infrastructure
support for a build type called "DebugFull", which turns off
optimization, as KDE leaves it on for the "Debug" build type. Confer
to <http://techbase.kde.org/Development/CMake/Addons_for_KDE> for
further explanations.
{{{0004-Handle-configure.cflags-and-configure.cxxflags-in-debug-variant-
of-CMake-PortGroup.patch}}}
Consider the configure.cflags and configure.cxxflags for +debug variant of
the CMake PortsGroup.
The CMAKE_BUILD_TYPE "Debug" uses CMAKE_C_FLAGS_DEBUG and
CMAKE_CXX_FLAGS_DEBUG to specify the compiler flags. These variables
are set to "-g" plus the respective configure.cflags and
configure.cxxflags. Be aware that configure.cflags and
configure.cxxflags contain configure.optflags by default, which are
not deleted for the Debug build. The port author has to set
configure.optflags to "-O0" to turn off optimization.
Please have a look on it and test it with the ports, which motivated the
change in r110069 in the first place. I don't have commit rights to apply
these changes to the MacPorts SVN.
--
Ticket URL: <https://trac.macports.org/ticket/40648#comment:15>
MacPorts <http://www.macports.org/>
Ports system for OS X
More information about the macports-tickets
mailing list