2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012,2013, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 # Due to a bug, gcc 4.4.x crashes when compiling bondfree.c with -O3 and
36 # -fopenmp, but strangely it does not crash with -O2 + all additional options.
37 # -O3 uses. Therefore, for the affected files, when compiling in release mode,
38 # we override -O3 with -O2 and add the additional option.
41 # Considering compiler version and build configuration, check if the workaround
42 # is needed to avoid gcc crash.
43 macro(gmx_check_gcc44_bug_workaround_needed OUT_VAR)
44 if(CMAKE_COMPILER_IS_GNUCC AND
45 C_COMPILER_VERSION VERSION_GREATER "4.3.999" AND C_COMPILER_VERSION VERSION_LESS "4.4.999")
47 set(_gcc44_workaround FALSE)
49 # only apply the workaround if we are actually using -O3
50 string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
51 if ("${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_build_type}}" MATCHES ".*-O3.*" AND
53 if(GMX_DISABLE_GCC44_BUG_WORKAROUND)
54 set(_msg "gcc ${C_COMPILER_VERSION} detected, using -O3, but workaround for optimization bug is disabled")
56 set(_msg "gcc ${C_COMPILER_VERSION} detected, using -O3, will apply workaround for optimization bug (disable with GMX_DISABLE_GCC44_BUG_WORKAROUND)")
57 set(_gcc44_workaround TRUE)
59 # only issues message if the value has changed
60 if((NOT _gcc44_workaround AND ${OUT_VAR}) OR (_gcc44_workaround AND NOT ${OUT_VAR}))
61 message(STATUS "${_msg}")
65 set(${OUT_VAR} ${_gcc44_workaround} CACHE INTERNAL "Use gcc 4.4.x O3 optimization bug workaround" FORCE)
69 # Apply workaround on the specified source file.
71 # This workaround does not seem to affect the performance in a measurable way.
72 macro(gmx_apply_gcc44_bug_workaround FILE_NAME)
73 set_source_files_properties(
76 COMPILE_FLAGS "-O2 -finline-functions -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -fipa-cp-clone"