ACGCompiler.cmake 8.6 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3 4
################################################################################
# Custom settings for compiler flags and similar
################################################################################

5 6 7 8 9 10 11 12 13 14 15 16 17
if ( WIN32 )
  ################################################################################
  # Windows large memory support
  ################################################################################
  if ( NOT DEFINED WINDOWS_LARGE_MEMORY_SUPPORT )
    set( WINDOWS_LARGE_MEMORY_SUPPORT true CACHE BOOL "Enable or disable binary support for large memory" )
  endif()
  
  set( ADDITIONAL_CMAKE_EXE_LINKER_FLAGS )
  set( ADDITIONAL_CMAKE_SHARED_LINKER_FLAGS )
  set( ADDITIONAL_CMAKE_MODULE_LINKER_FLAGS )
  
  if ( WINDOWS_LARGE_MEMORY_SUPPORT )
18
    if (MSVC)
19 20 21
	list(APPEND ADDITIONAL_CMAKE_EXE_LINKER_FLAGS       "/LARGEADDRESSAWARE" )
	list(APPEND ADDITIONAL_CMAKE_SHARED_LINKER_FLAGS    "/LARGEADDRESSAWARE" )
	list(APPEND ADDITIONAL_CMAKE_MODULE_LINKER_FLAGS    "/LARGEADDRESSAWARE" )
Jan Möbius's avatar
Jan Möbius committed
22
  endif()
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  endif()
  
  
  foreach( flag ${ADDITIONAL_CMAKE_EXE_LINKER_FLAGS} )
    if( NOT CMAKE_EXE_LINKER_FLAGS MATCHES "${flag}" )
      set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag} ")
    endif()
  endforeach()
  
  foreach( flag ${ADDITIONAL_CMAKE_SHARED_LINKER_FLAGS} )
    if( NOT CMAKE_SHARED_LINKER_FLAGS MATCHES "${flag}" )
      set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${flag} ")
    endif()
  endforeach()
  
  foreach( flag ${ADDITIONAL_CMAKE_MODULE_LINKER_FLAGS} )
    if( NOT CMAKE_MODULE_LINKER_FLAGS MATCHES "${flag}" )
      set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${flag} ")
    endif()
  endforeach()

endif( WIN32 )

Jan Möbius's avatar
Jan Möbius committed
46 47
if (UNIX)

Jan Möbius's avatar
Jan Möbius committed
48
  set ( ADDITIONAL_CXX_FLAGS )
49 50 51 52
  set ( ADDITIONAL_CXX_DEBUG_FLAGS )
  set ( ADDITIONAL_CXX_RELEASE_FLAGS )
  set ( ADDITIONAL_CXX_RELWITHDEBINFO_FLAGS )
  
Jan Möbius's avatar
Jan Möbius committed
53
  set ( ADDITIONAL_C_FLAGS )
54 55 56 57 58 59 60 61 62
  set ( ADDITIONAL_C_DEBUG_FLAGS )
  set ( ADDITIONAL_C_RELEASE_FLAGS )
  set ( ADDITIONAL_C_RELWITHDEBINFO_FLAGS )

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

  # add our standard flags for Template inclusion
Jan Möbius's avatar
Jan Möbius committed
63 64
  list(APPEND ADDITIONAL_CXX_FLAGS          "-DINCLUDE_TEMPLATES" )
  list(APPEND ADDITIONAL_C_FLAGS            "-DINCLUDE_TEMPLATES" )
65

66 67 68
  ################################################################################
  # OS Defines
  ################################################################################  
Jan Möbius's avatar
Jan Möbius committed
69

Jan Möbius's avatar
Jan Möbius committed
70 71
  if (APPLE)
    add_definitions( -DARCH_DARWIN )
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  endif()
  
  ################################################################################
  # 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
  ################################################################################
Jan Möbius's avatar
Jan Möbius committed
90
  
91 92 93 94 95
  # Add the standard compiler warnings
  if ( NOT COMPILER_WARNINGS )
   
    IF ( APPLE  )
      # Skip unused parameters as it has to be used for the documentation via doxygen and the interfaces
96 97 98
      set ( COMPILER_WARNINGS "-W" "-Wall" "-Wno-unused" "-Wextra" "-Wno-non-virtual-dtor" "-Wno-unused-parameter" "-Wno-variadic-macros" CACHE STRINGLIST "This list contains the warning flags used during compilation " )
    elseif ("${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")
      set ( COMPILER_WARNINGS "-W" "-Wall" "-Wextra" "-Wno-non-virtual-dtor" "-Wno-unused-parameter" "-Wno-variadic-macros" CACHE STRINGLIST "This list contains the warning flags used during compilation " )
99 100 101
    ELSEIF ( CMAKE_SYSTEM MATCHES "SunOS*" )
      set ( COMPILER_WARNINGS "" CACHE STRINGLIST "This list contains the warning flags used during compilation " )
    ELSE ()
102
      set ( COMPILER_WARNINGS "-W" "-Wall" "-Wno-unused" "-Wextra" "-Wno-variadic-macros" CACHE STRINGLIST "This list contains the warning flags used during compilation " )
Jan Möbius's avatar
Jan Möbius committed
103
  ENDIF()
104 105 106

  endif ( NOT COMPILER_WARNINGS )

Jan Möbius's avatar
Jan Möbius committed
107 108 109 110 111 112
  list(APPEND ADDITIONAL_CXX_FLAGS          ${COMPILER_WARNINGS} )
  list(APPEND ADDITIONAL_C_FLAGS            ${COMPILER_WARNINGS} )


  if ("${CMAKE_CXX_COMPILER}" MATCHES ".*clang.*")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Weverything")
Jan Möbius's avatar
Jan Möbius committed
113 114 115 116 117
      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")
Jan Möbius's avatar
Jan Möbius committed
118
      # enable later:
Jan Möbius's avatar
Jan Möbius committed
119 120 121
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-sign-conversion")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-deprecated")
      list(APPEND ADDITIONAL_CXX_FLAGS "-Wno-weak-vtables")
Jan Möbius's avatar
Jan Möbius committed
122 123
  endif()

124 125 126 127 128 129 130 131 132
  ################################################################################
  # 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 )
  
133
  # Add a flag to check stl vectors
134 135 136
  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")
137 138
    list(APPEND ADDITIONAL_CXX_RELEASE_FLAGS        "-D_GLIBCXX_DEBUG" )
    list(APPEND ADDITIONAL_CXX_RELEASE_FLAGS        "-D_GLIBCXX_DEBUG_PEDANTIC")
139 140 141 142 143
    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")
144 145
    list(APPEND ADDITIONAL_C_RELEASE_FLAGS          "-D_GLIBCXX_DEBUG" )
    list(APPEND ADDITIONAL_C_RELEASE_FLAGS          "-D_GLIBCXX_DEBUG_PEDANTIC")
146 147 148 149 150 151 152 153 154
    list(APPEND ADDITIONAL_C_RELWITHDEBINFO_FLAGS   "-D_GLIBCXX_DEBUG" )
    list(APPEND ADDITIONAL_C_RELWITHDEBINFO_FLAGS   "-D_GLIBCXX_DEBUG_PEDANTIC")
  endif()

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

  # Add the debug flags
Jan Möbius's avatar
Jan Möbius committed
155 156 157
  foreach( flag ${ADDITIONAL_CXX_FLAGS} ${ADDITIONAL_CXX_DEBUG_FLAGS} )
    list (FIND ${CMAKE_CXX_FLAGS_DEBUG} ${flag} _index)
    if (${_index} EQUAL -1)
158 159 160 161 162
      set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${flag} ")
    endif()
  endforeach()

  # Add the release flags
Jan Möbius's avatar
Jan Möbius committed
163 164 165
  foreach( flag ${ADDITIONAL_CXX_FLAGS} ${ADDITIONAL_CXX_RELEASE_FLAGS} )
    list (FIND ${CMAKE_CXX_FLAGS_RELEASE} ${flag} _index)
    if (${_index} EQUAL -1)
166 167 168 169 170
      set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${flag} ")
    endif()
  endforeach()

  # Add the release with debug info flags
Jan Möbius's avatar
Jan Möbius committed
171 172 173
  foreach( flag ${ADDITIONAL_CXX_FLAGS} ${ADDITIONAL_CXX_RELWITHDEBINFO_FLAGS} )
    list (FIND ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${flag} _index)
    if (${_index} EQUAL -1)
174 175 176 177 178
      set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${flag} ")
    endif()
  endforeach()

  # Add the debug flags
Jan Möbius's avatar
Jan Möbius committed
179 180 181
  foreach( flag ${ADDITIONAL_C_FLAGS} ${ADDITIONAL_C_DEBUG_FLAGS} )
    list (FIND ${CMAKE_C_FLAGS_DEBUG} ${flag} _index)
    if (${_index} EQUAL -1)
182 183 184 185 186
      set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${flag} ")
    endif()
  endforeach()

  # Add the release flags
Jan Möbius's avatar
Jan Möbius committed
187 188 189
  foreach( flag ${ADDITIONAL_C_FLAGS} ${ADDITIONAL_C_RELEASE_FLAGS} )
      list (FIND ${CMAKE_C_FLAGS_RELEASE} ${flag} _index)
    if (${_index} EQUAL -1)
190 191 192 193 194
      set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${flag} ")
    endif()
  endforeach()

  # Add the release with debug info flags
Jan Möbius's avatar
Jan Möbius committed
195 196 197
  foreach( flag ${ADDITIONAL_C_FLAGS} ${ADDITIONAL_C_RELWITHDEBINFO_FLAGS} )
    list (FIND ${CMAKE_C_FLAGS_RELWITHDEBINFO} ${flag} _index)
    if (${_index} EQUAL -1)
198 199 200 201
      set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${flag} ")
    endif()
  endforeach()

Jan Möbius's avatar
Jan Möbius committed
202
endif ()