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 | |
---|
26 | INCLUDE(FlagUtilities) |
---|
27 | INCLUDE(CompareVersionStrings) |
---|
28 | INCLUDE(CheckCXXCompilerFlag) |
---|
29 | |
---|
30 | # Shortcut for CMAKE_COMPILER_IS_GNUCXX and ..._GNUC |
---|
31 | SET(CMAKE_COMPILER_IS_GNU TRUE) |
---|
32 | |
---|
33 | # Determine compiler version |
---|
34 | EXEC_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. |
---|
43 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.0.0" _compare_result) |
---|
44 | IF(_compare_result LESS 0) |
---|
45 | SET(GCC_NO_SYSTEM_HEADER_SUPPORT TRUE) |
---|
46 | ENDIF() |
---|
47 | |
---|
48 | # GCC only supports PCH in versions 3.4 and above |
---|
49 | INCLUDE(CompareVersionStrings) |
---|
50 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "3.4.0" _compare_result) |
---|
51 | IF(_compare_result GREATER -1) |
---|
52 | SET(PCH_COMPILER_SUPPORT TRUE) |
---|
53 | ENDIF() |
---|
54 | |
---|
55 | # Also include environment flags. Could cause conflicts though |
---|
56 | SET_COMPILER_FLAGS("$ENV{CXXFLAGS}" CXX CACHE) |
---|
57 | SET_COMPILER_FLAGS("$ENV{CFLAGS}" C CACHE) |
---|
58 | |
---|
59 | # These flags get added to the flags above |
---|
60 | SET_COMPILER_FLAGS(" -g -ggdb -D_DEBUG" Debug CACHE) |
---|
61 | SET_COMPILER_FLAGS(" -DNDEBUG" ReleaseAll CACHE) |
---|
62 | ADD_COMPILER_FLAGS("-O3" Release CACHE) |
---|
63 | ADD_COMPILER_FLAGS("-O2 -g -ggdb" RelWithDebInfo CACHE) |
---|
64 | ADD_COMPILER_FLAGS("-Os" MinSizeRel CACHE) |
---|
65 | |
---|
66 | # CMake doesn't seem to set the PIC flags right on certain 64 bit systems |
---|
67 | IF(NOT MINGW AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") |
---|
68 | ADD_COMPILER_FLAGS("-fPIC" CACHE) |
---|
69 | ENDIF() |
---|
70 | |
---|
71 | # Enable non standard floating point optimisations |
---|
72 | ADD_COMPILER_FLAGS("-ffast-math" CACHE) |
---|
73 | |
---|
74 | # Use SSE if possible |
---|
75 | # Commented because this might not work for cross compiling |
---|
76 | #CHECK_CXX_COMPILER_FLAG(-msse _gcc_have_sse) |
---|
77 | #IF(_gcc_have_sse) |
---|
78 | # ADD_COMPILER_FLAGS("-msse" CACHE) |
---|
79 | #ENDIF() |
---|
80 | |
---|
81 | IF(NOT MINGW) |
---|
82 | # Have GCC visibility? |
---|
83 | CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" _gcc_have_visibility) |
---|
84 | IF(_gcc_have_visibility) |
---|
85 | # Note: There is a possible bug with the flag in gcc < 4.2 and Debug versions |
---|
86 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.2.0" _compare_result) |
---|
87 | IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR _compare_result GREATER -1) |
---|
88 | ADD_COMPILER_FLAGS("-DORXONOX_GCC_VISIBILITY -fvisibility=default -fvisibility-inlines-hidden" CACHE) |
---|
89 | ENDIF() |
---|
90 | ENDIF(_gcc_have_visibility) |
---|
91 | ENDIF() |
---|
92 | |
---|
93 | # We have some unconformant code, disable an optimisation feature |
---|
94 | ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE) |
---|
95 | |
---|
96 | # For GCC older than version 4, do not display sign compare warnings |
---|
97 | # because of boost::filesystem (which creates about a hundred per include) |
---|
98 | ADD_COMPILER_FLAGS("-Wno-sign-compare" GCC_NO_SYSTEM_HEADER_SUPPORT CACHE) |
---|
99 | |
---|
100 | # For newer GCC (4.3 and above), don't display hundreds of annoying deprecated |
---|
101 | # messages. Other versions don't seem to show any such warnings at all. |
---|
102 | ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE) |
---|
103 | |
---|
104 | # Always show why a precompiled header file could not be used |
---|
105 | ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE) |
---|
106 | |
---|
107 | # Increase warning level if requested |
---|
108 | IF(EXTRA_COMPILER_WARNINGS) |
---|
109 | ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE) |
---|
110 | ELSE() |
---|
111 | REMOVE_COMPILER_FLAGS("-Wextra -Wno-unused-parameter" CACHE) |
---|
112 | ADD_COMPILER_FLAGS("-Wall" CACHE) |
---|
113 | ENDIF() |
---|
114 | |
---|
115 | # General linker flags |
---|
116 | #SET_LINKER_FLAGS("-Wl,--no-undefined" CACHE) |
---|
117 | SET_LINKER_FLAGS("" CACHE) |
---|
118 | |
---|
119 | # Add compiler and linker flags for MinGW |
---|
120 | IF (MINGW) |
---|
121 | ADD_COMPILER_FLAGS("-gstabs+" Debug CACHE) |
---|
122 | ADD_COMPILER_FLAGS("-gstabs+" RelWithDebInfo CACHE) |
---|
123 | |
---|
124 | ADD_LINKER_FLAGS("-enable-auto-import" CACHE) |
---|
125 | ENDIF() |
---|