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