[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] | 26 | INCLUDE(FlagUtilities) |
---|
[5702] | 27 | INCLUDE(CompareVersionStrings) |
---|
[8351] | 28 | INCLUDE(CheckCXXCompilerFlag) |
---|
[5664] | 29 | |
---|
[3196] | 30 | # Shortcut for CMAKE_COMPILER_IS_GNUCXX and ..._GNUC |
---|
| 31 | SET(CMAKE_COMPILER_IS_GNU TRUE) |
---|
| 32 | |
---|
[2638] | 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 | |
---|
[3196] | 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 | |
---|
[2621] | 47 | # Also include environment flags. Could cause conflicts though |
---|
| 48 | SET_COMPILER_FLAGS("$ENV{CXXFLAGS}" CXX CACHE) |
---|
| 49 | SET_COMPILER_FLAGS("$ENV{CFLAGS}" C CACHE) |
---|
[2582] | 50 | |
---|
[2621] | 51 | # These flags get added to the flags above |
---|
| 52 | SET_COMPILER_FLAGS(" -g -ggdb -D_DEBUG" Debug CACHE) |
---|
| 53 | SET_COMPILER_FLAGS(" -DNDEBUG" ReleaseAll CACHE) |
---|
[8368] | 54 | ADD_COMPILER_FLAGS("-O2 -g -ggdb" RelForDevs CACHE) |
---|
| 55 | ADD_COMPILER_FLAGS("-O3 -g -ggdb" RelWithDebInfo CACHE) |
---|
[2621] | 56 | ADD_COMPILER_FLAGS("-O3" Release CACHE) |
---|
| 57 | ADD_COMPILER_FLAGS("-Os" MinSizeRel CACHE) |
---|
[2582] | 58 | |
---|
[2621] | 59 | # CMake doesn't seem to set the PIC flags right on certain 64 bit systems |
---|
[8351] | 60 | IF(NOT MINGW AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") |
---|
[2621] | 61 | ADD_COMPILER_FLAGS("-fPIC" CACHE) |
---|
[2624] | 62 | ENDIF() |
---|
[2621] | 63 | |
---|
[8364] | 64 | # Never omit frame pointers that could interfere with proper stack traces |
---|
| 65 | ADD_COMPILER_FLAGS("-fno-omit-frame-pointer" CACHE) |
---|
| 66 | |
---|
[8351] | 67 | # Enable non standard floating point optimisations |
---|
| 68 | ADD_COMPILER_FLAGS("-ffast-math" CACHE) |
---|
| 69 | |
---|
| 70 | # Use SSE if possible |
---|
| 71 | # Commented because this might not work for cross compiling |
---|
| 72 | #CHECK_CXX_COMPILER_FLAG(-msse _gcc_have_sse) |
---|
| 73 | #IF(_gcc_have_sse) |
---|
| 74 | # ADD_COMPILER_FLAGS("-msse" CACHE) |
---|
| 75 | #ENDIF() |
---|
| 76 | |
---|
| 77 | IF(NOT MINGW) |
---|
| 78 | # Have GCC visibility? |
---|
| 79 | CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" _gcc_have_visibility) |
---|
| 80 | IF(_gcc_have_visibility) |
---|
| 81 | # Note: There is a possible bug with the flag in gcc < 4.2 and Debug versions |
---|
| 82 | COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.2.0" _compare_result) |
---|
| 83 | IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR _compare_result GREATER -1) |
---|
| 84 | ADD_COMPILER_FLAGS("-DORXONOX_GCC_VISIBILITY -fvisibility=default -fvisibility-inlines-hidden" CACHE) |
---|
| 85 | ENDIF() |
---|
| 86 | ENDIF(_gcc_have_visibility) |
---|
| 87 | ENDIF() |
---|
| 88 | |
---|
[7416] | 89 | # We have some unconformant code, disable an optimisation feature |
---|
[3111] | 90 | ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE) |
---|
[2704] | 91 | |
---|
[2896] | 92 | # For newer GCC (4.3 and above), don't display hundreds of annoying deprecated |
---|
| 93 | # messages. Other versions don't seem to show any such warnings at all. |
---|
[2988] | 94 | ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE) |
---|
[2896] | 95 | |
---|
[3196] | 96 | # Always show why a precompiled header file could not be used |
---|
| 97 | ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE) |
---|
| 98 | |
---|
[2621] | 99 | # Increase warning level if requested |
---|
[2673] | 100 | IF(EXTRA_COMPILER_WARNINGS) |
---|
[2868] | 101 | ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE) |
---|
[2624] | 102 | ELSE() |
---|
[2868] | 103 | REMOVE_COMPILER_FLAGS("-Wextra -Wno-unused-parameter" CACHE) |
---|
[2621] | 104 | ADD_COMPILER_FLAGS("-Wall" CACHE) |
---|
[2624] | 105 | ENDIF() |
---|
[2621] | 106 | |
---|
[8351] | 107 | # Linker flags |
---|
| 108 | IF(LINUX) |
---|
| 109 | # Don't allow undefined symbols in a shared library |
---|
| 110 | SET_LINKER_FLAGS("-Wl,--no-undefined" CACHE) |
---|
| 111 | ENDIF() |
---|
[7429] | 112 | |
---|
[7458] | 113 | # Add compiler and linker flags for MinGW |
---|
[7429] | 114 | IF (MINGW) |
---|
[8368] | 115 | ADD_COMPILER_FLAGS("-gstabs+" Debug RelForDevs RelWithDebInfo CACHE) |
---|
[7458] | 116 | |
---|
[7429] | 117 | ADD_LINKER_FLAGS("-enable-auto-import" CACHE) |
---|
[7458] | 118 | ENDIF() |
---|