| 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 only supports PCH in versions 3.4 and above | 
|---|
| 41 | INCLUDE(CompareVersionStrings) | 
|---|
| 42 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "3.4.0" _compare_result) | 
|---|
| 43 | IF(_compare_result GREATER -1) | 
|---|
| 44 | SET(PCH_COMPILER_SUPPORT TRUE) | 
|---|
| 45 | ENDIF() | 
|---|
| 46 |  | 
|---|
| 47 | # __COUNTER__ macro was only added in GCC 4.3 | 
|---|
| 48 | # It might be required to make full build units work | 
|---|
| 49 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.3.0" _compare_result) | 
|---|
| 50 | IF(_compare_result GREATER -1) | 
|---|
| 51 | SET(HAVE_COUNTER_MACRO 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("-O2 -g -ggdb"          RelForDevs     CACHE) | 
|---|
| 62 | ADD_COMPILER_FLAGS("-O3 -g -ggdb"          RelWithDebInfo CACHE) | 
|---|
| 63 | ADD_COMPILER_FLAGS("-O3"                   Release        CACHE) | 
|---|
| 64 | ADD_COMPILER_FLAGS("-Os"                   MinSizeRel     CACHE) | 
|---|
| 65 |  | 
|---|
| 66 | # Introducing c++11 | 
|---|
| 67 | ADD_COMPILER_FLAGS("-std=gnu++11" CACHE) | 
|---|
| 68 |  | 
|---|
| 69 | # CMake doesn't seem to set the PIC flags right on certain 64 bit systems | 
|---|
| 70 | IF(NOT MINGW AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") | 
|---|
| 71 | ADD_COMPILER_FLAGS("-fPIC" CACHE) | 
|---|
| 72 | ENDIF() | 
|---|
| 73 |  | 
|---|
| 74 | # Never omit frame pointers that could interfere with proper stack traces | 
|---|
| 75 | ADD_COMPILER_FLAGS("-fno-omit-frame-pointer" CACHE) | 
|---|
| 76 |  | 
|---|
| 77 | # Enable non standard floating point optimisations | 
|---|
| 78 | ADD_COMPILER_FLAGS("-ffast-math" CACHE) | 
|---|
| 79 |  | 
|---|
| 80 | # Use SSE if possible | 
|---|
| 81 | # Commented because this might not work for cross compiling | 
|---|
| 82 | #CHECK_CXX_COMPILER_FLAG(-msse _gcc_have_sse) | 
|---|
| 83 | #IF(_gcc_have_sse) | 
|---|
| 84 | #  ADD_COMPILER_FLAGS("-msse" CACHE) | 
|---|
| 85 | #ENDIF() | 
|---|
| 86 |  | 
|---|
| 87 | IF(NOT MINGW) | 
|---|
| 88 | # Have GCC visibility? | 
|---|
| 89 | CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" _gcc_have_visibility) | 
|---|
| 90 | IF(_gcc_have_visibility) | 
|---|
| 91 | # Note: There is a possible bug with the flag in gcc < 4.2 and Debug versions | 
|---|
| 92 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.2.0" _compare_result) | 
|---|
| 93 | IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR _compare_result GREATER -1) | 
|---|
| 94 | ADD_COMPILER_FLAGS("-DORXONOX_GCC_VISIBILITY -fvisibility=default -fvisibility-inlines-hidden" CACHE) | 
|---|
| 95 | ENDIF() | 
|---|
| 96 | ENDIF(_gcc_have_visibility) | 
|---|
| 97 | ENDIF() | 
|---|
| 98 |  | 
|---|
| 99 | # We have some unconformant code, disable an optimisation feature | 
|---|
| 100 | ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE) | 
|---|
| 101 |  | 
|---|
| 102 | # For newer GCC (4.3 and above), don't display hundreds of annoying deprecated | 
|---|
| 103 | # messages. Other versions don't seem to show any such warnings at all. | 
|---|
| 104 | ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE) | 
|---|
| 105 |  | 
|---|
| 106 | # Since GCC 4.8 -Wall includes -Wunused-local-typedefs which triggers lots of warnings | 
|---|
| 107 | # in Boost headers, hence we disable it | 
|---|
| 108 | ADD_COMPILER_FLAGS("-Wno-unused-local-typedefs" CXX CACHE) | 
|---|
| 109 |  | 
|---|
| 110 | # Always show why a precompiled header file could not be used | 
|---|
| 111 | ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE) | 
|---|
| 112 |  | 
|---|
| 113 | # Increase warning level if requested | 
|---|
| 114 | IF(EXTRA_COMPILER_WARNINGS) | 
|---|
| 115 | ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE) | 
|---|
| 116 | ELSE() | 
|---|
| 117 | REMOVE_COMPILER_FLAGS("-Wextra -Wno-unused-parameter" CACHE) | 
|---|
| 118 | ADD_COMPILER_FLAGS("-Wall" CACHE) | 
|---|
| 119 | ENDIF() | 
|---|
| 120 |  | 
|---|
| 121 | # Linker flags | 
|---|
| 122 | IF(LINUX) | 
|---|
| 123 | # Don't allow undefined symbols in a shared library | 
|---|
| 124 | SET_LINKER_FLAGS("-Wl,--no-undefined" CACHE) | 
|---|
| 125 | ENDIF() | 
|---|
| 126 |  | 
|---|
| 127 | # Add compiler and linker flags for MinGW | 
|---|
| 128 | IF (MINGW) | 
|---|
| 129 | ADD_COMPILER_FLAGS("-gstabs+" Debug RelForDevs RelWithDebInfo CACHE) | 
|---|
| 130 |  | 
|---|
| 131 | ADD_LINKER_FLAGS("-Wl,--enable-auto-import" CACHE) | 
|---|
| 132 | ENDIF() | 
|---|