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 | |
---|
29 | # Shortcut for CMAKE_COMPILER_IS_GNUCXX and ..._GNUC |
---|
30 | SET(CMAKE_COMPILER_IS_GNU TRUE) |
---|
31 | |
---|
32 | # Determine compiler version |
---|
33 | EXEC_PROGRAM( |
---|
34 | ${CMAKE_CXX_COMPILER} |
---|
35 | ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion |
---|
36 | OUTPUT_VARIABLE GCC_VERSION |
---|
37 | ) |
---|
38 | |
---|
39 | # GCC may not support #pragma GCC system_header correctly when using |
---|
40 | # templates. According to Bugzilla, it was fixed March 07 but tests |
---|
41 | # have confirmed that GCC 4.0.0 does not pose a problem for our cases. |
---|
42 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.0.0" _compare_result) |
---|
43 | IF(_compare_result LESS 0) |
---|
44 | SET(GCC_NO_SYSTEM_HEADER_SUPPORT TRUE) |
---|
45 | ENDIF() |
---|
46 | |
---|
47 | # GCC only supports PCH in versions 3.4 and above |
---|
48 | INCLUDE(CompareVersionStrings) |
---|
49 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "3.4.0" _compare_result) |
---|
50 | IF(_compare_result GREATER -1) |
---|
51 | SET(PCH_COMPILER_SUPPORT TRUE) |
---|
52 | ENDIF() |
---|
53 | |
---|
54 | # Also include environment flags. Could cause conflicts though |
---|
55 | SET_COMPILER_FLAGS("$ENV{CXXFLAGS}" CXX CACHE) |
---|
56 | SET_COMPILER_FLAGS("$ENV{CFLAGS}" C CACHE) |
---|
57 | |
---|
58 | # These flags get added to the flags above |
---|
59 | SET_COMPILER_FLAGS(" -g -ggdb -D_DEBUG" Debug CACHE) |
---|
60 | SET_COMPILER_FLAGS(" -DNDEBUG" ReleaseAll CACHE) |
---|
61 | ADD_COMPILER_FLAGS("-O3" Release CACHE) |
---|
62 | ADD_COMPILER_FLAGS("-O2 -g -ggdb" RelWithDebInfo CACHE) |
---|
63 | ADD_COMPILER_FLAGS("-Os" MinSizeRel CACHE) |
---|
64 | |
---|
65 | # CMake doesn't seem to set the PIC flags right on certain 64 bit systems |
---|
66 | IF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") |
---|
67 | ADD_COMPILER_FLAGS("-fPIC" CACHE) |
---|
68 | ENDIF() |
---|
69 | |
---|
70 | # We have some unconformant code, disable an optimisation feature |
---|
71 | ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE) |
---|
72 | |
---|
73 | # For GCC older than version 4, do not display sign compare warnings |
---|
74 | # because of boost::filesystem (which creates about a hundred per include) |
---|
75 | ADD_COMPILER_FLAGS("-Wno-sign-compare" GCC_NO_SYSTEM_HEADER_SUPPORT CACHE) |
---|
76 | |
---|
77 | # For newer GCC (4.3 and above), don't display hundreds of annoying deprecated |
---|
78 | # messages. Other versions don't seem to show any such warnings at all. |
---|
79 | ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE) |
---|
80 | |
---|
81 | # Always show why a precompiled header file could not be used |
---|
82 | ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE) |
---|
83 | |
---|
84 | # Increase warning level if requested |
---|
85 | IF(EXTRA_COMPILER_WARNINGS) |
---|
86 | ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE) |
---|
87 | ELSE() |
---|
88 | REMOVE_COMPILER_FLAGS("-Wextra -Wno-unused-parameter" CACHE) |
---|
89 | ADD_COMPILER_FLAGS("-Wall" CACHE) |
---|
90 | ENDIF() |
---|
91 | |
---|
92 | # General linker flags |
---|
93 | SET_LINKER_FLAGS("--no-undefined" CACHE) |
---|
94 | |
---|
95 | # Add compiler and linker flags for MinGW |
---|
96 | IF (MINGW) |
---|
97 | ADD_COMPILER_FLAGS("-gstabs+" Debug CACHE) |
---|
98 | ADD_COMPILER_FLAGS("-gstabs+" RelWithDebInfo CACHE) |
---|
99 | |
---|
100 | ADD_LINKER_FLAGS("-enable-auto-import" CACHE) |
---|
101 | ENDIF() |
---|