Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/unity_build/cmake/CompilerConfigGCC.cmake @ 8739

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

The COUNTER macro required for full build units was only added in GCC 4.3.
Warn the developer if using GCC < 4.3 and full build units.

  • Property svn:eol-style set to native
File size: 4.4 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# __COUNTER__ macro was only added in GCC 4.3
48# It might be required to make full build units work
49COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.3.0" _compare_result)
50IF(_compare_result GREATER -1)
51  SET(HAVE_COUNTER_MACRO TRUE)
52ENDIF()
53
54# Also include environment flags. Could cause conflicts though
55SET_COMPILER_FLAGS("$ENV{CXXFLAGS}" CXX CACHE)
56SET_COMPILER_FLAGS("$ENV{CFLAGS}"   C   CACHE)
57
58# These flags get added to the flags above
59SET_COMPILER_FLAGS("    -g -ggdb -D_DEBUG" Debug          CACHE)
60SET_COMPILER_FLAGS("             -DNDEBUG" ReleaseAll     CACHE)
61ADD_COMPILER_FLAGS("-O2 -g -ggdb"          RelForDevs     CACHE)
62ADD_COMPILER_FLAGS("-O3 -g -ggdb"          RelWithDebInfo CACHE)
63ADD_COMPILER_FLAGS("-O3"                   Release        CACHE)
64ADD_COMPILER_FLAGS("-Os"                   MinSizeRel     CACHE)
65
66# CMake doesn't seem to set the PIC flags right on certain 64 bit systems
67IF(NOT MINGW AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
68  ADD_COMPILER_FLAGS("-fPIC" CACHE)
69ENDIF()
70
71# Never omit frame pointers that could interfere with proper stack traces
72ADD_COMPILER_FLAGS("-fno-omit-frame-pointer" CACHE)
73
74# Enable non standard floating point optimisations
75ADD_COMPILER_FLAGS("-ffast-math" CACHE)
76
77# Use SSE if possible
78# Commented because this might not work for cross compiling
79#CHECK_CXX_COMPILER_FLAG(-msse _gcc_have_sse)
80#IF(_gcc_have_sse)
81#  ADD_COMPILER_FLAGS("-msse" CACHE)
82#ENDIF()
83
84IF(NOT MINGW)
85  # Have GCC visibility?
86  CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" _gcc_have_visibility)
87  IF(_gcc_have_visibility)
88    # Note: There is a possible bug with the flag in gcc < 4.2 and Debug versions
89    COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.2.0" _compare_result)
90    IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR _compare_result GREATER -1)
91      ADD_COMPILER_FLAGS("-DORXONOX_GCC_VISIBILITY -fvisibility=default -fvisibility-inlines-hidden" CACHE)
92    ENDIF()
93  ENDIF(_gcc_have_visibility)
94ENDIF()
95
96# We have some unconformant code, disable an optimisation feature
97ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE)
98
99# For newer GCC (4.3 and above), don't display hundreds of annoying deprecated
100# messages. Other versions don't seem to show any such warnings at all.
101ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE)
102
103# Always show why a precompiled header file could not be used
104ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE)
105
106# Increase warning level if requested
107IF(EXTRA_COMPILER_WARNINGS)
108  ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE)
109ELSE()
110  REMOVE_COMPILER_FLAGS("-Wextra -Wno-unused-parameter" CACHE)
111  ADD_COMPILER_FLAGS("-Wall" CACHE)
112ENDIF()
113
114# Linker flags
115IF(LINUX)
116  # Don't allow undefined symbols in a shared library
117  SET_LINKER_FLAGS("-Wl,--no-undefined" CACHE)
118ENDIF()
119
120# Add compiler and linker flags for MinGW
121IF (MINGW)
122  ADD_COMPILER_FLAGS("-gstabs+" Debug RelForDevs RelWithDebInfo CACHE)
123
124  ADD_LINKER_FLAGS("-enable-auto-import" CACHE)
125ENDIF()
Note: See TracBrowser for help on using the repository browser.