+
+# clang doesn't print colored diagnostics when invoked from Ninja
+if (UNIX AND
+ CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
+ CMAKE_GENERATOR STREQUAL "Ninja")
+ append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+endif()
+
+# Add flags for add_dead_strip().
+# FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF?
+# But MinSizeRel seems to add that automatically, so maybe disable these
+# flags instead if LLVM_NO_DEAD_STRIP is set.
+if(NOT CYGWIN AND NOT WIN32)
+ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+ check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS)
+ if (C_SUPPORTS_FNO_FUNCTION_SECTIONS)
+ # Don't add -ffunction-section if it can be disabled with -fno-function-sections.
+ # Doing so will break sanitizers.
+ add_flag_if_supported("-ffunction-sections" FFUNCTION_SECTIONS)
+ endif()
+ add_flag_if_supported("-fdata-sections" FDATA_SECTIONS)
+ endif()
+endif()
+
+if(CYGWIN OR MINGW)
+ # Prune --out-implib from executables. It doesn't make sense even
+ # with --export-all-symbols.
+ string(REGEX REPLACE "-Wl,--out-implib,[^ ]+ " " "
+ CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
+ string(REGEX REPLACE "-Wl,--out-implib,[^ ]+ " " "
+ CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE}")
+endif()
+
+if(MSVC)
+ # Remove flags here, for exceptions and RTTI.
+ # Each target property or source property should be responsible to control
+ # them.
+ # CL.EXE complains to override flags like "/GR /GR-".
+ string(REGEX REPLACE "(^| ) */EH[-cs]+ *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REGEX REPLACE "(^| ) */GR-? *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+endif()
+
+# Provide public options to globally control RTTI and EH
+option(LLVM_ENABLE_EH "Enable Exception handling" OFF)
+option(LLVM_ENABLE_RTTI "Enable run time type information" OFF)
+if(LLVM_ENABLE_EH AND NOT LLVM_ENABLE_RTTI)
+ message(FATAL_ERROR "Exception handling requires RTTI. You must set LLVM_ENABLE_RTTI to ON")
+endif()
+
+# Plugin support
+# FIXME: Make this configurable.
+if(WIN32 OR CYGWIN)
+ if(BUILD_SHARED_LIBS)
+ set(LLVM_ENABLE_PLUGINS ON)
+ else()
+ set(LLVM_ENABLE_PLUGINS OFF)
+ endif()
+else()
+ set(LLVM_ENABLE_PLUGINS ON)
+endif()