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