| Daniel Dunbar | 10fa2df | 2011-11-04 19:04:35 +0000 | [diff] [blame] | 1 | # This CMake module is responsible for interpreting the user defined LLVM_ |
| 2 | # options and executing the appropriate CMake commands to realize the users' |
| 3 | # selections. |
| 4 | |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 5 | include(AddLLVMDefinitions) |
| Joe Abbey | 15d9834 | 2012-11-26 02:02:08 +0000 | [diff] [blame] | 6 | include(CheckCCompilerFlag) |
| Jordan Rose | 643aa0e | 2013-03-02 01:00:40 +0000 | [diff] [blame] | 7 | include(CheckCXXCompilerFlag) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 8 | |
| Oscar Fuentes | ab84a7b | 2011-05-11 13:53:08 +0000 | [diff] [blame] | 9 | if( CMAKE_COMPILER_IS_GNUCXX ) |
| 10 | set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) |
| Hans Wennborg | 3e67a65 | 2013-10-07 22:03:23 +0000 | [diff] [blame] | 11 | elseif( MSVC ) |
| 12 | set(LLVM_COMPILER_IS_GCC_COMPATIBLE OFF) |
| Oscar Fuentes | ab84a7b | 2011-05-11 13:53:08 +0000 | [diff] [blame] | 13 | elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) |
| 14 | set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) |
| 15 | endif() |
| 16 | |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 17 | if( LLVM_ENABLE_ASSERTIONS ) |
| 18 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
| 19 | if( NOT MSVC ) |
| 20 | add_definitions( -D_DEBUG ) |
| 21 | endif() |
| Duncan Sands | 80f122f | 2013-07-17 09:34:51 +0000 | [diff] [blame] | 22 | # On non-Debug builds cmake automatically defines NDEBUG, so we |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 23 | # explicitly undefine it: |
| Duncan Sands | 80f122f | 2013-07-17 09:34:51 +0000 | [diff] [blame] | 24 | if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 25 | add_definitions( -UNDEBUG ) |
| Reid Kleckner | c1c01d5 | 2013-04-07 01:45:01 +0000 | [diff] [blame] | 26 | # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. |
| Nico Weber | d16b48a | 2013-12-28 23:26:51 +0000 | [diff] [blame] | 27 | set(REGEXP_NDEBUG "(^| )[/-]D *NDEBUG($| )") |
| 28 | string (REGEX REPLACE "${REGEXP_NDEBUG}" " " |
| 29 | CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") |
| 30 | string (REGEX REPLACE "${REGEXP_NDEBUG}" " " |
| 31 | CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") |
| 32 | string (REGEX REPLACE "${REGEXP_NDEBUG}" " " |
| 33 | CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}") |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 34 | endif() |
| 35 | else() |
| 36 | if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" ) |
| Oscar Fuentes | 7dc9dce | 2011-02-06 19:07:06 +0000 | [diff] [blame] | 37 | if( NOT MSVC_IDE AND NOT XCODE ) |
| 38 | add_definitions( -DNDEBUG ) |
| 39 | endif() |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 40 | endif() |
| 41 | endif() |
| 42 | |
| 43 | if(WIN32) |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame^] | 44 | set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 45 | if(CYGWIN) |
| 46 | set(LLVM_ON_WIN32 0) |
| 47 | set(LLVM_ON_UNIX 1) |
| 48 | else(CYGWIN) |
| 49 | set(LLVM_ON_WIN32 1) |
| 50 | set(LLVM_ON_UNIX 0) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 51 | endif(CYGWIN) |
| 52 | set(LTDL_SHLIB_EXT ".dll") |
| 53 | set(EXEEXT ".exe") |
| 54 | # Maximum path length is 160 for non-unicode paths |
| 55 | set(MAXPATHLEN 160) |
| 56 | else(WIN32) |
| 57 | if(UNIX) |
| 58 | set(LLVM_ON_WIN32 0) |
| 59 | set(LLVM_ON_UNIX 1) |
| 60 | if(APPLE) |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame^] | 61 | set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 62 | set(LTDL_SHLIB_EXT ".dylib") |
| 63 | else(APPLE) |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame^] | 64 | set(LLVM_HAVE_LINK_VERSION_SCRIPT 1) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 65 | set(LTDL_SHLIB_EXT ".so") |
| 66 | endif(APPLE) |
| 67 | set(EXEEXT "") |
| 68 | # FIXME: Maximum path length is currently set to 'safe' fixed value |
| 69 | set(MAXPATHLEN 2024) |
| 70 | else(UNIX) |
| 71 | MESSAGE(SEND_ERROR "Unable to determine platform") |
| 72 | endif(UNIX) |
| 73 | endif(WIN32) |
| 74 | |
| Alexey Samsonov | 6706578 | 2013-03-13 20:50:23 +0000 | [diff] [blame] | 75 | function(add_flag_or_print_warning flag) |
| Alexey Samsonov | 75789a2 | 2013-03-26 07:49:46 +0000 | [diff] [blame] | 76 | check_c_compiler_flag(${flag} C_SUPPORTS_FLAG) |
| 77 | check_cxx_compiler_flag(${flag} CXX_SUPPORTS_FLAG) |
| 78 | if (C_SUPPORTS_FLAG AND CXX_SUPPORTS_FLAG) |
| Alexey Samsonov | 6706578 | 2013-03-13 20:50:23 +0000 | [diff] [blame] | 79 | message(STATUS "Building with ${flag}") |
| 80 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) |
| 81 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE) |
| 82 | else() |
| 83 | message(WARNING "${flag} is not supported.") |
| 84 | endif() |
| 85 | endfunction() |
| 86 | |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 87 | function(append value) |
| 88 | foreach(variable ${ARGN}) |
| Alexey Samsonov | 6706578 | 2013-03-13 20:50:23 +0000 | [diff] [blame] | 89 | set(${variable} "${${variable}} ${value}" PARENT_SCOPE) |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 90 | endforeach(variable) |
| 91 | endfunction() |
| 92 | |
| 93 | function(append_if condition value) |
| 94 | if (${condition}) |
| 95 | foreach(variable ${ARGN}) |
| 96 | set(${variable} "${${variable}} ${value}" PARENT_SCOPE) |
| 97 | endforeach(variable) |
| Alexey Samsonov | 6706578 | 2013-03-13 20:50:23 +0000 | [diff] [blame] | 98 | endif() |
| 99 | endfunction() |
| 100 | |
| Alexey Samsonov | 75789a2 | 2013-03-26 07:49:46 +0000 | [diff] [blame] | 101 | macro(add_flag_if_supported flag) |
| 102 | check_c_compiler_flag(${flag} C_SUPPORTS_FLAG) |
| 103 | append_if(C_SUPPORTS_FLAG "${flag}" CMAKE_C_FLAGS) |
| 104 | check_cxx_compiler_flag(${flag} CXX_SUPPORTS_FLAG) |
| 105 | append_if(CXX_SUPPORTS_FLAG "${flag}" CMAKE_CXX_FLAGS) |
| 106 | endmacro() |
| 107 | |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 108 | if( LLVM_ENABLE_PIC ) |
| 109 | if( XCODE ) |
| 110 | # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't |
| 111 | # know how to disable this, so just force ENABLE_PIC off for now. |
| 112 | message(WARNING "-fPIC not supported with Xcode.") |
| NAKAMURA Takumi | 1b745d0 | 2011-12-16 06:21:08 +0000 | [diff] [blame] | 113 | elseif( WIN32 OR CYGWIN) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 114 | # On Windows all code is PIC. MinGW warns if -fPIC is used. |
| 115 | else() |
| Alexey Samsonov | 6706578 | 2013-03-13 20:50:23 +0000 | [diff] [blame] | 116 | add_flag_or_print_warning("-fPIC") |
| Rafael Espindola | 5258ab8 | 2012-01-20 04:07:48 +0000 | [diff] [blame] | 117 | |
| Rafael Espindola | 9f404cc | 2012-01-20 13:10:10 +0000 | [diff] [blame] | 118 | if( WIN32 OR CYGWIN) |
| 119 | # MinGW warns if -fvisibility-inlines-hidden is used. |
| 120 | else() |
| 121 | check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG) |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 122 | append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS) |
| Alexey Samsonov | 6706578 | 2013-03-13 20:50:23 +0000 | [diff] [blame] | 123 | endif() |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 124 | endif() |
| 125 | endif() |
| 126 | |
| 127 | if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 128 | # TODO: support other platforms and toolchains. |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 129 | if( LLVM_BUILD_32_BITS ) |
| 130 | message(STATUS "Building 32 bits executables and libraries.") |
| 131 | add_llvm_definitions( -m32 ) |
| Tim Northover | f6e29c4 | 2012-05-23 18:42:02 +0000 | [diff] [blame] | 132 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") |
| 133 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") |
| Tobias Grosser | b32ad40 | 2012-06-08 09:41:23 +0000 | [diff] [blame] | 134 | set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32") |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 135 | endif( LLVM_BUILD_32_BITS ) |
| 136 | endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 137 | |
| NAKAMURA Takumi | a83601d | 2012-04-21 14:50:56 +0000 | [diff] [blame] | 138 | # On Win32 using MS tools, provide an option to set the number of parallel jobs |
| 139 | # to use. |
| NAKAMURA Takumi | 75bfe69 | 2012-04-21 14:51:02 +0000 | [diff] [blame] | 140 | if( MSVC_IDE ) |
| Oscar Fuentes | 318c3f1 | 2011-03-02 17:47:37 +0000 | [diff] [blame] | 141 | set(LLVM_COMPILER_JOBS "0" CACHE STRING |
| 142 | "Number of parallel compiler jobs. 0 means use all processors. Default is 0.") |
| 143 | if( NOT LLVM_COMPILER_JOBS STREQUAL "1" ) |
| 144 | if( LLVM_COMPILER_JOBS STREQUAL "0" ) |
| 145 | add_llvm_definitions( /MP ) |
| 146 | else() |
| 147 | if (MSVC10) |
| 148 | message(FATAL_ERROR |
| 149 | "Due to a bug in CMake only 0 and 1 is supported for " |
| 150 | "LLVM_COMPILER_JOBS when generating for Visual Studio 2010") |
| 151 | else() |
| 152 | message(STATUS "Number of parallel compiler jobs set to " ${LLVM_COMPILER_JOBS}) |
| 153 | add_llvm_definitions( /MP${LLVM_COMPILER_JOBS} ) |
| 154 | endif() |
| 155 | endif() |
| 156 | else() |
| 157 | message(STATUS "Parallel compilation disabled") |
| 158 | endif() |
| 159 | endif() |
| 160 | |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 161 | if( MSVC ) |
| 162 | include(ChooseMSVCCRT) |
| 163 | |
| Hans Wennborg | bef50ab | 2013-10-17 18:39:47 +0000 | [diff] [blame] | 164 | if( NOT (${CMAKE_VERSION} VERSION_LESS 2.8.11) ) |
| 165 | # set stack reserved size to ~10MB |
| 166 | # CMake previously automatically set this value for MSVC builds, but the |
| 167 | # behavior was changed in CMake 2.8.11 (Issue 12437) to use the MSVC default |
| 168 | # value (1 MB) which is not enough for us in tasks such as parsing recursive |
| 169 | # C++ templates in Clang. |
| 170 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000") |
| 171 | endif() |
| Hans Wennborg | fd541f0 | 2013-10-17 17:49:57 +0000 | [diff] [blame] | 172 | |
| Aaron Ballman | f5aacd3 | 2013-07-29 13:02:08 +0000 | [diff] [blame] | 173 | if( MSVC10 ) |
| 174 | # MSVC 10 will complain about headers in the STL not being exported, but |
| 175 | # will not complain in MSVC 11. |
| 176 | add_llvm_definitions( |
| 177 | -wd4275 # Suppress 'An exported class was derived from a class that was not exported.' |
| 178 | ) |
| 179 | elseif( MSVC11 ) |
| Michael J. Spencer | 35145f8 | 2012-03-01 22:42:52 +0000 | [diff] [blame] | 180 | add_llvm_definitions(-D_VARIADIC_MAX=10) |
| 181 | endif() |
| Aaron Ballman | f5aacd3 | 2013-07-29 13:02:08 +0000 | [diff] [blame] | 182 | |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 183 | # Add definitions that make MSVC much less annoying. |
| 184 | add_llvm_definitions( |
| 185 | # For some reason MS wants to deprecate a bunch of standard functions... |
| 186 | -D_CRT_SECURE_NO_DEPRECATE |
| 187 | -D_CRT_SECURE_NO_WARNINGS |
| 188 | -D_CRT_NONSTDC_NO_DEPRECATE |
| 189 | -D_CRT_NONSTDC_NO_WARNINGS |
| 190 | -D_SCL_SECURE_NO_DEPRECATE |
| 191 | -D_SCL_SECURE_NO_WARNINGS |
| 192 | |
| Michael J. Spencer | 6d45d83 | 2012-06-07 21:34:15 +0000 | [diff] [blame] | 193 | # Disabled warnings. |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 194 | -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned' |
| 195 | -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored' |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 196 | -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data' |
| 197 | -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data' |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 198 | -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized' |
| 199 | -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized' |
| 200 | -wd4355 # Suppress ''this' : used in base member initializer list' |
| 201 | -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated' |
| 202 | -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible' |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 203 | -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)' |
| Aaron Ballman | 99ea291 | 2013-08-16 03:06:38 +0000 | [diff] [blame] | 204 | -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception' |
| Aaron Ballman | d1594bd | 2013-07-28 18:04:26 +0000 | [diff] [blame] | 205 | |
| Michael J. Spencer | 6d45d83 | 2012-06-07 21:34:15 +0000 | [diff] [blame] | 206 | # Promoted warnings. |
| 207 | -w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning. |
| Michael J. Spencer | aeb59e1 | 2012-06-07 23:33:56 +0000 | [diff] [blame] | 208 | |
| 209 | # Promoted warnings to errors. |
| 210 | -we4238 # Promote 'nonstandard extension used : class rvalue used as lvalue' to error. |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 211 | ) |
| 212 | |
| 213 | # Enable warnings |
| 214 | if (LLVM_ENABLE_WARNINGS) |
| Michael J. Spencer | 6d45d83 | 2012-06-07 21:34:15 +0000 | [diff] [blame] | 215 | add_llvm_definitions( /W4 ) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 216 | if (LLVM_ENABLE_PEDANTIC) |
| 217 | # No MSVC equivalent available |
| 218 | endif (LLVM_ENABLE_PEDANTIC) |
| 219 | endif (LLVM_ENABLE_WARNINGS) |
| 220 | if (LLVM_ENABLE_WERROR) |
| 221 | add_llvm_definitions( /WX ) |
| 222 | endif (LLVM_ENABLE_WERROR) |
| Oscar Fuentes | ab84a7b | 2011-05-11 13:53:08 +0000 | [diff] [blame] | 223 | elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 224 | if (LLVM_ENABLE_WARNINGS) |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 225 | append("-Wall -W -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| Edwin Vane | c641084 | 2013-01-31 18:05:54 +0000 | [diff] [blame] | 226 | |
| 227 | # Turn off missing field initializer warnings for gcc to avoid noise from |
| 228 | # false positives with empty {}. Turn them on otherwise (they're off by |
| 229 | # default for clang). |
| 230 | check_cxx_compiler_flag("-Wmissing-field-initializers" CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG) |
| 231 | if (CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG) |
| 232 | if (CMAKE_COMPILER_IS_GNUCXX) |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 233 | append("-Wno-missing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| Edwin Vane | c641084 | 2013-01-31 18:05:54 +0000 | [diff] [blame] | 234 | else() |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 235 | append("-Wmissing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| Edwin Vane | c641084 | 2013-01-31 18:05:54 +0000 | [diff] [blame] | 236 | endif() |
| 237 | endif() |
| 238 | |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 239 | append_if(LLVM_ENABLE_PEDANTIC "-pedantic -Wno-long-long" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| Joe Abbey | 15d9834 | 2012-11-26 02:02:08 +0000 | [diff] [blame] | 240 | check_cxx_compiler_flag("-Werror -Wcovered-switch-default" CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG) |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 241 | append_if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG "-Wcovered-switch-default" CMAKE_CXX_FLAGS) |
| Joe Abbey | 15d9834 | 2012-11-26 02:02:08 +0000 | [diff] [blame] | 242 | check_c_compiler_flag("-Werror -Wcovered-switch-default" C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG) |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 243 | append_if(C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG "-Wcovered-switch-default" CMAKE_C_FLAGS) |
| 244 | append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS) |
| 245 | append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS) |
| Alexey Samsonov | ffb4ca8 | 2013-03-19 10:10:03 +0000 | [diff] [blame] | 246 | check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" CXX_SUPPORTS_NON_VIRTUAL_DTOR_FLAG) |
| Duncan Sands | 71de6dc | 2013-03-25 13:25:34 +0000 | [diff] [blame] | 247 | append_if(CXX_SUPPORTS_NON_VIRTUAL_DTOR_FLAG "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 248 | endif (LLVM_ENABLE_WARNINGS) |
| 249 | if (LLVM_ENABLE_WERROR) |
| 250 | add_llvm_definitions( -Werror ) |
| 251 | endif (LLVM_ENABLE_WERROR) |
| Arnaud A. de Grandmaison | b697b53 | 2013-11-26 10:33:53 +0000 | [diff] [blame] | 252 | if (LLVM_ENABLE_CXX11) |
| 253 | check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11) |
| 254 | append_if(CXX_SUPPORTS_CXX11 "-std=c++11" CMAKE_CXX_FLAGS) |
| 255 | endif (LLVM_ENABLE_CXX11) |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 256 | endif( MSVC ) |
| 257 | |
| Alexey Samsonov | 75789a2 | 2013-03-26 07:49:46 +0000 | [diff] [blame] | 258 | macro(append_common_sanitizer_flags) |
| 259 | # Append -fno-omit-frame-pointer and turn on debug info to get better |
| 260 | # stack traces. |
| 261 | add_flag_if_supported("-fno-omit-frame-pointer") |
| 262 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 263 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
| 264 | add_flag_if_supported("-gline-tables-only") |
| 265 | endif() |
| Alexey Samsonov | f9ab351 | 2013-09-02 09:15:01 +0000 | [diff] [blame] | 266 | # Use -O1 even in debug mode, otherwise sanitizers slowdown is too large. |
| 267 | if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
| 268 | add_flag_if_supported("-O1") |
| 269 | endif() |
| Alexey Samsonov | 75789a2 | 2013-03-26 07:49:46 +0000 | [diff] [blame] | 270 | endmacro() |
| 271 | |
| 272 | # Turn on sanitizers if necessary. |
| 273 | if(LLVM_USE_SANITIZER) |
| 274 | if (LLVM_ON_UNIX) |
| 275 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
| 276 | append_common_sanitizer_flags() |
| 277 | add_flag_or_print_warning("-fsanitize=address") |
| 278 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
| 279 | append_common_sanitizer_flags() |
| 280 | add_flag_or_print_warning("-fsanitize=memory") |
| Alexey Samsonov | 75789a2 | 2013-03-26 07:49:46 +0000 | [diff] [blame] | 281 | if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
| 282 | add_flag_or_print_warning("-fsanitize-memory-track-origins") |
| 283 | endif() |
| 284 | else() |
| 285 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 286 | endif() |
| 287 | else() |
| 288 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
| 289 | endif() |
| 290 | endif() |
| 291 | |
| Eric Christopher | 3987806 | 2013-07-30 21:44:10 +0000 | [diff] [blame] | 292 | # Turn on -gsplit-dwarf if requested |
| 293 | if(LLVM_USE_SPLIT_DWARF) |
| Eric Christopher | 83afc1e | 2013-07-30 22:34:30 +0000 | [diff] [blame] | 294 | add_llvm_definitions("-gsplit-dwarf") |
| Eric Christopher | 3987806 | 2013-07-30 21:44:10 +0000 | [diff] [blame] | 295 | endif() |
| 296 | |
| Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 297 | add_llvm_definitions( -D__STDC_CONSTANT_MACROS ) |
| NAKAMURA Takumi | c5554c9 | 2011-10-11 12:51:44 +0000 | [diff] [blame] | 298 | add_llvm_definitions( -D__STDC_FORMAT_MACROS ) |
| NAKAMURA Takumi | e63cd19 | 2011-10-11 12:51:36 +0000 | [diff] [blame] | 299 | add_llvm_definitions( -D__STDC_LIMIT_MACROS ) |
| Arnaud A. de Grandmaison | 916f3cc | 2013-05-29 20:41:35 +0000 | [diff] [blame] | 300 | |
| 301 | # clang doesn't print colored diagnostics when invoked from Ninja |
| Rafael Espindola | 6f2564c | 2013-06-14 19:41:05 +0000 | [diff] [blame] | 302 | if (UNIX AND |
| 303 | CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND |
| 304 | CMAKE_GENERATOR STREQUAL "Ninja") |
| 305 | append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| Arnaud A. de Grandmaison | 916f3cc | 2013-05-29 20:41:35 +0000 | [diff] [blame] | 306 | endif() |