annotate compiler-rt/CMakeLists.txt @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children 0572611fdcc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 # CMake build for CompilerRT.
anatofuz
parents:
diff changeset
2 #
anatofuz
parents:
diff changeset
3 # An important constraint of the build is that it only produces libraries
anatofuz
parents:
diff changeset
4 # based on the ability of the host toolchain to target various platforms.
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 cmake_minimum_required(VERSION 3.4.3)
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 if(POLICY CMP0075)
anatofuz
parents:
diff changeset
9 cmake_policy(SET CMP0075 NEW)
anatofuz
parents:
diff changeset
10 endif()
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 # Check if compiler-rt is built as a standalone project.
anatofuz
parents:
diff changeset
13 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
anatofuz
parents:
diff changeset
14 project(CompilerRT C CXX ASM)
anatofuz
parents:
diff changeset
15 set(COMPILER_RT_STANDALONE_BUILD TRUE)
anatofuz
parents:
diff changeset
16 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
anatofuz
parents:
diff changeset
17 endif()
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 # Add path for custom compiler-rt modules.
anatofuz
parents:
diff changeset
20 list(INSERT CMAKE_MODULE_PATH 0
anatofuz
parents:
diff changeset
21 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
anatofuz
parents:
diff changeset
22 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
anatofuz
parents:
diff changeset
23 )
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 if(CMAKE_CONFIGURATION_TYPES)
anatofuz
parents:
diff changeset
26 set(CMAKE_CFG_RESOLVED_INTDIR "${CMAKE_CFG_INTDIR}/")
anatofuz
parents:
diff changeset
27 else()
anatofuz
parents:
diff changeset
28 set(CMAKE_CFG_RESOLVED_INTDIR "")
anatofuz
parents:
diff changeset
29 endif()
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 include(base-config-ix)
anatofuz
parents:
diff changeset
32 include(CompilerRTUtils)
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
anatofuz
parents:
diff changeset
35 mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
anatofuz
parents:
diff changeset
36 option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON)
anatofuz
parents:
diff changeset
37 mark_as_advanced(COMPILER_RT_BUILD_CRT)
anatofuz
parents:
diff changeset
38 option(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY "Use eh_frame in crtbegin.o/crtend.o" ON)
anatofuz
parents:
diff changeset
39 mark_as_advanced(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY)
anatofuz
parents:
diff changeset
40 option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
anatofuz
parents:
diff changeset
41 mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
anatofuz
parents:
diff changeset
42 option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
anatofuz
parents:
diff changeset
43 mark_as_advanced(COMPILER_RT_BUILD_XRAY)
anatofuz
parents:
diff changeset
44 option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
anatofuz
parents:
diff changeset
45 mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
anatofuz
parents:
diff changeset
46 option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
anatofuz
parents:
diff changeset
47 mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
anatofuz
parents:
diff changeset
48 option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
anatofuz
parents:
diff changeset
49 mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 set(COMPILER_RT_ASAN_SHADOW_SCALE ""
anatofuz
parents:
diff changeset
52 CACHE STRING "Override the shadow scale to be used in ASan runtime")
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 if (NOT COMPILER_RT_ASAN_SHADOW_SCALE STREQUAL "")
anatofuz
parents:
diff changeset
55 # Check that the shadow scale value is valid.
anatofuz
parents:
diff changeset
56 if (NOT (COMPILER_RT_ASAN_SHADOW_SCALE GREATER -1 AND
anatofuz
parents:
diff changeset
57 COMPILER_RT_ASAN_SHADOW_SCALE LESS 8))
anatofuz
parents:
diff changeset
58 message(FATAL_ERROR "
anatofuz
parents:
diff changeset
59 Invalid ASan Shadow Scale '${COMPILER_RT_ASAN_SHADOW_SCALE}'.")
anatofuz
parents:
diff changeset
60 endif()
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 set(COMPILER_RT_ASAN_SHADOW_SCALE_LLVM_FLAG
anatofuz
parents:
diff changeset
63 -mllvm -asan-mapping-scale=${COMPILER_RT_ASAN_SHADOW_SCALE})
anatofuz
parents:
diff changeset
64 set(COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION
anatofuz
parents:
diff changeset
65 ASAN_SHADOW_SCALE=${COMPILER_RT_ASAN_SHADOW_SCALE})
anatofuz
parents:
diff changeset
66 set(COMPILER_RT_ASAN_SHADOW_SCALE_FLAG
anatofuz
parents:
diff changeset
67 -D${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
anatofuz
parents:
diff changeset
68 endif()
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ON CACHE BOOL
anatofuz
parents:
diff changeset
71 "Enable libc interceptors in HWASan (testing mode)")
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
anatofuz
parents:
diff changeset
74 "Build for a bare-metal target.")
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 if (COMPILER_RT_STANDALONE_BUILD)
anatofuz
parents:
diff changeset
77 load_llvm_config()
anatofuz
parents:
diff changeset
78 if (TARGET intrinsics_gen)
anatofuz
parents:
diff changeset
79 # Loading the llvm config causes this target to be imported so place it
anatofuz
parents:
diff changeset
80 # under the appropriate folder in an IDE.
anatofuz
parents:
diff changeset
81 set_target_properties(intrinsics_gen PROPERTIES FOLDER "Compiler-RT Misc")
anatofuz
parents:
diff changeset
82 endif()
anatofuz
parents:
diff changeset
83
anatofuz
parents:
diff changeset
84 # Find Python interpreter.
anatofuz
parents:
diff changeset
85 include(FindPythonInterp)
anatofuz
parents:
diff changeset
86 if(NOT PYTHONINTERP_FOUND)
anatofuz
parents:
diff changeset
87 message(FATAL_ERROR "
anatofuz
parents:
diff changeset
88 Unable to find Python interpreter required testing. Please install Python
anatofuz
parents:
diff changeset
89 or specify the PYTHON_EXECUTABLE CMake variable.")
anatofuz
parents:
diff changeset
90 endif()
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 # Ensure that fat libraries are built correctly on Darwin
anatofuz
parents:
diff changeset
93 if(CMAKE_HOST_APPLE AND APPLE)
anatofuz
parents:
diff changeset
94 include(UseLibtool)
anatofuz
parents:
diff changeset
95 endif()
anatofuz
parents:
diff changeset
96
anatofuz
parents:
diff changeset
97 # Define default arguments to lit.
anatofuz
parents:
diff changeset
98 set(LIT_ARGS_DEFAULT "-sv")
anatofuz
parents:
diff changeset
99 if (MSVC OR XCODE)
anatofuz
parents:
diff changeset
100 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
anatofuz
parents:
diff changeset
101 endif()
anatofuz
parents:
diff changeset
102 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
anatofuz
parents:
diff changeset
103 set(LLVM_LIT_OUTPUT_DIR "${COMPILER_RT_EXEC_OUTPUT_DIR}")
anatofuz
parents:
diff changeset
104 endif()
anatofuz
parents:
diff changeset
105
anatofuz
parents:
diff changeset
106 construct_compiler_rt_default_triple()
anatofuz
parents:
diff changeset
107 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*hf$")
anatofuz
parents:
diff changeset
108 if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^arm")
anatofuz
parents:
diff changeset
109 set(COMPILER_RT_DEFAULT_TARGET_ARCH "armhf")
anatofuz
parents:
diff changeset
110 endif()
anatofuz
parents:
diff changeset
111 endif()
anatofuz
parents:
diff changeset
112 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")
anatofuz
parents:
diff changeset
113 set(ANDROID 1)
anatofuz
parents:
diff changeset
114 endif()
anatofuz
parents:
diff changeset
115 pythonize_bool(ANDROID)
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 set(ANDROID_NDK_VERSION 18
anatofuz
parents:
diff changeset
118 CACHE STRING "Set this to the Android NDK version that you are using")
anatofuz
parents:
diff changeset
119
anatofuz
parents:
diff changeset
120 set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
anatofuz
parents:
diff changeset
121 set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
anatofuz
parents:
diff changeset
122
anatofuz
parents:
diff changeset
123 pythonize_bool(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
anatofuz
parents:
diff changeset
124
anatofuz
parents:
diff changeset
125 # We support running instrumented tests when we're not cross compiling
anatofuz
parents:
diff changeset
126 # and target a UNIX-like system or Windows.
anatofuz
parents:
diff changeset
127 # We can run tests on Android even when we are cross-compiling.
anatofuz
parents:
diff changeset
128 if(("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND (UNIX OR WIN32)) OR ANDROID
anatofuz
parents:
diff changeset
129 OR COMPILER_RT_EMULATOR)
anatofuz
parents:
diff changeset
130 option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON)
anatofuz
parents:
diff changeset
131 else()
anatofuz
parents:
diff changeset
132 option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" OFF)
anatofuz
parents:
diff changeset
133 endif()
anatofuz
parents:
diff changeset
134
anatofuz
parents:
diff changeset
135 option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
anatofuz
parents:
diff changeset
136 option(COMPILER_RT_EXTERNALIZE_DEBUGINFO
anatofuz
parents:
diff changeset
137 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
anatofuz
parents:
diff changeset
138 # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in.
anatofuz
parents:
diff changeset
139 pythonize_bool(COMPILER_RT_DEBUG)
anatofuz
parents:
diff changeset
140
anatofuz
parents:
diff changeset
141 option(COMPILER_RT_INTERCEPT_LIBDISPATCH
anatofuz
parents:
diff changeset
142 "Support interception of libdispatch (GCD). Requires '-fblocks'" OFF)
anatofuz
parents:
diff changeset
143 option(COMPILER_RT_LIBDISPATCH_INSTALL_PATH
anatofuz
parents:
diff changeset
144 "Specify if libdispatch is installed in a custom location" "")
anatofuz
parents:
diff changeset
145 if (COMPILER_RT_INTERCEPT_LIBDISPATCH AND NOT APPLE)
anatofuz
parents:
diff changeset
146 set(COMPILER_RT_LIBDISPATCH_CFLAGS -fblocks)
anatofuz
parents:
diff changeset
147 set(COMPILER_RT_TEST_LIBDISPATCH_CFLAGS)
anatofuz
parents:
diff changeset
148 if (COMPILER_RT_LIBDISPATCH_INSTALL_PATH)
anatofuz
parents:
diff changeset
149 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS
anatofuz
parents:
diff changeset
150 -I${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/include
anatofuz
parents:
diff changeset
151 -L${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib
anatofuz
parents:
diff changeset
152 -Wl,-rpath=${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib)
anatofuz
parents:
diff changeset
153 endif()
anatofuz
parents:
diff changeset
154 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS -lBlocksRuntime -ldispatch)
anatofuz
parents:
diff changeset
155 endif()
anatofuz
parents:
diff changeset
156 if (APPLE) # Always enable on Apple platforms.
anatofuz
parents:
diff changeset
157 set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON)
anatofuz
parents:
diff changeset
158 endif()
anatofuz
parents:
diff changeset
159 pythonize_bool(COMPILER_RT_INTERCEPT_LIBDISPATCH)
anatofuz
parents:
diff changeset
160
anatofuz
parents:
diff changeset
161 if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
anatofuz
parents:
diff changeset
162 # Mac OS X prior to 10.9 had problems with exporting symbols from
anatofuz
parents:
diff changeset
163 # libc++/libc++abi.
anatofuz
parents:
diff changeset
164 set(cxxabi_supported OFF)
anatofuz
parents:
diff changeset
165 else()
anatofuz
parents:
diff changeset
166 set(cxxabi_supported ON)
anatofuz
parents:
diff changeset
167 endif()
anatofuz
parents:
diff changeset
168
anatofuz
parents:
diff changeset
169 option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON)
anatofuz
parents:
diff changeset
170
anatofuz
parents:
diff changeset
171 set(SANITIZE_CAN_USE_CXXABI OFF)
anatofuz
parents:
diff changeset
172 if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI)
anatofuz
parents:
diff changeset
173 set(SANITIZER_CAN_USE_CXXABI ON)
anatofuz
parents:
diff changeset
174 endif()
anatofuz
parents:
diff changeset
175 pythonize_bool(SANITIZER_CAN_USE_CXXABI)
anatofuz
parents:
diff changeset
176
anatofuz
parents:
diff changeset
177 macro(handle_default_cxx_lib var)
anatofuz
parents:
diff changeset
178 if (${var} STREQUAL "default")
anatofuz
parents:
diff changeset
179 if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
anatofuz
parents:
diff changeset
180 set(${var}_LIBNAME "libc++")
anatofuz
parents:
diff changeset
181 set(${var}_SYSTEM 1)
anatofuz
parents:
diff changeset
182 elseif (FUCHSIA)
anatofuz
parents:
diff changeset
183 set(${var}_LIBNAME "libc++")
anatofuz
parents:
diff changeset
184 set(${var}_INTREE 1)
anatofuz
parents:
diff changeset
185 else()
anatofuz
parents:
diff changeset
186 set(${var}_LIBNAME "libstdc++")
anatofuz
parents:
diff changeset
187 set(${var}_SYSTEM 1)
anatofuz
parents:
diff changeset
188 endif()
anatofuz
parents:
diff changeset
189 else()
anatofuz
parents:
diff changeset
190 set(${var}_LIBNAME "${${var}}")
anatofuz
parents:
diff changeset
191 set(${var}_SYSTEM 1)
anatofuz
parents:
diff changeset
192 endif()
anatofuz
parents:
diff changeset
193 endmacro()
anatofuz
parents:
diff changeset
194
anatofuz
parents:
diff changeset
195 # This is either directly the C++ ABI library or the full C++ library
anatofuz
parents:
diff changeset
196 # which pulls in the ABI transitively.
anatofuz
parents:
diff changeset
197 set(SANITIZER_CXX_ABI "default" CACHE STRING
anatofuz
parents:
diff changeset
198 "Specify C++ ABI library to use.")
anatofuz
parents:
diff changeset
199 set(CXXABIS none default libstdc++ libc++ libcxxabi)
anatofuz
parents:
diff changeset
200 set_property(CACHE SANITIZER_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
anatofuz
parents:
diff changeset
201 handle_default_cxx_lib(SANITIZER_CXX_ABI)
anatofuz
parents:
diff changeset
202
anatofuz
parents:
diff changeset
203 # This needs to be a full C++ library for linking gtest and unit tests.
anatofuz
parents:
diff changeset
204 set(SANITIZER_TEST_CXX "default" CACHE STRING
anatofuz
parents:
diff changeset
205 "Specify C++ library to use for tests.")
anatofuz
parents:
diff changeset
206 set(CXXLIBS none default libstdc++ libc++)
anatofuz
parents:
diff changeset
207 set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS})
anatofuz
parents:
diff changeset
208 handle_default_cxx_lib(SANITIZER_TEST_CXX)
anatofuz
parents:
diff changeset
209
anatofuz
parents:
diff changeset
210 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER OFF)
anatofuz
parents:
diff changeset
211 if (FUCHSIA)
anatofuz
parents:
diff changeset
212 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
anatofuz
parents:
diff changeset
213 elseif (DEFINED LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_SHARED)
anatofuz
parents:
diff changeset
214 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
anatofuz
parents:
diff changeset
215 endif()
anatofuz
parents:
diff changeset
216
anatofuz
parents:
diff changeset
217 option(SANITIZER_USE_STATIC_LLVM_UNWINDER
anatofuz
parents:
diff changeset
218 "Use static LLVM unwinder." ${DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER})
anatofuz
parents:
diff changeset
219
anatofuz
parents:
diff changeset
220 set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI OFF)
anatofuz
parents:
diff changeset
221 if (DEFINED LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_SHARED)
anatofuz
parents:
diff changeset
222 set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI ON)
anatofuz
parents:
diff changeset
223 endif()
anatofuz
parents:
diff changeset
224
anatofuz
parents:
diff changeset
225 option(SANITIZER_USE_STATIC_CXX_ABI
anatofuz
parents:
diff changeset
226 "Use static libc++abi." ${DEFAULT_SANITIZER_USE_STATIC_CXX_ABI})
anatofuz
parents:
diff changeset
227
anatofuz
parents:
diff changeset
228 set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY OFF)
anatofuz
parents:
diff changeset
229 if (FUCHSIA)
anatofuz
parents:
diff changeset
230 set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY ON)
anatofuz
parents:
diff changeset
231 endif()
anatofuz
parents:
diff changeset
232
anatofuz
parents:
diff changeset
233 option(COMPILER_RT_USE_BUILTINS_LIBRARY
anatofuz
parents:
diff changeset
234 "Use compiler-rt builtins instead of libgcc" ${DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY})
anatofuz
parents:
diff changeset
235
anatofuz
parents:
diff changeset
236 include(config-ix)
anatofuz
parents:
diff changeset
237
anatofuz
parents:
diff changeset
238 #================================
anatofuz
parents:
diff changeset
239 # Setup Compiler Flags
anatofuz
parents:
diff changeset
240 #================================
anatofuz
parents:
diff changeset
241
anatofuz
parents:
diff changeset
242 if(MSVC)
anatofuz
parents:
diff changeset
243 # Override any existing /W flags with /W4. This is what LLVM does. Failing to
anatofuz
parents:
diff changeset
244 # remove other /W[0-4] flags will result in a warning about overriding a
anatofuz
parents:
diff changeset
245 # previous flag.
anatofuz
parents:
diff changeset
246 if (COMPILER_RT_HAS_W4_FLAG)
anatofuz
parents:
diff changeset
247 string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
anatofuz
parents:
diff changeset
248 string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
anatofuz
parents:
diff changeset
249 append_string_if(COMPILER_RT_HAS_W4_FLAG /W4 CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
250 endif()
anatofuz
parents:
diff changeset
251 else()
anatofuz
parents:
diff changeset
252 append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
253 endif()
anatofuz
parents:
diff changeset
254 if(COMPILER_RT_ENABLE_WERROR)
anatofuz
parents:
diff changeset
255 append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
256 append_string_if(COMPILER_RT_HAS_WX_FLAG /WX CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
257 endif()
anatofuz
parents:
diff changeset
258
anatofuz
parents:
diff changeset
259 append_string_if(COMPILER_RT_HAS_STD_CXX14_FLAG -std=c++14 CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
260
anatofuz
parents:
diff changeset
261 # Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP.
anatofuz
parents:
diff changeset
262 if(NOT COMPILER_RT_HAS_FUNC_SYMBOL)
anatofuz
parents:
diff changeset
263 add_definitions(-D__func__=__FUNCTION__)
anatofuz
parents:
diff changeset
264 endif()
anatofuz
parents:
diff changeset
265
anatofuz
parents:
diff changeset
266 # Provide some common commmandline flags for Sanitizer runtimes.
anatofuz
parents:
diff changeset
267 if(NOT WIN32)
anatofuz
parents:
diff changeset
268 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
269 endif()
anatofuz
parents:
diff changeset
270 append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
271 append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
272 if(NOT COMPILER_RT_DEBUG AND NOT APPLE)
anatofuz
parents:
diff changeset
273 append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
274 endif()
anatofuz
parents:
diff changeset
275 append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
276 append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
277 append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
278 append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
279 if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
anatofuz
parents:
diff changeset
280 append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
281 endif()
anatofuz
parents:
diff changeset
282 append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
283
anatofuz
parents:
diff changeset
284 # The following is a workaround for powerpc64le. This is the only architecture
anatofuz
parents:
diff changeset
285 # that requires -fno-function-sections to work properly. If lacking, the ASan
anatofuz
parents:
diff changeset
286 # Linux test function-sections-are-bad.cpp fails with the following error:
anatofuz
parents:
diff changeset
287 # 'undefined symbol: __sanitizer_unaligned_load32'.
anatofuz
parents:
diff changeset
288 if(DEFINED TARGET_powerpc64le_CFLAGS)
anatofuz
parents:
diff changeset
289 if(CMAKE_CXX_COMPILER_ID MATCHES "XL")
anatofuz
parents:
diff changeset
290 append("-qnofuncsect" TARGET_powerpc64le_CFLAGS)
anatofuz
parents:
diff changeset
291 else()
anatofuz
parents:
diff changeset
292 append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections TARGET_powerpc64le_CFLAGS)
anatofuz
parents:
diff changeset
293 endif()
anatofuz
parents:
diff changeset
294 endif()
anatofuz
parents:
diff changeset
295
anatofuz
parents:
diff changeset
296 # The following is a workaround for s390x. This avoids creation of "partial
anatofuz
parents:
diff changeset
297 # inline" function fragments when building the asan libraries with certain
anatofuz
parents:
diff changeset
298 # GCC versions. The presence of those fragments, in particular for the
anatofuz
parents:
diff changeset
299 # interceptors, changes backtraces seen in asan error cases, which causes
anatofuz
parents:
diff changeset
300 # testsuite failures.
anatofuz
parents:
diff changeset
301 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
anatofuz
parents:
diff changeset
302 append_list_if(COMPILER_RT_HAS_FNO_PARTIAL_INLINING_FLAG -fno-partial-inlining SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
303 endif()
anatofuz
parents:
diff changeset
304
anatofuz
parents:
diff changeset
305 if(MSVC)
anatofuz
parents:
diff changeset
306 # Replace the /M[DT][d] flags with /MT, and strip any definitions of _DEBUG,
anatofuz
parents:
diff changeset
307 # which cause definition mismatches at link time.
anatofuz
parents:
diff changeset
308 # FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
anatofuz
parents:
diff changeset
309 if(COMPILER_RT_HAS_MT_FLAG)
anatofuz
parents:
diff changeset
310 foreach(flag_var
anatofuz
parents:
diff changeset
311 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
anatofuz
parents:
diff changeset
312 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
anatofuz
parents:
diff changeset
313 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
anatofuz
parents:
diff changeset
314 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
anatofuz
parents:
diff changeset
315 string(REGEX REPLACE "/M[DT]d" "/MT" ${flag_var} "${${flag_var}}")
anatofuz
parents:
diff changeset
316 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
anatofuz
parents:
diff changeset
317 string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
anatofuz
parents:
diff changeset
318 endforeach()
anatofuz
parents:
diff changeset
319 endif()
anatofuz
parents:
diff changeset
320 append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
321 append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
322
anatofuz
parents:
diff changeset
323 # Disable thread safe initialization for static locals. ASan shouldn't need
anatofuz
parents:
diff changeset
324 # it. Thread safe initialization assumes that the CRT has already been
anatofuz
parents:
diff changeset
325 # initialized, but ASan initializes before the CRT.
anatofuz
parents:
diff changeset
326 list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-)
anatofuz
parents:
diff changeset
327 endif()
anatofuz
parents:
diff changeset
328
anatofuz
parents:
diff changeset
329 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
330
anatofuz
parents:
diff changeset
331 # If we're using MSVC,
anatofuz
parents:
diff changeset
332 # always respect the optimization flags set by CMAKE_BUILD_TYPE instead.
anatofuz
parents:
diff changeset
333 if (NOT MSVC)
anatofuz
parents:
diff changeset
334
anatofuz
parents:
diff changeset
335 # Build with optimization, unless we're in debug mode.
anatofuz
parents:
diff changeset
336 if(COMPILER_RT_DEBUG)
anatofuz
parents:
diff changeset
337 list(APPEND SANITIZER_COMMON_CFLAGS -O0)
anatofuz
parents:
diff changeset
338 else()
anatofuz
parents:
diff changeset
339 list(APPEND SANITIZER_COMMON_CFLAGS -O3)
anatofuz
parents:
diff changeset
340 endif()
anatofuz
parents:
diff changeset
341 endif()
anatofuz
parents:
diff changeset
342
anatofuz
parents:
diff changeset
343 # Determine if we should restrict stack frame sizes.
anatofuz
parents:
diff changeset
344 # Stack frames on PowerPC, Mips, SystemZ and in debug build can be much larger than
anatofuz
parents:
diff changeset
345 # anticipated.
anatofuz
parents:
diff changeset
346 # FIXME: Fix all sanitizers and add -Wframe-larger-than to
anatofuz
parents:
diff changeset
347 # SANITIZER_COMMON_FLAGS
anatofuz
parents:
diff changeset
348 if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG
anatofuz
parents:
diff changeset
349 AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips|s390x")
anatofuz
parents:
diff changeset
350 set(SANITIZER_LIMIT_FRAME_SIZE TRUE)
anatofuz
parents:
diff changeset
351 else()
anatofuz
parents:
diff changeset
352 set(SANITIZER_LIMIT_FRAME_SIZE FALSE)
anatofuz
parents:
diff changeset
353 endif()
anatofuz
parents:
diff changeset
354
anatofuz
parents:
diff changeset
355 if(FUCHSIA OR UNIX)
anatofuz
parents:
diff changeset
356 set(SANITIZER_USE_SYMBOLS TRUE)
anatofuz
parents:
diff changeset
357 else()
anatofuz
parents:
diff changeset
358 set(SANITIZER_USE_SYMBOLS FALSE)
anatofuz
parents:
diff changeset
359 endif()
anatofuz
parents:
diff changeset
360
anatofuz
parents:
diff changeset
361 # Build sanitizer runtimes with debug info.
anatofuz
parents:
diff changeset
362 if(MSVC)
anatofuz
parents:
diff changeset
363 # Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
anatofuz
parents:
diff changeset
364 # warning from the MS linker complaining that it can't find the 'vc140.pdb'
anatofuz
parents:
diff changeset
365 # file used by our object library compilations.
anatofuz
parents:
diff changeset
366 list(APPEND SANITIZER_COMMON_CFLAGS /Z7)
anatofuz
parents:
diff changeset
367 foreach(var_to_update
anatofuz
parents:
diff changeset
368 CMAKE_CXX_FLAGS
anatofuz
parents:
diff changeset
369 CMAKE_CXX_FLAGS_DEBUG
anatofuz
parents:
diff changeset
370 CMAKE_CXX_FLAGS_RELWITHDEBINFO)
anatofuz
parents:
diff changeset
371 string(REGEX REPLACE "(^| )/Z[i7I]($| )" " /Z7 "
anatofuz
parents:
diff changeset
372 "${var_to_update}" "${${var_to_update}}")
anatofuz
parents:
diff changeset
373 endforeach()
anatofuz
parents:
diff changeset
374 elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
anatofuz
parents:
diff changeset
375 list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
anatofuz
parents:
diff changeset
376 elseif(COMPILER_RT_HAS_G_FLAG)
anatofuz
parents:
diff changeset
377 list(APPEND SANITIZER_COMMON_CFLAGS -g)
anatofuz
parents:
diff changeset
378 endif()
anatofuz
parents:
diff changeset
379
anatofuz
parents:
diff changeset
380 if(LLVM_ENABLE_MODULES)
anatofuz
parents:
diff changeset
381 # Sanitizers cannot be built with -fmodules. The interceptors intentionally
anatofuz
parents:
diff changeset
382 # don't include system headers, which is incompatible with modules.
anatofuz
parents:
diff changeset
383 list(APPEND SANITIZER_COMMON_CFLAGS -fno-modules)
anatofuz
parents:
diff changeset
384 endif()
anatofuz
parents:
diff changeset
385
anatofuz
parents:
diff changeset
386 # Turn off several warnings.
anatofuz
parents:
diff changeset
387 append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
388 append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
389 append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
390 append_list_if(COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG -Wno-non-virtual-dtor SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
391 append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
392 append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
393 append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
394 append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
395 append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
396
anatofuz
parents:
diff changeset
397 append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
398
anatofuz
parents:
diff changeset
399 # Set common link flags.
anatofuz
parents:
diff changeset
400 append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS)
anatofuz
parents:
diff changeset
401 append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
anatofuz
parents:
diff changeset
402
anatofuz
parents:
diff changeset
403 if (COMPILER_RT_USE_BUILTINS_LIBRARY)
anatofuz
parents:
diff changeset
404 list(APPEND SANITIZER_COMMON_LINK_LIBS ${COMPILER_RT_BUILTINS_LIBRARY})
anatofuz
parents:
diff changeset
405 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
anatofuz
parents:
diff changeset
406 else()
anatofuz
parents:
diff changeset
407 if (ANDROID)
anatofuz
parents:
diff changeset
408 append_list_if(COMPILER_RT_HAS_GCC_LIB gcc SANITIZER_COMMON_LINK_LIBS)
anatofuz
parents:
diff changeset
409 else()
anatofuz
parents:
diff changeset
410 append_list_if(COMPILER_RT_HAS_GCC_S_LIB gcc_s SANITIZER_COMMON_LINK_LIBS)
anatofuz
parents:
diff changeset
411 endif()
anatofuz
parents:
diff changeset
412 endif()
anatofuz
parents:
diff changeset
413
anatofuz
parents:
diff changeset
414 append_list_if(COMPILER_RT_HAS_LIBC c SANITIZER_COMMON_LINK_LIBS)
anatofuz
parents:
diff changeset
415
anatofuz
parents:
diff changeset
416 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
anatofuz
parents:
diff changeset
417 list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
anatofuz
parents:
diff changeset
418 list(APPEND SANITIZER_COMMON_LINK_LIBS zircon)
anatofuz
parents:
diff changeset
419 endif()
anatofuz
parents:
diff changeset
420
anatofuz
parents:
diff changeset
421 macro(append_libcxx_libs var)
anatofuz
parents:
diff changeset
422 if (${var}_INTREE)
anatofuz
parents:
diff changeset
423 if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND))
anatofuz
parents:
diff changeset
424 list(APPEND ${var}_LIBRARIES unwind_static)
anatofuz
parents:
diff changeset
425 elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)
anatofuz
parents:
diff changeset
426 list(APPEND ${var}_LIBRARIES unwind_shared)
anatofuz
parents:
diff changeset
427 endif()
anatofuz
parents:
diff changeset
428
anatofuz
parents:
diff changeset
429 if (SANITIZER_USE_STATIC_CXX_ABI AND (TARGET cxxabi_static OR HAVE_LIBCXXABI))
anatofuz
parents:
diff changeset
430 list(APPEND ${var}_LIBRARIES cxxabi_static)
anatofuz
parents:
diff changeset
431 elseif (TARGET cxxabi_shared OR HAVE_LIBCXXABI)
anatofuz
parents:
diff changeset
432 list(APPEND ${var}_LIBRARIES cxxabi_shared)
anatofuz
parents:
diff changeset
433 endif()
anatofuz
parents:
diff changeset
434 else()
anatofuz
parents:
diff changeset
435 append_list_if(COMPILER_RT_HAS_LIBCXX c++ ${var}_LIBRARIES)
anatofuz
parents:
diff changeset
436 endif()
anatofuz
parents:
diff changeset
437 endmacro()
anatofuz
parents:
diff changeset
438
anatofuz
parents:
diff changeset
439 if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++")
anatofuz
parents:
diff changeset
440 append_libcxx_libs(SANITIZER_CXX_ABI)
anatofuz
parents:
diff changeset
441 elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libcxxabi")
anatofuz
parents:
diff changeset
442 list(APPEND SANITIZER_CXX_ABI_LIBRARIES "c++abi")
anatofuz
parents:
diff changeset
443 elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libstdc++")
anatofuz
parents:
diff changeset
444 append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARIES)
anatofuz
parents:
diff changeset
445 endif()
anatofuz
parents:
diff changeset
446
anatofuz
parents:
diff changeset
447 if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++")
anatofuz
parents:
diff changeset
448 append_libcxx_libs(SANITIZER_TEST_CXX)
anatofuz
parents:
diff changeset
449 elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++")
anatofuz
parents:
diff changeset
450 append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_TEST_CXX_LIBRARIES)
anatofuz
parents:
diff changeset
451 endif()
anatofuz
parents:
diff changeset
452
anatofuz
parents:
diff changeset
453 # Warnings to turn off for all libraries, not just sanitizers.
anatofuz
parents:
diff changeset
454 append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
455
anatofuz
parents:
diff changeset
456 if (CMAKE_LINKER MATCHES "link.exe$")
anatofuz
parents:
diff changeset
457 # Silence MSVC linker warnings caused by empty object files. The
anatofuz
parents:
diff changeset
458 # sanitizer libraries intentionally use ifdefs that result in empty
anatofuz
parents:
diff changeset
459 # files, rather than skipping these files in the build system.
anatofuz
parents:
diff changeset
460 # Ideally, we would pass this flag only for the libraries that need
anatofuz
parents:
diff changeset
461 # it, but CMake doesn't seem to have a way to set linker flags for
anatofuz
parents:
diff changeset
462 # individual static libraries, so we enable the suppression flag for
anatofuz
parents:
diff changeset
463 # the whole compiler-rt project.
anatofuz
parents:
diff changeset
464 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221")
anatofuz
parents:
diff changeset
465 endif()
anatofuz
parents:
diff changeset
466
anatofuz
parents:
diff changeset
467 add_subdirectory(include)
anatofuz
parents:
diff changeset
468
anatofuz
parents:
diff changeset
469 option(COMPILER_RT_USE_LIBCXX
anatofuz
parents:
diff changeset
470 "Enable compiler-rt to use libc++ from the source tree" ON)
anatofuz
parents:
diff changeset
471 if(COMPILER_RT_USE_LIBCXX)
anatofuz
parents:
diff changeset
472 if(LLVM_ENABLE_PROJECTS_USED)
anatofuz
parents:
diff changeset
473 # Don't use libcxx if LLVM_ENABLE_PROJECTS does not enable it.
anatofuz
parents:
diff changeset
474 set(COMPILER_RT_LIBCXX_PATH ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
anatofuz
parents:
diff changeset
475 set(COMPILER_RT_LIBCXXABI_PATH ${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
anatofuz
parents:
diff changeset
476 else()
anatofuz
parents:
diff changeset
477 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxx
anatofuz
parents:
diff changeset
478 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxx
anatofuz
parents:
diff changeset
479 ${LLVM_MAIN_SRC_DIR}/../libcxx
anatofuz
parents:
diff changeset
480 ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
anatofuz
parents:
diff changeset
481 if(IS_DIRECTORY ${path})
anatofuz
parents:
diff changeset
482 set(COMPILER_RT_LIBCXX_PATH ${path})
anatofuz
parents:
diff changeset
483 break()
anatofuz
parents:
diff changeset
484 endif()
anatofuz
parents:
diff changeset
485 endforeach()
anatofuz
parents:
diff changeset
486 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi
anatofuz
parents:
diff changeset
487 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi
anatofuz
parents:
diff changeset
488 ${LLVM_MAIN_SRC_DIR}/../libcxxabi
anatofuz
parents:
diff changeset
489 ${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
anatofuz
parents:
diff changeset
490 if(IS_DIRECTORY ${path})
anatofuz
parents:
diff changeset
491 set(COMPILER_RT_LIBCXXABI_PATH ${path})
anatofuz
parents:
diff changeset
492 break()
anatofuz
parents:
diff changeset
493 endif()
anatofuz
parents:
diff changeset
494 endforeach()
anatofuz
parents:
diff changeset
495 endif()
anatofuz
parents:
diff changeset
496 endif()
anatofuz
parents:
diff changeset
497
anatofuz
parents:
diff changeset
498 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
anatofuz
parents:
diff changeset
499 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
anatofuz
parents:
diff changeset
500 set(COMPILER_RT_HAS_LLD TRUE)
anatofuz
parents:
diff changeset
501 else()
anatofuz
parents:
diff changeset
502 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/../lld)
anatofuz
parents:
diff changeset
503 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
anatofuz
parents:
diff changeset
504 set(COMPILER_RT_HAS_LLD TRUE)
anatofuz
parents:
diff changeset
505 else()
anatofuz
parents:
diff changeset
506 set(COMPILER_RT_HAS_LLD ${COMPILER_RT_HAS_FUSE_LD_LLD_FLAG})
anatofuz
parents:
diff changeset
507 endif()
anatofuz
parents:
diff changeset
508 endif()
anatofuz
parents:
diff changeset
509 pythonize_bool(COMPILER_RT_HAS_LLD)
anatofuz
parents:
diff changeset
510
anatofuz
parents:
diff changeset
511 add_subdirectory(lib)
anatofuz
parents:
diff changeset
512
anatofuz
parents:
diff changeset
513 if(COMPILER_RT_INCLUDE_TESTS)
anatofuz
parents:
diff changeset
514 add_subdirectory(unittests)
anatofuz
parents:
diff changeset
515 add_subdirectory(test)
anatofuz
parents:
diff changeset
516 if (COMPILER_RT_STANDALONE_BUILD)
anatofuz
parents:
diff changeset
517 # If we have a valid source tree, generate llvm-lit into the bin directory.
anatofuz
parents:
diff changeset
518 # The user can still choose to have the check targets *use* a different lit
anatofuz
parents:
diff changeset
519 # by specifying -DLLVM_EXTERNAL_LIT, but we generate it regardless.
anatofuz
parents:
diff changeset
520 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
anatofuz
parents:
diff changeset
521 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
anatofuz
parents:
diff changeset
522 elseif(NOT EXISTS ${LLVM_EXTERNAL_LIT})
anatofuz
parents:
diff changeset
523 message(WARNING "Could not find LLVM source directory and LLVM_EXTERNAL_LIT does not"
anatofuz
parents:
diff changeset
524 "point to a valid file. You will not be able to run tests.")
anatofuz
parents:
diff changeset
525 endif()
anatofuz
parents:
diff changeset
526 endif()
anatofuz
parents:
diff changeset
527 endif()
anatofuz
parents:
diff changeset
528
anatofuz
parents:
diff changeset
529 add_subdirectory(tools)