blob: b40103ca1860fa3db79427a824fd7b4193012181 [file] [log] [blame]
Daniel Dunbar10fa2df2011-11-04 19:04:35 +00001# 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 Fuentesf4202ba2011-02-03 20:57:36 +00005include(AddLLVMDefinitions)
Joe Abbey15d98342012-11-26 02:02:08 +00006include(CheckCCompilerFlag)
Jordan Rose643aa0e2013-03-02 01:00:40 +00007include(CheckCXXCompilerFlag)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +00008
Chandler Carruth83885972014-01-13 22:21:34 +00009if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN)
10 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
11 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
12 message(FATAL_ERROR "Host GCC version must be at least 4.7!")
13 endif()
14 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
15 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
16 message(FATAL_ERROR "Host Clang version must be at least 3.1!")
17 endif()
Chandler Carruthf8f00152014-01-17 09:47:55 +000018
19 # Also test that we aren't using too old of a version of libstdc++ with the
20 # Clang compiler. This is tricky as there is no real way to check the
21 # version of libstdc++ directly. Instead we test for a known bug in
22 # libstdc++4.6 that is fixed in libstdc++4.7.
23 if(NOT LLVM_ENABLE_LIBCXX)
Chandler Carruthf4144ad2014-01-21 18:09:19 +000024 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
25 set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
Chandler Carruthf8f00152014-01-17 09:47:55 +000026 set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
Evgeniy Stepanov131585a2014-01-21 09:00:30 +000027 if (ANDROID)
28 set(CMAKE_REQUIRED_LIBRARIES "atomic")
29 endif()
Chandler Carruthf8f00152014-01-17 09:47:55 +000030 check_cxx_source_compiles("
31#include <atomic>
32std::atomic<float> x(0.0f);
33int main() { return (float)x; }"
34 LLVM_NO_OLD_LIBSTDCXX)
35 if(NOT LLVM_NO_OLD_LIBSTDCXX)
36 message(FATAL_ERROR "Host Clang must be able to find libstdc++4.7 or newer!")
37 endif()
Chandler Carruthf4144ad2014-01-21 18:09:19 +000038 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
39 set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
Chandler Carruthf8f00152014-01-17 09:47:55 +000040 endif()
Amara Emerson5569381a2014-01-21 16:41:07 +000041 elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
Chandler Carruth83885972014-01-13 22:21:34 +000042 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0)
43 message(FATAL_ERROR "Host Visual Studio must be at least 2012 (MSVC 17.0)")
44 endif()
45 endif()
46endif()
47
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000048if( LLVM_ENABLE_ASSERTIONS )
49 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
50 if( NOT MSVC )
51 add_definitions( -D_DEBUG )
52 endif()
Duncan Sands80f122f2013-07-17 09:34:51 +000053 # On non-Debug builds cmake automatically defines NDEBUG, so we
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000054 # explicitly undefine it:
Duncan Sands80f122f2013-07-17 09:34:51 +000055 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000056 add_definitions( -UNDEBUG )
Reid Klecknerc1c01d52013-04-07 01:45:01 +000057 # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
Nico Weberd16b48a2013-12-28 23:26:51 +000058 set(REGEXP_NDEBUG "(^| )[/-]D *NDEBUG($| )")
59 string (REGEX REPLACE "${REGEXP_NDEBUG}" " "
60 CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
61 string (REGEX REPLACE "${REGEXP_NDEBUG}" " "
62 CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
63 string (REGEX REPLACE "${REGEXP_NDEBUG}" " "
64 CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000065 endif()
66else()
67 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
Oscar Fuentes7dc9dce2011-02-06 19:07:06 +000068 if( NOT MSVC_IDE AND NOT XCODE )
69 add_definitions( -DNDEBUG )
70 endif()
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000071 endif()
72endif()
73
74if(WIN32)
Nico Weberc27118d2013-12-28 23:31:44 +000075 set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000076 if(CYGWIN)
77 set(LLVM_ON_WIN32 0)
78 set(LLVM_ON_UNIX 1)
79 else(CYGWIN)
80 set(LLVM_ON_WIN32 1)
81 set(LLVM_ON_UNIX 0)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000082 endif(CYGWIN)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000083 # Maximum path length is 160 for non-unicode paths
84 set(MAXPATHLEN 160)
85else(WIN32)
86 if(UNIX)
87 set(LLVM_ON_WIN32 0)
88 set(LLVM_ON_UNIX 1)
89 if(APPLE)
Nico Weberc27118d2013-12-28 23:31:44 +000090 set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000091 else(APPLE)
Nico Weberc27118d2013-12-28 23:31:44 +000092 set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000093 endif(APPLE)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +000094 # FIXME: Maximum path length is currently set to 'safe' fixed value
95 set(MAXPATHLEN 2024)
96 else(UNIX)
97 MESSAGE(SEND_ERROR "Unable to determine platform")
98 endif(UNIX)
99endif(WIN32)
100
Alp Tokerc0b7bb52014-01-08 11:10:24 +0000101set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
102set(LTDL_SHLIB_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
103set(LLVM_PLUGIN_EXT ${CMAKE_SHARED_MODULE_SUFFIX})
104
Alexey Samsonov67065782013-03-13 20:50:23 +0000105function(add_flag_or_print_warning flag)
Alexey Samsonov75789a22013-03-26 07:49:46 +0000106 check_c_compiler_flag(${flag} C_SUPPORTS_FLAG)
107 check_cxx_compiler_flag(${flag} CXX_SUPPORTS_FLAG)
108 if (C_SUPPORTS_FLAG AND CXX_SUPPORTS_FLAG)
Alexey Samsonov67065782013-03-13 20:50:23 +0000109 message(STATUS "Building with ${flag}")
110 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
111 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
112 else()
113 message(WARNING "${flag} is not supported.")
114 endif()
115endfunction()
116
Duncan Sands71de6dc2013-03-25 13:25:34 +0000117function(append value)
118 foreach(variable ${ARGN})
Alexey Samsonov67065782013-03-13 20:50:23 +0000119 set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
Duncan Sands71de6dc2013-03-25 13:25:34 +0000120 endforeach(variable)
121endfunction()
122
123function(append_if condition value)
124 if (${condition})
125 foreach(variable ${ARGN})
126 set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
127 endforeach(variable)
Alexey Samsonov67065782013-03-13 20:50:23 +0000128 endif()
129endfunction()
130
Alexey Samsonov75789a22013-03-26 07:49:46 +0000131macro(add_flag_if_supported flag)
132 check_c_compiler_flag(${flag} C_SUPPORTS_FLAG)
133 append_if(C_SUPPORTS_FLAG "${flag}" CMAKE_C_FLAGS)
134 check_cxx_compiler_flag(${flag} CXX_SUPPORTS_FLAG)
135 append_if(CXX_SUPPORTS_FLAG "${flag}" CMAKE_CXX_FLAGS)
136endmacro()
137
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000138if( LLVM_ENABLE_PIC )
139 if( XCODE )
140 # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
141 # know how to disable this, so just force ENABLE_PIC off for now.
142 message(WARNING "-fPIC not supported with Xcode.")
NAKAMURA Takumi1b745d02011-12-16 06:21:08 +0000143 elseif( WIN32 OR CYGWIN)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000144 # On Windows all code is PIC. MinGW warns if -fPIC is used.
145 else()
Alexey Samsonov67065782013-03-13 20:50:23 +0000146 add_flag_or_print_warning("-fPIC")
Rafael Espindola5258ab82012-01-20 04:07:48 +0000147
Rafael Espindola9f404cc2012-01-20 13:10:10 +0000148 if( WIN32 OR CYGWIN)
149 # MinGW warns if -fvisibility-inlines-hidden is used.
150 else()
151 check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
Duncan Sands71de6dc2013-03-25 13:25:34 +0000152 append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS)
Alexey Samsonov67065782013-03-13 20:50:23 +0000153 endif()
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000154 endif()
155endif()
156
157if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
158 # TODO: support other platforms and toolchains.
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000159 if( LLVM_BUILD_32_BITS )
160 message(STATUS "Building 32 bits executables and libraries.")
161 add_llvm_definitions( -m32 )
Tim Northoverf6e29c42012-05-23 18:42:02 +0000162 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
163 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
Tobias Grosserb32ad402012-06-08 09:41:23 +0000164 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32")
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000165 endif( LLVM_BUILD_32_BITS )
166endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
167
NAKAMURA Takumia83601d2012-04-21 14:50:56 +0000168# On Win32 using MS tools, provide an option to set the number of parallel jobs
169# to use.
NAKAMURA Takumi75bfe692012-04-21 14:51:02 +0000170if( MSVC_IDE )
Oscar Fuentes318c3f12011-03-02 17:47:37 +0000171 set(LLVM_COMPILER_JOBS "0" CACHE STRING
172 "Number of parallel compiler jobs. 0 means use all processors. Default is 0.")
173 if( NOT LLVM_COMPILER_JOBS STREQUAL "1" )
174 if( LLVM_COMPILER_JOBS STREQUAL "0" )
175 add_llvm_definitions( /MP )
176 else()
177 if (MSVC10)
178 message(FATAL_ERROR
179 "Due to a bug in CMake only 0 and 1 is supported for "
180 "LLVM_COMPILER_JOBS when generating for Visual Studio 2010")
181 else()
182 message(STATUS "Number of parallel compiler jobs set to " ${LLVM_COMPILER_JOBS})
183 add_llvm_definitions( /MP${LLVM_COMPILER_JOBS} )
184 endif()
185 endif()
186 else()
187 message(STATUS "Parallel compilation disabled")
188 endif()
189endif()
190
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000191if( MSVC )
192 include(ChooseMSVCCRT)
193
Hans Wennborgbef50ab2013-10-17 18:39:47 +0000194 if( NOT (${CMAKE_VERSION} VERSION_LESS 2.8.11) )
195 # set stack reserved size to ~10MB
196 # CMake previously automatically set this value for MSVC builds, but the
197 # behavior was changed in CMake 2.8.11 (Issue 12437) to use the MSVC default
198 # value (1 MB) which is not enough for us in tasks such as parsing recursive
199 # C++ templates in Clang.
200 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000")
201 endif()
Hans Wennborgfd541f02013-10-17 17:49:57 +0000202
Aaron Ballmanf5aacd32013-07-29 13:02:08 +0000203 if( MSVC10 )
204 # MSVC 10 will complain about headers in the STL not being exported, but
205 # will not complain in MSVC 11.
206 add_llvm_definitions(
207 -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
208 )
209 elseif( MSVC11 )
Michael J. Spencer35145f82012-03-01 22:42:52 +0000210 add_llvm_definitions(-D_VARIADIC_MAX=10)
211 endif()
Aaron Ballmanf5aacd32013-07-29 13:02:08 +0000212
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000213 # Add definitions that make MSVC much less annoying.
214 add_llvm_definitions(
215 # For some reason MS wants to deprecate a bunch of standard functions...
216 -D_CRT_SECURE_NO_DEPRECATE
217 -D_CRT_SECURE_NO_WARNINGS
218 -D_CRT_NONSTDC_NO_DEPRECATE
219 -D_CRT_NONSTDC_NO_WARNINGS
220 -D_SCL_SECURE_NO_DEPRECATE
221 -D_SCL_SECURE_NO_WARNINGS
222
Michael J. Spencer6d45d832012-06-07 21:34:15 +0000223 # Disabled warnings.
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000224 -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
225 -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000226 -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
227 -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000228 -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
229 -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
230 -wd4355 # Suppress ''this' : used in base member initializer list'
231 -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
232 -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000233 -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
Aaron Ballman99ea2912013-08-16 03:06:38 +0000234 -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
Aaron Ballmand1594bd2013-07-28 18:04:26 +0000235
Michael J. Spencer6d45d832012-06-07 21:34:15 +0000236 # Promoted warnings.
237 -w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning.
Michael J. Spenceraeb59e12012-06-07 23:33:56 +0000238
239 # Promoted warnings to errors.
240 -we4238 # Promote 'nonstandard extension used : class rvalue used as lvalue' to error.
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000241 )
242
243 # Enable warnings
244 if (LLVM_ENABLE_WARNINGS)
Michael J. Spencer6d45d832012-06-07 21:34:15 +0000245 add_llvm_definitions( /W4 )
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000246 if (LLVM_ENABLE_PEDANTIC)
247 # No MSVC equivalent available
248 endif (LLVM_ENABLE_PEDANTIC)
249 endif (LLVM_ENABLE_WARNINGS)
250 if (LLVM_ENABLE_WERROR)
251 add_llvm_definitions( /WX )
252 endif (LLVM_ENABLE_WERROR)
Oscar Fuentesab84a7b2011-05-11 13:53:08 +0000253elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000254 if (LLVM_ENABLE_WARNINGS)
Duncan Sands71de6dc2013-03-25 13:25:34 +0000255 append("-Wall -W -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
Edwin Vanec6410842013-01-31 18:05:54 +0000256
257 # Turn off missing field initializer warnings for gcc to avoid noise from
258 # false positives with empty {}. Turn them on otherwise (they're off by
259 # default for clang).
260 check_cxx_compiler_flag("-Wmissing-field-initializers" CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG)
261 if (CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG)
262 if (CMAKE_COMPILER_IS_GNUCXX)
Duncan Sands71de6dc2013-03-25 13:25:34 +0000263 append("-Wno-missing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
Edwin Vanec6410842013-01-31 18:05:54 +0000264 else()
Duncan Sands71de6dc2013-03-25 13:25:34 +0000265 append("-Wmissing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
Edwin Vanec6410842013-01-31 18:05:54 +0000266 endif()
267 endif()
268
Duncan Sands71de6dc2013-03-25 13:25:34 +0000269 append_if(LLVM_ENABLE_PEDANTIC "-pedantic -Wno-long-long" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
Joe Abbey15d98342012-11-26 02:02:08 +0000270 check_cxx_compiler_flag("-Werror -Wcovered-switch-default" CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
Duncan Sands71de6dc2013-03-25 13:25:34 +0000271 append_if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG "-Wcovered-switch-default" CMAKE_CXX_FLAGS)
Joe Abbey15d98342012-11-26 02:02:08 +0000272 check_c_compiler_flag("-Werror -Wcovered-switch-default" C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
Duncan Sands71de6dc2013-03-25 13:25:34 +0000273 append_if(C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG "-Wcovered-switch-default" CMAKE_C_FLAGS)
274 append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
275 append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)
Alexey Samsonovffb4ca82013-03-19 10:10:03 +0000276 check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" CXX_SUPPORTS_NON_VIRTUAL_DTOR_FLAG)
Duncan Sands71de6dc2013-03-25 13:25:34 +0000277 append_if(CXX_SUPPORTS_NON_VIRTUAL_DTOR_FLAG "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000278 endif (LLVM_ENABLE_WARNINGS)
279 if (LLVM_ENABLE_WERROR)
280 add_llvm_definitions( -Werror )
281 endif (LLVM_ENABLE_WERROR)
Arnaud A. de Grandmaisonb697b532013-11-26 10:33:53 +0000282 if (LLVM_ENABLE_CXX11)
283 check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11)
284 append_if(CXX_SUPPORTS_CXX11 "-std=c++11" CMAKE_CXX_FLAGS)
285 endif (LLVM_ENABLE_CXX11)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000286endif( MSVC )
287
Alexey Samsonov75789a22013-03-26 07:49:46 +0000288macro(append_common_sanitizer_flags)
289 # Append -fno-omit-frame-pointer and turn on debug info to get better
290 # stack traces.
291 add_flag_if_supported("-fno-omit-frame-pointer")
292 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
293 NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
294 add_flag_if_supported("-gline-tables-only")
295 endif()
Alexey Samsonovf9ab3512013-09-02 09:15:01 +0000296 # Use -O1 even in debug mode, otherwise sanitizers slowdown is too large.
297 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
298 add_flag_if_supported("-O1")
299 endif()
Alexey Samsonov75789a22013-03-26 07:49:46 +0000300endmacro()
301
302# Turn on sanitizers if necessary.
303if(LLVM_USE_SANITIZER)
304 if (LLVM_ON_UNIX)
305 if (LLVM_USE_SANITIZER STREQUAL "Address")
306 append_common_sanitizer_flags()
307 add_flag_or_print_warning("-fsanitize=address")
308 elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
309 append_common_sanitizer_flags()
310 add_flag_or_print_warning("-fsanitize=memory")
Alexey Samsonov75789a22013-03-26 07:49:46 +0000311 if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
312 add_flag_or_print_warning("-fsanitize-memory-track-origins")
313 endif()
314 else()
315 message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
316 endif()
317 else()
318 message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
319 endif()
320endif()
321
Eric Christopher39878062013-07-30 21:44:10 +0000322# Turn on -gsplit-dwarf if requested
323if(LLVM_USE_SPLIT_DWARF)
Eric Christopher83afc1e2013-07-30 22:34:30 +0000324 add_llvm_definitions("-gsplit-dwarf")
Eric Christopher39878062013-07-30 21:44:10 +0000325endif()
326
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000327add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
NAKAMURA Takumic5554c92011-10-11 12:51:44 +0000328add_llvm_definitions( -D__STDC_FORMAT_MACROS )
NAKAMURA Takumie63cd192011-10-11 12:51:36 +0000329add_llvm_definitions( -D__STDC_LIMIT_MACROS )
Arnaud A. de Grandmaison916f3cc2013-05-29 20:41:35 +0000330
331# clang doesn't print colored diagnostics when invoked from Ninja
Rafael Espindola6f2564c2013-06-14 19:41:05 +0000332if (UNIX AND
333 CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
334 CMAKE_GENERATOR STREQUAL "Ninja")
335 append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
Arnaud A. de Grandmaison916f3cc2013-05-29 20:41:35 +0000336endif()
NAKAMURA Takumibb50bce2014-01-28 09:43:55 +0000337
338# Add flags for add_dead_strip().
339# FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF?
340# But MinSizeRel seems to add that automatically, so maybe disable these
341# flags instead if LLVM_NO_DEAD_STRIP is set.
342if(NOT CYGWIN AND NOT WIN32)
343 if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Alexey Samsonov482beff2014-02-04 08:15:46 +0000344 check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS)
345 if (C_SUPPORTS_FNO_FUNCTION_SECTIONS)
346 # Don't add -ffunction-section if it can be disabled with -fno-function-sections.
347 # Doing so will break sanitizers.
348 check_c_compiler_flag("-Werror -ffunction-sections" C_SUPPORTS_FFUNCTION_SECTIONS)
349 check_cxx_compiler_flag("-Werror -ffunction-sections" CXX_SUPPORTS_FFUNCTION_SECTIONS)
350 append_if(C_SUPPORTS_FFUNCTION_SECTIONS "-ffunction-sections" CMAKE_C_FLAGS)
351 append_if(CXX_SUPPORTS_FFUNCTION_SECTIONS "-ffunction-sections" CMAKE_CXX_FLAGS)
Evgeniy Stepanovc7b7e252014-02-03 13:57:09 +0000352 endif()
Alexey Samsonov482beff2014-02-04 08:15:46 +0000353 check_c_compiler_flag("-Werror -fdata-sections" C_SUPPORTS_FDATA_SECTIONS)
354 check_cxx_compiler_flag("-Werror -fdata-sections" CXX_SUPPORTS_FDATA_SECTIONS)
355 append_if(C_SUPPORTS_FDATA_SECTIONS "-fdata-sections" CMAKE_C_FLAGS)
356 append_if(CXX_SUPPORTS_FDATA_SECTIONS "-fdata-sections" CMAKE_CXX_FLAGS)
NAKAMURA Takumibb50bce2014-01-28 09:43:55 +0000357 endif()
358endif()
NAKAMURA Takumia679f432014-01-28 09:44:06 +0000359
360if(MSVC)
361 # Remove flags here, for exceptions and RTTI.
NAKAMURA Takumiac624642014-01-31 17:32:36 +0000362 # Each target property or source property should be responsible to control
363 # them.
NAKAMURA Takumia679f432014-01-28 09:44:06 +0000364 # CL.EXE complains to override flags like "/GR /GR-".
365 string(REGEX REPLACE "(^| ) */EH[-cs]+ *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
366 string(REGEX REPLACE "(^| ) */GR-? *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
367endif()