Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/cmake/CompilerConfigGCC.cmake @ 8364

Last change on this file since 8364 was 8364, checked in by rgrieder, 13 years ago

Never omit frame pointer on GCC too to avoid unreadable stack traces (even in Release mode).

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1 #
2 #             ORXONOX - the hottest 3D action shooter ever to exist
3 #                             > www.orxonox.net <
4 #
5 #        This program is free software; you can redistribute it and/or
6 #         modify it under the terms of the GNU General Public License
7 #        as published by the Free Software Foundation; either version 2
8 #            of the License, or (at your option) any later version.
9 #
10 #       This program is distributed in the hope that it will be useful,
11 #        but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #                 GNU General Public License for more details.
14 #
15 #   You should have received a copy of the GNU General Public License along
16 #      with this program; if not, write to the Free Software Foundation,
17 #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 #
19 #
20 #  Author:
21 #    Reto Grieder, Adrian Friedli
22 #  Description:
23 #    Sets the right compiler and linker flags for GCC.
24 #
25
26INCLUDE(FlagUtilities)
27INCLUDE(CompareVersionStrings)
28INCLUDE(CheckCXXCompilerFlag)
29
30# Shortcut for CMAKE_COMPILER_IS_GNUCXX and ..._GNUC
31SET(CMAKE_COMPILER_IS_GNU TRUE)
32
33# Determine compiler version
34EXEC_PROGRAM(
35  ${CMAKE_CXX_COMPILER}
36  ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
37  OUTPUT_VARIABLE GCC_VERSION
38)
39
40# GCC only supports PCH in versions 3.4 and above
41INCLUDE(CompareVersionStrings)
42COMPARE_VERSION_STRINGS("${GCC_VERSION}" "3.4.0" _compare_result)
43IF(_compare_result GREATER -1)
44  SET(PCH_COMPILER_SUPPORT TRUE)
45ENDIF()
46
47# Also include environment flags. Could cause conflicts though
48SET_COMPILER_FLAGS("$ENV{CXXFLAGS}" CXX CACHE)
49SET_COMPILER_FLAGS("$ENV{CFLAGS}"   C   CACHE)
50
51# These flags get added to the flags above
52SET_COMPILER_FLAGS("    -g -ggdb -D_DEBUG" Debug          CACHE)
53SET_COMPILER_FLAGS("             -DNDEBUG" ReleaseAll     CACHE)
54ADD_COMPILER_FLAGS("-O3"                   Release        CACHE)
55ADD_COMPILER_FLAGS("-O2 -g -ggdb"          RelWithDebInfo CACHE)
56ADD_COMPILER_FLAGS("-Os"                   MinSizeRel     CACHE)
57
58# CMake doesn't seem to set the PIC flags right on certain 64 bit systems
59IF(NOT MINGW AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
60  ADD_COMPILER_FLAGS("-fPIC" CACHE)
61ENDIF()
62
63# Never omit frame pointers that could interfere with proper stack traces
64ADD_COMPILER_FLAGS("-fno-omit-frame-pointer" CACHE)
65
66# Enable non standard floating point optimisations
67ADD_COMPILER_FLAGS("-ffast-math" CACHE)
68
69# Use SSE if possible
70# Commented because this might not work for cross compiling
71#CHECK_CXX_COMPILER_FLAG(-msse _gcc_have_sse)
72#IF(_gcc_have_sse)
73#  ADD_COMPILER_FLAGS("-msse" CACHE)
74#ENDIF()
75
76IF(NOT MINGW)
77  # Have GCC visibility?
78  CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" _gcc_have_visibility)
79  IF(_gcc_have_visibility)
80    # Note: There is a possible bug with the flag in gcc < 4.2 and Debug versions
81    COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.2.0" _compare_result)
82    IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR _compare_result GREATER -1)
83      ADD_COMPILER_FLAGS("-DORXONOX_GCC_VISIBILITY -fvisibility=default -fvisibility-inlines-hidden" CACHE)
84    ENDIF()
85  ENDIF(_gcc_have_visibility)
86ENDIF()
87
88# We have some unconformant code, disable an optimisation feature
89ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE)
90
91# For newer GCC (4.3 and above), don't display hundreds of annoying deprecated
92# messages. Other versions don't seem to show any such warnings at all.
93ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE)
94
95# Always show why a precompiled header file could not be used
96ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE)
97
98# Increase warning level if requested
99IF(EXTRA_COMPILER_WARNINGS)
100  ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE)
101ELSE()
102  REMOVE_COMPILER_FLAGS("-Wextra -Wno-unused-parameter" CACHE)
103  ADD_COMPILER_FLAGS("-Wall" CACHE)
104ENDIF()
105
106# Linker flags
107IF(LINUX)
108  # Don't allow undefined symbols in a shared library
109  SET_LINKER_FLAGS("-Wl,--no-undefined" CACHE)
110ENDIF()
111
112# Add compiler and linker flags for MinGW
113IF (MINGW)
114  ADD_COMPILER_FLAGS("-gstabs+" Debug          CACHE)
115  ADD_COMPILER_FLAGS("-gstabs+" RelWithDebInfo CACHE)
116
117  ADD_LINKER_FLAGS("-enable-auto-import" CACHE)
118ENDIF()
Note: See TracBrowser for help on using the repository browser.