xref: /aosp_15_r20/external/compiler-rt/CMakeLists.txt (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot# CMake build for CompilerRT.
2*7c3d14c8STreehugger Robot#
3*7c3d14c8STreehugger Robot# This build assumes that CompilerRT is checked out into the
4*7c3d14c8STreehugger Robot# 'projects/compiler-rt' inside of an LLVM tree.
5*7c3d14c8STreehugger Robot# Standalone build system for CompilerRT is not yet ready.
6*7c3d14c8STreehugger Robot#
7*7c3d14c8STreehugger Robot# An important constraint of the build is that it only produces libraries
8*7c3d14c8STreehugger Robot# based on the ability of the host toolchain to target various platforms.
9*7c3d14c8STreehugger Robot
10*7c3d14c8STreehugger Robot# Check if compiler-rt is built as a standalone project.
11*7c3d14c8STreehugger Robotif (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
12*7c3d14c8STreehugger Robot  project(CompilerRT C CXX ASM)
13*7c3d14c8STreehugger Robot  set(COMPILER_RT_STANDALONE_BUILD TRUE)
14*7c3d14c8STreehugger Robotendif()
15*7c3d14c8STreehugger Robot
16*7c3d14c8STreehugger Robotcmake_minimum_required(VERSION 3.4.3)
17*7c3d14c8STreehugger Robot# FIXME:
18*7c3d14c8STreehugger Robot# The OLD behavior (pre 3.2) for this policy is to not set the value of the
19*7c3d14c8STreehugger Robot# CMAKE_EXE_LINKER_FLAGS variable in the generated test project. The NEW behavior
20*7c3d14c8STreehugger Robot# for this policy is to set the value of the CMAKE_EXE_LINKER_FLAGS variable
21*7c3d14c8STreehugger Robot# in the test project to the same as it is in the calling project. The new
22*7c3d14c8STreehugger Robot# behavior cause the compiler_rt test to fail during try_compile: see
23*7c3d14c8STreehugger Robot# projects/compiler-rt/cmake/Modules/CompilerRTUtils.cmake:121 such that
24*7c3d14c8STreehugger Robot# CAN_TARGET_${arch} is not set properly. This results in COMPILER_RT_SUPPORTED_ARCH
25*7c3d14c8STreehugger Robot# not being updated properly leading to poblems.
26*7c3d14c8STreehugger Robotcmake_policy(SET CMP0056 OLD)
27*7c3d14c8STreehugger Robot
28*7c3d14c8STreehugger Robot# Add path for custom compiler-rt modules.
29*7c3d14c8STreehugger Robotlist(INSERT CMAKE_MODULE_PATH 0
30*7c3d14c8STreehugger Robot  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
31*7c3d14c8STreehugger Robot  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
32*7c3d14c8STreehugger Robot  )
33*7c3d14c8STreehugger Robot
34*7c3d14c8STreehugger Robotinclude(base-config-ix)
35*7c3d14c8STreehugger Robot
36*7c3d14c8STreehugger Robotoption(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
37*7c3d14c8STreehugger Robotmark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
38*7c3d14c8STreehugger Robotoption(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
39*7c3d14c8STreehugger Robotmark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
40*7c3d14c8STreehugger Robot
41*7c3d14c8STreehugger Robotif (COMPILER_RT_STANDALONE_BUILD)
42*7c3d14c8STreehugger Robot  if (NOT LLVM_CONFIG_PATH)
43*7c3d14c8STreehugger Robot    find_program(LLVM_CONFIG_PATH "llvm-config"
44*7c3d14c8STreehugger Robot                 DOC "Path to llvm-config binary")
45*7c3d14c8STreehugger Robot    if (NOT LLVM_CONFIG_PATH)
46*7c3d14c8STreehugger Robot      message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH")
47*7c3d14c8STreehugger Robot    endif()
48*7c3d14c8STreehugger Robot  endif()
49*7c3d14c8STreehugger Robot  execute_process(
50*7c3d14c8STreehugger Robot    COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root"
51*7c3d14c8STreehugger Robot    RESULT_VARIABLE HAD_ERROR
52*7c3d14c8STreehugger Robot    OUTPUT_VARIABLE CONFIG_OUTPUT)
53*7c3d14c8STreehugger Robot  if (HAD_ERROR)
54*7c3d14c8STreehugger Robot    message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
55*7c3d14c8STreehugger Robot  endif()
56*7c3d14c8STreehugger Robot  string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT})
57*7c3d14c8STreehugger Robot  list(GET CONFIG_OUTPUT 0 LLVM_BINARY_DIR)
58*7c3d14c8STreehugger Robot  list(GET CONFIG_OUTPUT 1 LLVM_TOOLS_BINARY_DIR)
59*7c3d14c8STreehugger Robot  list(GET CONFIG_OUTPUT 2 LLVM_LIBRARY_DIR)
60*7c3d14c8STreehugger Robot  list(GET CONFIG_OUTPUT 3 LLVM_MAIN_SRC_DIR)
61*7c3d14c8STreehugger Robot
62*7c3d14c8STreehugger Robot  # Make use of LLVM CMake modules.
63*7c3d14c8STreehugger Robot  file(TO_CMAKE_PATH ${LLVM_BINARY_DIR} LLVM_BINARY_DIR_CMAKE_STYLE)
64*7c3d14c8STreehugger Robot  set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
65*7c3d14c8STreehugger Robot  list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
66*7c3d14c8STreehugger Robot  # Get some LLVM variables from LLVMConfig.
67*7c3d14c8STreehugger Robot  include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
68*7c3d14c8STreehugger Robot
69*7c3d14c8STreehugger Robot  set(LLVM_LIBRARY_OUTPUT_INTDIR
70*7c3d14c8STreehugger Robot    ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
71*7c3d14c8STreehugger Robot
72*7c3d14c8STreehugger Robot  # Find Python interpreter.
73*7c3d14c8STreehugger Robot  set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5)
74*7c3d14c8STreehugger Robot  include(FindPythonInterp)
75*7c3d14c8STreehugger Robot  if(NOT PYTHONINTERP_FOUND)
76*7c3d14c8STreehugger Robot    message(FATAL_ERROR "
77*7c3d14c8STreehugger Robot      Unable to find Python interpreter required testing. Please install Python
78*7c3d14c8STreehugger Robot      or specify the PYTHON_EXECUTABLE CMake variable.")
79*7c3d14c8STreehugger Robot  endif()
80*7c3d14c8STreehugger Robot
81*7c3d14c8STreehugger Robot  # Define default arguments to lit.
82*7c3d14c8STreehugger Robot  set(LIT_ARGS_DEFAULT "-sv")
83*7c3d14c8STreehugger Robot  if (MSVC OR XCODE)
84*7c3d14c8STreehugger Robot    set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
85*7c3d14c8STreehugger Robot  endif()
86*7c3d14c8STreehugger Robot  set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
87*7c3d14c8STreehugger Robotendif()
88*7c3d14c8STreehugger Robot
89*7c3d14c8STreehugger Robotset(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING
90*7c3d14c8STreehugger Robot    "Default triple for which compiler-rt runtimes will be built.")
91*7c3d14c8STreehugger Robotif(DEFINED COMPILER_RT_TEST_TARGET_TRIPLE)
92*7c3d14c8STreehugger Robot  # Backwards compatibility: this variable used to be called
93*7c3d14c8STreehugger Robot  # COMPILER_RT_TEST_TARGET_TRIPLE.
94*7c3d14c8STreehugger Robot  set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${COMPILER_RT_TEST_TARGET_TRIPLE})
95*7c3d14c8STreehugger Robotendif()
96*7c3d14c8STreehugger Robot
97*7c3d14c8STreehugger Robotstring(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
98*7c3d14c8STreehugger Robotlist(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH)
99*7c3d14c8STreehugger Robotlist(GET TARGET_TRIPLE_LIST 1 COMPILER_RT_DEFAULT_TARGET_OS)
100*7c3d14c8STreehugger Robotlist(GET TARGET_TRIPLE_LIST 2 COMPILER_RT_DEFAULT_TARGET_ABI)
101*7c3d14c8STreehugger Robot# Determine if test target triple is specified explicitly, and doesn't match the
102*7c3d14c8STreehugger Robot# default.
103*7c3d14c8STreehugger Robotif(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE)
104*7c3d14c8STreehugger Robot  set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE TRUE)
105*7c3d14c8STreehugger Robotelse()
106*7c3d14c8STreehugger Robot  set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE)
107*7c3d14c8STreehugger Robotendif()
108*7c3d14c8STreehugger Robotif ("${COMPILER_RT_DEFAULT_TARGET_ABI}" STREQUAL "androideabi")
109*7c3d14c8STreehugger Robot  set(ANDROID 1)
110*7c3d14c8STreehugger Robotendif()
111*7c3d14c8STreehugger Robotinclude(CompilerRTUtils)
112*7c3d14c8STreehugger Robot
113*7c3d14c8STreehugger Robotset(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
114*7c3d14c8STreehugger Robotset(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
115*7c3d14c8STreehugger Robot
116*7c3d14c8STreehugger Robot# We support running instrumented tests when we're not cross compiling
117*7c3d14c8STreehugger Robot# and target a UNIX-like system or Windows.
118*7c3d14c8STreehugger Robot# We can run tests on Android even when we are cross-compiling.
119*7c3d14c8STreehugger Robotif(("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND (UNIX OR WIN32)) OR ANDROID
120*7c3d14c8STreehugger Robot   OR COMPILER_RT_EMULATOR)
121*7c3d14c8STreehugger Robot  option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON)
122*7c3d14c8STreehugger Robotelse()
123*7c3d14c8STreehugger Robot  option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" OFF)
124*7c3d14c8STreehugger Robotendif()
125*7c3d14c8STreehugger Robot
126*7c3d14c8STreehugger Robotoption(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
127*7c3d14c8STreehugger Robotoption(COMPILER_RT_EXTERNALIZE_DEBUGINFO
128*7c3d14c8STreehugger Robot  "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
129*7c3d14c8STreehugger Robot# COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in.
130*7c3d14c8STreehugger Robotpythonize_bool(COMPILER_RT_DEBUG)
131*7c3d14c8STreehugger Robot
132*7c3d14c8STreehugger Robot#================================
133*7c3d14c8STreehugger Robot# Setup Compiler Flags
134*7c3d14c8STreehugger Robot#================================
135*7c3d14c8STreehugger Robot
136*7c3d14c8STreehugger Robotinclude(config-ix)
137*7c3d14c8STreehugger Robot
138*7c3d14c8STreehugger Robotif(MSVC)
139*7c3d14c8STreehugger Robot  # Override any existing /W flags with /W4. This is what LLVM does.  Failing to
140*7c3d14c8STreehugger Robot  # remove other /W[0-4] flags will result in a warning about overriding a
141*7c3d14c8STreehugger Robot  # previous flag.
142*7c3d14c8STreehugger Robot  if (COMPILER_RT_HAS_W4_FLAG)
143*7c3d14c8STreehugger Robot    string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
144*7c3d14c8STreehugger Robot    string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
145*7c3d14c8STreehugger Robot    append_string_if(COMPILER_RT_HAS_W4_FLAG /W4 CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
146*7c3d14c8STreehugger Robot  endif()
147*7c3d14c8STreehugger Robotelse()
148*7c3d14c8STreehugger Robot  append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
149*7c3d14c8STreehugger Robotendif()
150*7c3d14c8STreehugger Robotif(COMPILER_RT_ENABLE_WERROR)
151*7c3d14c8STreehugger Robot  append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
152*7c3d14c8STreehugger Robot  append_string_if(COMPILER_RT_HAS_WX_FLAG /WX CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
153*7c3d14c8STreehugger Robotendif()
154*7c3d14c8STreehugger Robot
155*7c3d14c8STreehugger Robotappend_string_if(COMPILER_RT_HAS_STD_CXX11_FLAG -std=c++11 CMAKE_CXX_FLAGS)
156*7c3d14c8STreehugger Robot
157*7c3d14c8STreehugger Robot# Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP.
158*7c3d14c8STreehugger Robotif(NOT COMPILER_RT_HAS_FUNC_SYMBOL)
159*7c3d14c8STreehugger Robot  add_definitions(-D__func__=__FUNCTION__)
160*7c3d14c8STreehugger Robotendif()
161*7c3d14c8STreehugger Robot
162*7c3d14c8STreehugger Robot# Provide some common commmandline flags for Sanitizer runtimes.
163*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS)
164*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS)
165*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS)
166*7c3d14c8STreehugger Robotif(NOT COMPILER_RT_DEBUG)
167*7c3d14c8STreehugger Robot  append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS)
168*7c3d14c8STreehugger Robotendif()
169*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS)
170*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS)
171*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS)
172*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS)
173*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
174*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections SANITIZER_COMMON_CFLAGS)
175*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
176*7c3d14c8STreehugger Robot
177*7c3d14c8STreehugger Robotif(MSVC)
178*7c3d14c8STreehugger Robot  # Replace the /M[DT][d] flags with /MT, and strip any definitions of _DEBUG,
179*7c3d14c8STreehugger Robot  # which cause definition mismatches at link time.
180*7c3d14c8STreehugger Robot  # FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
181*7c3d14c8STreehugger Robot  if(COMPILER_RT_HAS_MT_FLAG)
182*7c3d14c8STreehugger Robot    foreach(flag_var
183*7c3d14c8STreehugger Robot      CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
184*7c3d14c8STreehugger Robot      CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
185*7c3d14c8STreehugger Robot      CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
186*7c3d14c8STreehugger Robot      CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
187*7c3d14c8STreehugger Robot      string(REGEX REPLACE "/M[DT]d" "/MT" ${flag_var} "${${flag_var}}")
188*7c3d14c8STreehugger Robot      string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
189*7c3d14c8STreehugger Robot      string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
190*7c3d14c8STreehugger Robot    endforeach()
191*7c3d14c8STreehugger Robot  endif()
192*7c3d14c8STreehugger Robot  append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
193*7c3d14c8STreehugger Robot  append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)
194*7c3d14c8STreehugger Robot  # VS 2015 (version 1900) added support for thread safe static initialization.
195*7c3d14c8STreehugger Robot  # However, ASan interceptors run before CRT initialization, which causes the
196*7c3d14c8STreehugger Robot  # new thread safe code to crash. Disable this feature for now.
197*7c3d14c8STreehugger Robot  if (MSVC_VERSION GREATER 1899)
198*7c3d14c8STreehugger Robot    list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-)
199*7c3d14c8STreehugger Robot  endif()
200*7c3d14c8STreehugger Robotendif()
201*7c3d14c8STreehugger Robot
202*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS)
203*7c3d14c8STreehugger Robot
204*7c3d14c8STreehugger Robot# Build with optimization, unless we're in debug mode. If we're using MSVC,
205*7c3d14c8STreehugger Robot# always respect the optimization flags set by CMAKE_BUILD_TYPE instead.
206*7c3d14c8STreehugger Robotif(NOT COMPILER_RT_DEBUG AND NOT MSVC)
207*7c3d14c8STreehugger Robot  list(APPEND SANITIZER_COMMON_CFLAGS -O3)
208*7c3d14c8STreehugger Robotendif()
209*7c3d14c8STreehugger Robot
210*7c3d14c8STreehugger Robot# Determine if we should restrict stack frame sizes.
211*7c3d14c8STreehugger Robot# Stack frames on PowerPC and Mips and in debug biuld can be much larger than
212*7c3d14c8STreehugger Robot# anticipated.
213*7c3d14c8STreehugger Robot# FIXME: Fix all sanitizers and add -Wframe-larger-than to
214*7c3d14c8STreehugger Robot# SANITIZER_COMMON_FLAGS
215*7c3d14c8STreehugger Robotif(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG
216*7c3d14c8STreehugger Robot   AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips")
217*7c3d14c8STreehugger Robot  set(SANITIZER_LIMIT_FRAME_SIZE TRUE)
218*7c3d14c8STreehugger Robotelse()
219*7c3d14c8STreehugger Robot  set(SANITIZER_LIMIT_FRAME_SIZE FALSE)
220*7c3d14c8STreehugger Robotendif()
221*7c3d14c8STreehugger Robot
222*7c3d14c8STreehugger Robot# Build sanitizer runtimes with debug info.
223*7c3d14c8STreehugger Robotif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
224*7c3d14c8STreehugger Robot  list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
225*7c3d14c8STreehugger Robotelseif(COMPILER_RT_HAS_G_FLAG)
226*7c3d14c8STreehugger Robot  list(APPEND SANITIZER_COMMON_CFLAGS -g)
227*7c3d14c8STreehugger Robotelseif(COMPILER_RT_HAS_Zi_FLAG)
228*7c3d14c8STreehugger Robot  list(APPEND SANITIZER_COMMON_CFLAGS /Zi)
229*7c3d14c8STreehugger Robotendif()
230*7c3d14c8STreehugger Robot
231*7c3d14c8STreehugger Robot# Turn off several warnings.
232*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS)
233*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS)
234*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS)
235*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG -Wno-non-virtual-dtor SANITIZER_COMMON_CFLAGS)
236*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS)
237*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS)
238*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS)
239*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS)
240*7c3d14c8STreehugger Robotappend_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS)
241*7c3d14c8STreehugger Robot
242*7c3d14c8STreehugger Robot# Warnings to turn off for all libraries, not just sanitizers.
243*7c3d14c8STreehugger Robotappend_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
244*7c3d14c8STreehugger Robot
245*7c3d14c8STreehugger Robotif(APPLE AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
246*7c3d14c8STreehugger Robot  # Mac OS X prior to 10.9 had problems with exporting symbols from
247*7c3d14c8STreehugger Robot  # libc++/libc++abi.
248*7c3d14c8STreehugger Robot  set(SANITIZER_CAN_USE_CXXABI FALSE)
249*7c3d14c8STreehugger Robotelseif(MSVC)
250*7c3d14c8STreehugger Robot  set(SANITIZER_CAN_USE_CXXABI FALSE)
251*7c3d14c8STreehugger Robotelse()
252*7c3d14c8STreehugger Robot  set(SANITIZER_CAN_USE_CXXABI TRUE)
253*7c3d14c8STreehugger Robotendif()
254*7c3d14c8STreehugger Robotpythonize_bool(SANITIZER_CAN_USE_CXXABI)
255*7c3d14c8STreehugger Robot
256*7c3d14c8STreehugger Robotadd_subdirectory(include)
257*7c3d14c8STreehugger Robot
258*7c3d14c8STreehugger Robotset(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)
259*7c3d14c8STreehugger Robotif(EXISTS ${COMPILER_RT_LIBCXX_PATH}/)
260*7c3d14c8STreehugger Robot  set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE)
261*7c3d14c8STreehugger Robotelse()
262*7c3d14c8STreehugger Robot  set(COMPILER_RT_HAS_LIBCXX_SOURCES FALSE)
263*7c3d14c8STreehugger Robotendif()
264*7c3d14c8STreehugger Robot
265*7c3d14c8STreehugger Robotset(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
266*7c3d14c8STreehugger Robotif(EXISTS ${COMPILER_RT_LLD_PATH}/)
267*7c3d14c8STreehugger Robot  set(COMPILER_RT_HAS_LLD_SOURCES TRUE)
268*7c3d14c8STreehugger Robotelse()
269*7c3d14c8STreehugger Robot  set(COMPILER_RT_HAS_LLD_SOURCES FALSE)
270*7c3d14c8STreehugger Robotendif()
271*7c3d14c8STreehugger Robotpythonize_bool(COMPILER_RT_HAS_LLD_SOURCES)
272*7c3d14c8STreehugger Robot
273*7c3d14c8STreehugger Robotadd_subdirectory(lib)
274*7c3d14c8STreehugger Robot
275*7c3d14c8STreehugger Robotif(COMPILER_RT_INCLUDE_TESTS)
276*7c3d14c8STreehugger Robot  add_subdirectory(unittests)
277*7c3d14c8STreehugger Robot  add_subdirectory(test)
278*7c3d14c8STreehugger Robotendif()
279