Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx/cmake/CompilerConfigGCC.cmake @ 8500

Last change on this file since 8500 was 8044, checked in by rgrieder, 14 years ago

No -fpic on MinGW 64 bit.

  • Property svn:eol-style set to native
File size: 4.4 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)
[7520]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
40# GCC may not support #pragma GCC system_header correctly when using
41# templates. According to Bugzilla, it was fixed March 07 but tests
42# have confirmed that GCC 4.0.0 does not pose a problem for our cases.
43COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.0.0" _compare_result)
[2640]44IF(_compare_result LESS 0)
[2641]45  SET(GCC_NO_SYSTEM_HEADER_SUPPORT TRUE)
[2638]46ENDIF()
47
[3196]48# GCC only supports PCH in versions 3.4 and above
49INCLUDE(CompareVersionStrings)
50COMPARE_VERSION_STRINGS("${GCC_VERSION}" "3.4.0" _compare_result)
51IF(_compare_result GREATER -1)
52  SET(PCH_COMPILER_SUPPORT TRUE)
53ENDIF()
54
[2621]55# Also include environment flags. Could cause conflicts though
56SET_COMPILER_FLAGS("$ENV{CXXFLAGS}" CXX CACHE)
57SET_COMPILER_FLAGS("$ENV{CFLAGS}"   C   CACHE)
[2582]58
[2621]59# These flags get added to the flags above
60SET_COMPILER_FLAGS("    -g -ggdb -D_DEBUG" Debug          CACHE)
61SET_COMPILER_FLAGS("             -DNDEBUG" ReleaseAll     CACHE)
62ADD_COMPILER_FLAGS("-O3"                   Release        CACHE)
63ADD_COMPILER_FLAGS("-O2 -g -ggdb"          RelWithDebInfo CACHE)
64ADD_COMPILER_FLAGS("-Os"                   MinSizeRel     CACHE)
[2582]65
[2621]66# CMake doesn't seem to set the PIC flags right on certain 64 bit systems
[8044]67IF(NOT MINGW AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
[2621]68  ADD_COMPILER_FLAGS("-fPIC" CACHE)
[2624]69ENDIF()
[2621]70
[7520]71# Use SSE if possible
[7524]72# Commented because this might not work for cross compiling
73#CHECK_CXX_COMPILER_FLAG(-msse _gcc_have_sse)
74#IF(_gcc_have_sse)
75#  ADD_COMPILER_FLAGS("-msse" CACHE)
76#ENDIF()
[7520]77
[7526]78IF(NOT MINGW)
[7520]79  # Have GCC visibility?
80  CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" _gcc_have_visibility)
81  IF(_gcc_have_visibility)
82    # Note: There is a possible bug with the flag in gcc < 4.2 and Debug versions
83    COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.2.0" _compare_result)
[7522]84    IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR _compare_result GREATER -1)
[7526]85      ADD_COMPILER_FLAGS("-DORXONOX_GCC_VISIBILITY -fvisibility=default -fvisibility-inlines-hidden" CACHE)
[7520]86    ENDIF()
[7522]87  ENDIF(_gcc_have_visibility)
[7526]88ENDIF()
[7520]89
[7416]90# We have some unconformant code, disable an optimisation feature
[3111]91ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE)
[2704]92
[7416]93# For GCC older than version 4, do not display sign compare warnings
[2690]94# because of boost::filesystem (which creates about a hundred per include)
95ADD_COMPILER_FLAGS("-Wno-sign-compare" GCC_NO_SYSTEM_HEADER_SUPPORT CACHE)
96
[2896]97# For newer GCC (4.3 and above), don't display hundreds of annoying deprecated
98# messages. Other versions don't seem to show any such warnings at all.
[2988]99ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE)
[2896]100
[3196]101# Always show why a precompiled header file could not be used
102ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE)
103
[2621]104# Increase warning level if requested
[2673]105IF(EXTRA_COMPILER_WARNINGS)
[2868]106  ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE)
[2624]107ELSE()
[2868]108  REMOVE_COMPILER_FLAGS("-Wextra -Wno-unused-parameter" CACHE)
[2621]109  ADD_COMPILER_FLAGS("-Wall" CACHE)
[2624]110ENDIF()
[2621]111
112# General linker flags
113SET_LINKER_FLAGS("--no-undefined" CACHE)
[7429]114
[7458]115# Add compiler and linker flags for MinGW
[7429]116IF (MINGW)
[7458]117  ADD_COMPILER_FLAGS("-gstabs+" Debug          CACHE)
118  ADD_COMPILER_FLAGS("-gstabs+" RelWithDebInfo CACHE)
119
[7429]120  ADD_LINKER_FLAGS("-enable-auto-import" CACHE)
[7458]121ENDIF()
Note: See TracBrowser for help on using the repository browser.