Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11/cmake/CompilerConfigGCC.cmake @ 10525

Last change on this file since 10525 was 10441, checked in by bknecht, 9 years ago

Turned on c++11 flag in compiler and fixed a bug where boost couldn't handle it.

  • Property svn:eol-style set to native
File size: 4.7 KB
RevLine 
[2579]1 #
[2626]2 #             ORXONOX - the hottest 3D action shooter ever to exist
3 #                             > www.orxonox.net <
[2579]4 #
[2626]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.
[2579]9 #
[2626]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.
[2579]14 #
[2626]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.
[2579]18 #
19 #
[2626]20 #  Author:
21 #    Reto Grieder, Adrian Friedli
22 #  Description:
23 #    Sets the right compiler and linker flags for GCC.
[2579]24 #
25
[5664]26INCLUDE(FlagUtilities)
[5702]27INCLUDE(CompareVersionStrings)
[8351]28INCLUDE(CheckCXXCompilerFlag)
[5664]29
[3196]30# Shortcut for CMAKE_COMPILER_IS_GNUCXX and ..._GNUC
31SET(CMAKE_COMPILER_IS_GNU TRUE)
32
[2638]33# Determine compiler version
34EXEC_PROGRAM(
35  ${CMAKE_CXX_COMPILER}
36  ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
37  OUTPUT_VARIABLE GCC_VERSION
38)
39
[3196]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
[8729]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
[2621]54# Also include environment flags. Could cause conflicts though
55SET_COMPILER_FLAGS("$ENV{CXXFLAGS}" CXX CACHE)
56SET_COMPILER_FLAGS("$ENV{CFLAGS}"   C   CACHE)
[2582]57
[2621]58# These flags get added to the flags above
59SET_COMPILER_FLAGS("    -g -ggdb -D_DEBUG" Debug          CACHE)
60SET_COMPILER_FLAGS("             -DNDEBUG" ReleaseAll     CACHE)
[8368]61ADD_COMPILER_FLAGS("-O2 -g -ggdb"          RelForDevs     CACHE)
62ADD_COMPILER_FLAGS("-O3 -g -ggdb"          RelWithDebInfo CACHE)
[2621]63ADD_COMPILER_FLAGS("-O3"                   Release        CACHE)
64ADD_COMPILER_FLAGS("-Os"                   MinSizeRel     CACHE)
[2582]65
[10441]66# Introducing c++11
67# Note: there is also 'std=gnu++11', but that might not be portable to windows
68ADD_COMPILER_FLAGS("-std=c++0x" CACHE)
69
[2621]70# CMake doesn't seem to set the PIC flags right on certain 64 bit systems
[8351]71IF(NOT MINGW AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
[2621]72  ADD_COMPILER_FLAGS("-fPIC" CACHE)
[2624]73ENDIF()
[2621]74
[8364]75# Never omit frame pointers that could interfere with proper stack traces
76ADD_COMPILER_FLAGS("-fno-omit-frame-pointer" CACHE)
77
[8351]78# Enable non standard floating point optimisations
79ADD_COMPILER_FLAGS("-ffast-math" CACHE)
80
81# Use SSE if possible
82# Commented because this might not work for cross compiling
83#CHECK_CXX_COMPILER_FLAG(-msse _gcc_have_sse)
84#IF(_gcc_have_sse)
85#  ADD_COMPILER_FLAGS("-msse" CACHE)
86#ENDIF()
87
88IF(NOT MINGW)
89  # Have GCC visibility?
90  CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" _gcc_have_visibility)
91  IF(_gcc_have_visibility)
92    # Note: There is a possible bug with the flag in gcc < 4.2 and Debug versions
93    COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.2.0" _compare_result)
94    IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR _compare_result GREATER -1)
95      ADD_COMPILER_FLAGS("-DORXONOX_GCC_VISIBILITY -fvisibility=default -fvisibility-inlines-hidden" CACHE)
96    ENDIF()
97  ENDIF(_gcc_have_visibility)
98ENDIF()
99
[7416]100# We have some unconformant code, disable an optimisation feature
[3111]101ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE)
[2704]102
[2896]103# For newer GCC (4.3 and above), don't display hundreds of annoying deprecated
104# messages. Other versions don't seem to show any such warnings at all.
[2988]105ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE)
[2896]106
[9686]107# Since GCC 4.8 -Wall includes -Wunused-local-typedefs which triggers lots of warnings
108# in Boost headers, hence we disable it
109ADD_COMPILER_FLAGS("-Wno-unused-local-typedefs" CXX CACHE)
110
[3196]111# Always show why a precompiled header file could not be used
112ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE)
113
[2621]114# Increase warning level if requested
[2673]115IF(EXTRA_COMPILER_WARNINGS)
[2868]116  ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE)
[2624]117ELSE()
[2868]118  REMOVE_COMPILER_FLAGS("-Wextra -Wno-unused-parameter" CACHE)
[2621]119  ADD_COMPILER_FLAGS("-Wall" CACHE)
[2624]120ENDIF()
[2621]121
[8351]122# Linker flags
123IF(LINUX)
124  # Don't allow undefined symbols in a shared library
125  SET_LINKER_FLAGS("-Wl,--no-undefined" CACHE)
126ENDIF()
[7429]127
[7458]128# Add compiler and linker flags for MinGW
[7429]129IF (MINGW)
[8368]130  ADD_COMPILER_FLAGS("-gstabs+" Debug RelForDevs RelWithDebInfo CACHE)
[7458]131
[9674]132  ADD_LINKER_FLAGS("-Wl,--enable-auto-import" CACHE)
[7458]133ENDIF()
Note: See TracBrowser for help on using the repository browser.