[CMake] Add -fno-sanitize=function to UBSan bootstrap
[oota-llvm.git] / cmake / modules / HandleLLVMOptions.cmake
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
5 include(HandleLLVMStdlib)
6 include(AddLLVMDefinitions)
7 include(CheckCCompilerFlag)
8 include(CheckCXXCompilerFlag)
9
10 if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN)
11   if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
12     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
13       message(FATAL_ERROR "Host GCC version must be at least 4.7!")
14     endif()
15   elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
16     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
17       message(FATAL_ERROR "Host Clang version must be at least 3.1!")
18     endif()
19
20     # Also test that we aren't using too old of a version of libstdc++ with the
21     # Clang compiler. This is tricky as there is no real way to check the
22     # version of libstdc++ directly. Instead we test for a known bug in
23     # libstdc++4.6 that is fixed in libstdc++4.7.
24     if(NOT LLVM_ENABLE_LIBCXX)
25       set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
26       set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
27       set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
28       if (ANDROID)
29         set(CMAKE_REQUIRED_LIBRARIES "atomic")
30       endif()
31       check_cxx_source_compiles("
32 #include <atomic>
33 std::atomic<float> x(0.0f);
34 int main() { return (float)x; }"
35         LLVM_NO_OLD_LIBSTDCXX)
36       if(NOT LLVM_NO_OLD_LIBSTDCXX)
37         message(FATAL_ERROR "Host Clang must be able to find libstdc++4.7 or newer!")
38       endif()
39       set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
40       set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
41     endif()
42   elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
43     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0)
44       message(FATAL_ERROR "Host Visual Studio must be at least 2012 (MSVC 17.0)")
45     endif()
46   endif()
47 endif()
48
49 if( LLVM_ENABLE_ASSERTIONS )
50   # MSVC doesn't like _DEBUG on release builds. See PR 4379.
51   if( NOT MSVC )
52     add_definitions( -D_DEBUG )
53   endif()
54   # On non-Debug builds cmake automatically defines NDEBUG, so we
55   # explicitly undefine it:
56   if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
57     add_definitions( -UNDEBUG )
58     # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
59     foreach (flags_var_to_scrub
60         CMAKE_CXX_FLAGS_RELEASE
61         CMAKE_CXX_FLAGS_RELWITHDEBINFO
62         CMAKE_CXX_FLAGS_MINSIZEREL
63         CMAKE_C_FLAGS_RELEASE
64         CMAKE_C_FLAGS_RELWITHDEBINFO
65         CMAKE_C_FLAGS_MINSIZEREL)
66       string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
67         "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
68     endforeach()
69   endif()
70 endif()
71
72 if(WIN32)
73   set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
74   if(CYGWIN)
75     set(LLVM_ON_WIN32 0)
76     set(LLVM_ON_UNIX 1)
77   else(CYGWIN)
78     set(LLVM_ON_WIN32 1)
79     set(LLVM_ON_UNIX 0)
80   endif(CYGWIN)
81   # Maximum path length is 160 for non-unicode paths
82   set(MAXPATHLEN 160)
83 else(WIN32)
84   if(UNIX)
85     set(LLVM_ON_WIN32 0)
86     set(LLVM_ON_UNIX 1)
87     if(APPLE)
88       set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
89     else(APPLE)
90       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
91     endif(APPLE)
92     # FIXME: Maximum path length is currently set to 'safe' fixed value
93     set(MAXPATHLEN 2024)
94   else(UNIX)
95     MESSAGE(SEND_ERROR "Unable to determine platform")
96   endif(UNIX)
97 endif(WIN32)
98
99 set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
100 set(LTDL_SHLIB_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
101
102 # We use *.dylib rather than *.so on darwin.
103 set(LLVM_PLUGIN_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
104
105 if(APPLE)
106   # Darwin-specific linker flags for loadable modules.
107   set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
108 endif()
109
110 function(append value)
111   foreach(variable ${ARGN})
112     set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
113   endforeach(variable)
114 endfunction()
115
116 function(append_if condition value)
117   if (${condition})
118     foreach(variable ${ARGN})
119       set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
120     endforeach(variable)
121   endif()
122 endfunction()
123
124 macro(add_flag_if_supported flag name)
125   check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}")
126   append_if("C_SUPPORTS_${name}" "${flag}" CMAKE_C_FLAGS)
127   check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}")
128   append_if("CXX_SUPPORTS_${name}" "${flag}" CMAKE_CXX_FLAGS)
129 endmacro()
130
131 function(add_flag_or_print_warning flag name)
132   check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}")
133   check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}")
134   if ("C_SUPPORTS_${name}" AND "CXX_SUPPORTS_${name}")
135     message(STATUS "Building with ${flag}")
136     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
137     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
138   else()
139     message(WARNING "${flag} is not supported.")
140   endif()
141 endfunction()
142
143 if( LLVM_ENABLE_PIC )
144   if( XCODE )
145     # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
146     # know how to disable this, so just force ENABLE_PIC off for now.
147     message(WARNING "-fPIC not supported with Xcode.")
148   elseif( WIN32 OR CYGWIN)
149     # On Windows all code is PIC. MinGW warns if -fPIC is used.
150   else()
151     add_flag_or_print_warning("-fPIC" FPIC)
152
153     if( WIN32 OR CYGWIN)
154       # MinGW warns if -fvisibility-inlines-hidden is used.
155     else()
156       check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
157       append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS)
158     endif()
159   endif()
160 endif()
161
162 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
163   # TODO: support other platforms and toolchains.
164   if( LLVM_BUILD_32_BITS )
165     message(STATUS "Building 32 bits executables and libraries.")
166     add_llvm_definitions( -m32 )
167     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
168     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
169     set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32")
170   endif( LLVM_BUILD_32_BITS )
171 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
172
173 if( XCODE )
174   # For Xcode enable several build settings that correspond to
175   # many warnings that are on by default in Clang but are
176   # not enabled for historical reasons.  For versions of Xcode
177   # that do not support these options they will simply
178   # be ignored.
179   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES")
180   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "YES")
181   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES")
182   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES")
183   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES")
184   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES")
185   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED "YES")
186   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES")
187   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES")
188   set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES")
189   set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES")
190   set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES")
191   set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES")
192   set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES")
193   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES")
194 endif()
195
196 # On Win32 using MS tools, provide an option to set the number of parallel jobs
197 # to use.
198 if( MSVC_IDE )
199   set(LLVM_COMPILER_JOBS "0" CACHE STRING
200     "Number of parallel compiler jobs. 0 means use all processors. Default is 0.")
201   if( NOT LLVM_COMPILER_JOBS STREQUAL "1" )
202     if( LLVM_COMPILER_JOBS STREQUAL "0" )
203       add_llvm_definitions( /MP )
204     else()
205       message(STATUS "Number of parallel compiler jobs set to " ${LLVM_COMPILER_JOBS})
206       add_llvm_definitions( /MP${LLVM_COMPILER_JOBS} )
207     endif()
208   else()
209     message(STATUS "Parallel compilation disabled")
210   endif()
211 endif()
212
213 if( MSVC )
214   include(ChooseMSVCCRT)
215
216   if( NOT (${CMAKE_VERSION} VERSION_LESS 2.8.11) )
217     # set stack reserved size to ~10MB
218     # CMake previously automatically set this value for MSVC builds, but the
219     # behavior was changed in CMake 2.8.11 (Issue 12437) to use the MSVC default
220     # value (1 MB) which is not enough for us in tasks such as parsing recursive
221     # C++ templates in Clang.
222     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000")
223   endif()
224
225   if( MSVC11 )
226     add_llvm_definitions(-D_VARIADIC_MAX=10)
227   endif()
228   
229   # Add definitions that make MSVC much less annoying.
230   add_llvm_definitions(
231     # For some reason MS wants to deprecate a bunch of standard functions...
232     -D_CRT_SECURE_NO_DEPRECATE
233     -D_CRT_SECURE_NO_WARNINGS
234     -D_CRT_NONSTDC_NO_DEPRECATE
235     -D_CRT_NONSTDC_NO_WARNINGS
236     -D_SCL_SECURE_NO_DEPRECATE
237     -D_SCL_SECURE_NO_WARNINGS
238
239     # Disabled warnings.
240     -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
241     -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
242     -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
243     -wd4258 # Suppress ''var' : definition from the for loop is ignored; the definition from the enclosing scope is used'
244     -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
245     -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
246     -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
247     -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
248     -wd4355 # Suppress ''this' : used in base member initializer list'
249     -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
250     -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
251     -wd4722 # Suppress 'function' : destructor never returns, potential memory leak
252     -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
253     
254     # Promoted warnings.
255     -w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning.
256
257     # Promoted warnings to errors.
258     -we4238 # Promote 'nonstandard extension used : class rvalue used as lvalue' to error.
259     )
260
261   # Enable warnings
262   if (LLVM_ENABLE_WARNINGS)
263     add_llvm_definitions( /W4 )
264     if (LLVM_ENABLE_PEDANTIC)
265       # No MSVC equivalent available
266     endif (LLVM_ENABLE_PEDANTIC)
267   endif (LLVM_ENABLE_WARNINGS)
268   if (LLVM_ENABLE_WERROR)
269     add_llvm_definitions( /WX )
270   endif (LLVM_ENABLE_WERROR)
271 elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
272   if (LLVM_ENABLE_WARNINGS)
273     append("-Wall -W -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
274
275     # Turn off missing field initializer warnings for gcc to avoid noise from
276     # false positives with empty {}. Turn them on otherwise (they're off by
277     # default for clang).
278     check_cxx_compiler_flag("-Wmissing-field-initializers" CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG)
279     if (CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG)
280       if (CMAKE_COMPILER_IS_GNUCXX)
281         append("-Wno-missing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
282       else()
283         append("-Wmissing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
284       endif()
285     endif()
286
287     append_if(LLVM_ENABLE_PEDANTIC "-pedantic -Wno-long-long" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
288     add_flag_if_supported("-Wcovered-switch-default" COVERED_SWITCH_DEFAULT_FLAG)
289     append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
290     append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)
291
292     # Check if -Wnon-virtual-dtor warns even though the class is marked final.
293     # If it does, don't add it. So it won't be added on clang 3.4 and older.
294     # This also catches cases when -Wnon-virtual-dtor isn't supported by
295     # the compiler at all.
296     set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
297     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11 -Werror=non-virtual-dtor")
298     CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();protected: ~base();};
299                                class derived final : public base { public: ~derived();};
300                                int main() { return 0; }"
301                               CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR)
302     set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
303     append_if(CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR
304               "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS)
305
306     # Check if -Wcomment is OK with an // comment ending with '\' if the next
307     # line is also a // comment.
308     set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
309     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror -Wcomment")
310     CHECK_C_SOURCE_COMPILES("// \\\\\\n//\\nint main() {return 0;}"
311                             C_WCOMMENT_ALLOWS_LINE_WRAP)
312     set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
313     if (NOT C_WCOMMENT_ALLOWS_LINE_WRAP)
314       append("-Wno-comment" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
315     endif()
316   endif (LLVM_ENABLE_WARNINGS)
317   append_if(LLVM_ENABLE_WERROR "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
318   if (NOT LLVM_ENABLE_TIMESTAMPS)
319     add_flag_if_supported("-Werror=date-time" WERROR_DATE_TIME)
320   endif ()
321   if (LLVM_ENABLE_CXX1Y)
322     check_cxx_compiler_flag("-std=c++1y" CXX_SUPPORTS_CXX1Y)
323     append_if(CXX_SUPPORTS_CXX1Y "-std=c++1y" CMAKE_CXX_FLAGS)
324   else()
325     check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11)
326     if (CXX_SUPPORTS_CXX11)
327       if (CYGWIN OR MINGW)
328         # MinGW and Cygwin are a bit stricter and lack things like
329         # 'strdup', 'stricmp', etc in c++11 mode.
330         append("-std=gnu++11" CMAKE_CXX_FLAGS)
331       else()
332         append("-std=c++11" CMAKE_CXX_FLAGS)
333       endif()
334     else()
335       message(FATAL_ERROR "LLVM requires C++11 support but the '-std=c++11' flag isn't supported.")
336     endif()
337   endif()
338 endif( MSVC )
339
340 macro(append_common_sanitizer_flags)
341   # Append -fno-omit-frame-pointer and turn on debug info to get better
342   # stack traces.
343   add_flag_if_supported("-fno-omit-frame-pointer" FNO_OMIT_FRAME_POINTER)
344   if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
345       NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
346     add_flag_if_supported("-gline-tables-only" GLINE_TABLES_ONLY)
347   endif()
348   # Use -O1 even in debug mode, otherwise sanitizers slowdown is too large.
349   if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
350     add_flag_if_supported("-O1" O1)
351   endif()
352 endmacro()
353
354 # Turn on sanitizers if necessary.
355 if(LLVM_USE_SANITIZER)
356   if (LLVM_ON_UNIX)
357     if (LLVM_USE_SANITIZER STREQUAL "Address")
358       append_common_sanitizer_flags()
359       append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
360     elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
361       append_common_sanitizer_flags()
362       append("-fsanitize=memory" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
363       if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
364         append("-fsanitize-memory-track-origins" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
365       endif()
366     elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
367       append_common_sanitizer_flags()
368       append("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover"
369               CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
370     else()
371       message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
372     endif()
373   else()
374     message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
375   endif()
376 endif()
377
378 # Turn on -gsplit-dwarf if requested
379 if(LLVM_USE_SPLIT_DWARF)
380   add_llvm_definitions("-gsplit-dwarf")
381 endif()
382
383 add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
384 add_llvm_definitions( -D__STDC_FORMAT_MACROS )
385 add_llvm_definitions( -D__STDC_LIMIT_MACROS )
386
387 # clang doesn't print colored diagnostics when invoked from Ninja
388 if (UNIX AND
389     CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
390     CMAKE_GENERATOR STREQUAL "Ninja")
391   append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
392 endif()
393
394 # Add flags for add_dead_strip().
395 # FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF?
396 # But MinSizeRel seems to add that automatically, so maybe disable these
397 # flags instead if LLVM_NO_DEAD_STRIP is set.
398 if(NOT CYGWIN AND NOT WIN32)
399   if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
400     check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS)
401     if (C_SUPPORTS_FNO_FUNCTION_SECTIONS)
402       # Don't add -ffunction-section if it can be disabled with -fno-function-sections.
403       # Doing so will break sanitizers.
404       add_flag_if_supported("-ffunction-sections" FFUNCTION_SECTIONS)
405     endif()
406     add_flag_if_supported("-fdata-sections" FDATA_SECTIONS)
407   endif()
408 endif()
409
410 if(CYGWIN OR MINGW)
411   # Prune --out-implib from executables. It doesn't make sense even
412   # with --export-all-symbols.
413   string(REGEX REPLACE "-Wl,--out-implib,[^ ]+ " " "
414     CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
415   string(REGEX REPLACE "-Wl,--out-implib,[^ ]+ " " "
416     CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE}")
417 endif()
418
419 if(MSVC)
420   # Remove flags here, for exceptions and RTTI.
421   # Each target property or source property should be responsible to control
422   # them.
423   # CL.EXE complains to override flags like "/GR /GR-".
424   string(REGEX REPLACE "(^| ) */EH[-cs]+ *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
425   string(REGEX REPLACE "(^| ) */GR-? *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
426 endif()
427
428 # Provide public options to globally control RTTI and EH
429 option(LLVM_ENABLE_EH "Enable Exception handling" OFF)
430 option(LLVM_ENABLE_RTTI "Enable run time type information" OFF)
431 if(LLVM_ENABLE_EH AND NOT LLVM_ENABLE_RTTI)
432   message(FATAL_ERROR "Exception handling requires RTTI. You must set LLVM_ENABLE_RTTI to ON")
433 endif()
434
435 # Plugin support
436 # FIXME: Make this configurable.
437 if(WIN32 OR CYGWIN)
438   if(BUILD_SHARED_LIBS)
439     set(LLVM_ENABLE_PLUGINS ON)
440   else()
441     set(LLVM_ENABLE_PLUGINS OFF)
442   endif()
443 else()
444   set(LLVM_ENABLE_PLUGINS ON)
445 endif()