ACGCompiler.cmake 7.2 KB
Newer Older
Mike Kremer's avatar
Mike Kremer committed
1
2
3
4
5
6
################################################################################
# Custom settings for compiler flags and similar
################################################################################

if (UNIX)

7
  set ( ADDITIONAL_CXX_FLAGS )
Mike Kremer's avatar
Mike Kremer committed
8
9
10
11
  set ( ADDITIONAL_CXX_DEBUG_FLAGS )
  set ( ADDITIONAL_CXX_RELEASE_FLAGS )
  set ( ADDITIONAL_CXX_RELWITHDEBINFO_FLAGS )
  
12
  set ( ADDITIONAL_C_FLAGS )
Mike Kremer's avatar
Mike Kremer committed
13
14
15
16
17
18
19
20
21
  set ( ADDITIONAL_C_DEBUG_FLAGS )
  set ( ADDITIONAL_C_RELEASE_FLAGS )
  set ( ADDITIONAL_C_RELWITHDEBINFO_FLAGS )

  ################################################################################
  # Defaults
  ################################################################################

  # add our standard flags for Template inclusion
22
23
  list(APPEND ADDITIONAL_CXX_FLAGS          "-DINCLUDE_TEMPLATES" )
  list(APPEND ADDITIONAL_C_FLAGS            "-DINCLUDE_TEMPLATES" )
Mike Kremer's avatar
Mike Kremer committed
24
25
26
  
  # Increase the template depth as this might be exceeded from time to time
  IF( NOT CMAKE_SYSTEM MATCHES "SunOS*")
27
    list(APPEND ADDITIONAL_CXX_FLAGS          "-ftemplate-depth-100" )
Mike Kremer's avatar
Mike Kremer committed
28
  ENDIF()
29
30


Mike Kremer's avatar
Mike Kremer committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  
  ################################################################################
  # Build/Release Defines
  ################################################################################
  IF( NOT CMAKE_SYSTEM MATCHES "SunOS*")
    list(APPEND ADDITIONAL_CXX_DEBUG_FLAGS          "-DDEBUG" )
    list(APPEND ADDITIONAL_CXX_RELEASE_FLAGS        "-DNDEBUG" )
    list(APPEND ADDITIONAL_CXX_RELWITHDEBINFO_FLAGS "-DDEBUG" )    
    
    list(APPEND ADDITIONAL_C_DEBUG_FLAGS            "-DDEBUG" )
    list(APPEND ADDITIONAL_C_RELEASE_FLAGS          "-DNDEBUG" )
    list(APPEND ADDITIONAL_C_RELWITHDEBINFO_FLAGS   "-DDEBUG" )
  ENDIF()  
  
  ################################################################################
  # Warnings
  ################################################################################
  
  IF( NOT CMAKE_SYSTEM MATCHES "SunOS*")
50
51
    list(APPEND ADDITIONAL_CXX_FLAGS          "-W" "-Wall" "-Wno-unused" )
    list(APPEND ADDITIONAL_C_FLAGS            "-W" "-Wall" "-Wno-unused" )
Mike Kremer's avatar
Mike Kremer committed
52
  ENDIF()
53
54
55
56
57
58
59
60
61
62
63
64
65

  if ("${CMAKE_CXX_COMPILER}" MATCHES ".*clang.*")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Weverything")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-c++98-compat")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-padded")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-old-style-cast")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-documentation-unknown-command")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-unreachable-code-return")
      # enable later:
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-sign-conversion")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-deprecated")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-weak-vtables")
  endif()
Mike Kremer's avatar
Mike Kremer committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  
  ################################################################################
  # STL Vector checks
  ################################################################################
  
  # Pre initialize stl vector check variable
  if ( NOT STL_VECTOR_CHECKS )
    set ( STL_VECTOR_CHECKS false CACHE BOOL "Include full stl vector checks in debug mode (This option is only used in debug Mode!)" )
  endif ( NOT STL_VECTOR_CHECKS )
  
  # Add a flag to check stl vectors in debugging mode
  if ( STL_VECTOR_CHECKS AND NOT CMAKE_SYSTEM MATCHES "SunOS*"  )
    list(APPEND ADDITIONAL_CXX_DEBUG_FLAGS          "-D_GLIBCXX_DEBUG" )
    list(APPEND ADDITIONAL_CXX_DEBUG_FLAGS          "-D_GLIBCXX_DEBUG_PEDANTIC")
    list(APPEND ADDITIONAL_CXX_RELWITHDEBINFO_FLAGS "-D_GLIBCXX_DEBUG" )
    list(APPEND ADDITIONAL_CXX_RELWITHDEBINFO_FLAGS "-D_GLIBCXX_DEBUG_PEDANTIC")
    
    list(APPEND ADDITIONAL_C_DEBUG_FLAGS            "-D_GLIBCXX_DEBUG" )
    list(APPEND ADDITIONAL_C_DEBUG_FLAGS            "-D_GLIBCXX_DEBUG_PEDANTIC")
    list(APPEND ADDITIONAL_C_RELWITHDEBINFO_FLAGS   "-D_GLIBCXX_DEBUG" )
    list(APPEND ADDITIONAL_C_RELWITHDEBINFO_FLAGS   "-D_GLIBCXX_DEBUG_PEDANTIC")
Jan Möbius's avatar
Jan Möbius committed
87
  endif()
Mike Kremer's avatar
Mike Kremer committed
88
89
90
91
92
93

  ################################################################################
  # Process the additional flags:
  ################################################################################

  # Add the debug flags
94
95
96
  foreach( flag ${ADDITIONAL_CXX_FLAGS} ${ADDITIONAL_CXX_DEBUG_FLAGS} )
    list (FIND ${CMAKE_CXX_FLAGS_DEBUG} ${flag} _index)
    if (${_index} EQUAL -1)
Mike Kremer's avatar
Mike Kremer committed
97
98
99
100
101
      set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${flag} ")
    endif()
  endforeach()

  # Add the release flags
102
103
104
  foreach( flag ${ADDITIONAL_CXX_FLAGS} ${ADDITIONAL_CXX_RELEASE_FLAGS} )
    list (FIND ${CMAKE_CXX_FLAGS_RELEASE} ${flag} _index)
    if (${_index} EQUAL -1)
Mike Kremer's avatar
Mike Kremer committed
105
106
107
108
109
      set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${flag} ")
    endif()
  endforeach()

  # Add the release with debug info flags
110
111
112
  foreach( flag ${ADDITIONAL_CXX_FLAGS} ${ADDITIONAL_CXX_RELWITHDEBINFO_FLAGS} )
    list (FIND ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${flag} _index)
    if (${_index} EQUAL -1)
Mike Kremer's avatar
Mike Kremer committed
113
114
115
116
117
      set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${flag} ")
    endif()
  endforeach()

  # Add the debug flags
118
119
120
  foreach( flag ${ADDITIONAL_C_FLAGS} ${ADDITIONAL_C_DEBUG_FLAGS} )
    list (FIND ${CMAKE_C_FLAGS_DEBUG} ${flag} _index)
    if (${_index} EQUAL -1)
Mike Kremer's avatar
Mike Kremer committed
121
122
123
124
125
      set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${flag} ")
    endif()
  endforeach()

  # Add the release flags
126
127
128
  foreach( flag ${ADDITIONAL_C_FLAGS} ${ADDITIONAL_C_RELEASE_FLAGS} )
      list (FIND ${CMAKE_C_FLAGS_RELEASE} ${flag} _index)
    if (${_index} EQUAL -1)
Mike Kremer's avatar
Mike Kremer committed
129
130
131
132
133
      set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${flag} ")
    endif()
  endforeach()

  # Add the release with debug info flags
134
135
136
  foreach( flag ${ADDITIONAL_C_FLAGS} ${ADDITIONAL_C_RELWITHDEBINFO_FLAGS} )
    list (FIND ${CMAKE_C_FLAGS_RELWITHDEBINFO} ${flag} _index)
    if (${_index} EQUAL -1)
Mike Kremer's avatar
Mike Kremer committed
137
138
139
140
141
142
143
144
145
      set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${flag} ")
    endif()
  endforeach()

  #TODO : Test and remove it?!
  IF( CMAKE_SYSTEM MATCHES "SunOS*")
    set (CMAKE_CFLAGS_RELEASE "-xO3")
    set (CMAKE_CXX_FLAGS_RELEASE "-xO3")        
  endif ( CMAKE_SYSTEM MATCHES "SunOS*" ) 
Jan Möbius's avatar
Jan Möbius committed
146
147
148
149
150
151

  ################################################################################
  # C++ 11 support
  ################################################################################

  # On apple, if we have c++ 11 support, we enable it automatically here
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#  if (APPLE)
#
#    include(CheckCXXCompilerFlag)
#    CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
#    CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
#
#    if(COMPILER_SUPPORTS_CXX11)
#       set( CMAKE_CXX_FLAGS_DEBUG          "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
#       set( CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
#       set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
#    elseif(COMPILER_SUPPORTS_CXX0X)
#       set( CMAKE_CXX_FLAGS_DEBUG          "${CMAKE_CXX_FLAGS_DEBUG} -std=c++0x")
#       set( CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS_DEBUG} -std=c++0x")
#       set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_DEBUG} -std=c++0x")
#    else()
#        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Falling back to non C++11 mode. If you encounter errors, please use a different C++ compiler.")
#    endif()
#
#  endif()
Jan Möbius's avatar
Jan Möbius committed
171

Mike Kremer's avatar
Mike Kremer committed
172
173
  
endif ()