1 # CMake build for CompilerRT.
3 # An important constraint of the build is that it only produces libraries
4 # based on the ability of the host toolchain to target various platforms.
6 cmake_minimum_required(VERSION 3.13.4)
8 # Check if compiler-rt is built as a standalone project.
9 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
10 project(CompilerRT C CXX ASM)
11 set(COMPILER_RT_STANDALONE_BUILD TRUE)
12 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
13 if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
15 "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
16 "minimum version of CMake required to build LLVM will become 3.20.0, and "
17 "using an older CMake will become an error. Please upgrade your CMake to "
18 "at least 3.20.0 now to avoid issues in the future!")
22 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
24 # Add path for custom compiler-rt modules.
25 list(INSERT CMAKE_MODULE_PATH 0
26 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
27 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
28 "${LLVM_COMMON_CMAKE_UTILS}"
29 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
32 if(CMAKE_CONFIGURATION_TYPES)
33 set(CMAKE_CFG_RESOLVED_INTDIR "${CMAKE_CFG_INTDIR}/")
35 set(CMAKE_CFG_RESOLVED_INTDIR "")
38 include(SetPlatformToolchainTools)
39 include(base-config-ix)
40 include(CompilerRTUtils)
41 include(CMakeDependentOption)
43 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
44 mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
45 option(COMPILER_RT_DISABLE_AARCH64_FMV "Disable AArch64 Function Multi Versioning support" OFF)
46 mark_as_advanced(COMPILER_RT_DISABLE_AARCH64_FMV)
47 option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON)
48 mark_as_advanced(COMPILER_RT_BUILD_CRT)
49 option(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY "Use eh_frame in crtbegin.o/crtend.o" ON)
50 mark_as_advanced(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY)
51 option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
52 mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
53 option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
54 mark_as_advanced(COMPILER_RT_BUILD_XRAY)
55 option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
56 mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
57 option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
58 mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
59 option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON)
60 mark_as_advanced(COMPILER_RT_BUILD_MEMPROF)
61 option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
62 mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
63 option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON)
64 mark_as_advanced(COMPILER_RT_BUILD_ORC)
65 option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
66 mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
67 option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)
69 option(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH "Set custom sysroot for building SCUDO standalone" OFF)
70 mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
71 option(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED "Build SCUDO standalone for shared libraries" ON)
72 mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
73 option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
74 mark_as_advanced(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
77 set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
79 set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT ON)
81 set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ${COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT} CACHE BOOL "Enable libc interceptors in HWASan (testing mode)")
83 set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
84 "Build for a bare-metal target.")
86 if (COMPILER_RT_STANDALONE_BUILD)
87 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
88 set(CMAKE_CXX_STANDARD_REQUIRED YES)
89 set(CMAKE_CXX_EXTENSIONS NO)
91 if (NOT LLVM_RUNTIMES_BUILD)
94 if (TARGET intrinsics_gen)
95 # Loading the llvm config causes this target to be imported so place it
96 # under the appropriate folder in an IDE.
97 set_target_properties(intrinsics_gen PROPERTIES FOLDER "Compiler-RT Misc")
100 find_package(Python3 COMPONENTS Interpreter)
101 if(NOT Python3_Interpreter_FOUND)
102 message(WARNING "Python3 not found, using python2 as a fallback")
103 find_package(Python2 COMPONENTS Interpreter REQUIRED)
104 if(Python2_VERSION VERSION_LESS 2.7)
105 message(SEND_ERROR "Python 2.7 or newer is required")
108 # Treat python2 as python3
109 add_executable(Python3::Interpreter IMPORTED)
110 set_target_properties(Python3::Interpreter PROPERTIES
111 IMPORTED_LOCATION ${Python2_EXECUTABLE})
112 set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
115 # Ensure that fat libraries are built correctly on Darwin
120 # Define default arguments to lit.
121 set(LIT_ARGS_DEFAULT "-sv")
123 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
125 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
126 set(LLVM_LIT_OUTPUT_DIR "${COMPILER_RT_EXEC_OUTPUT_DIR}")
129 construct_compiler_rt_default_triple()
130 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*hf$")
131 if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^arm")
132 set(COMPILER_RT_DEFAULT_TARGET_ARCH "armhf")
133 CHECK_SYMBOL_EXISTS (__thumb__ "" COMPILER_RT_ARM_THUMB)
136 if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^mips")
137 CHECK_SYMBOL_EXISTS (_MIPS_ARCH_MIPS32R6 "" COMPILER_RT_MIPS32R6)
138 CHECK_SYMBOL_EXISTS (_MIPS_ARCH_MIPS64R6 "" COMPILER_RT_MIPS64R6)
139 CHECK_SYMBOL_EXISTS (__mips64 "" COMPILER_RT_MIPS_64)
140 CHECK_SYMBOL_EXISTS (__MIPSEL__ "" COMPILER_RT_MIPS_EL)
141 if ("${COMPILER_RT_MIPS_64}")
142 set(COMPILER_RT_DEFAULT_TARGET_ARCH "mips64")
144 set(COMPILER_RT_DEFAULT_TARGET_ARCH "mips")
146 if ("${COMPILER_RT_MIPS_EL}")
147 set(COMPILER_RT_DEFAULT_TARGET_ARCH "${COMPILER_RT_DEFAULT_TARGET_ARCH}el")
150 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")
152 string(REGEX MATCH "-target(=| +)[^ ]+android[a-z]*([0-9]+)" ANDROID_API_LEVEL "${CMAKE_C_FLAGS}")
153 set(ANDROID_API_LEVEL ${CMAKE_MATCH_2})
155 pythonize_bool(ANDROID)
157 set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
158 set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
160 pythonize_bool(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
162 # We support running instrumented tests when we're not cross-compiling
163 # and target a UNIX-like system or Windows.
164 # We can run tests on Android even when we are cross-compiling.
165 if((NOT "${CMAKE_CROSSCOMPILING}" AND (UNIX OR WIN32))
166 OR ANDROID OR COMPILER_RT_EMULATOR)
167 option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON)
169 option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" OFF)
172 option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
173 option(COMPILER_RT_EXTERNALIZE_DEBUGINFO
174 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
175 # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in.
176 pythonize_bool(COMPILER_RT_DEBUG)
178 option(COMPILER_RT_INTERCEPT_LIBDISPATCH
179 "Support interception of libdispatch (GCD). Requires '-fblocks'" OFF)
180 option(COMPILER_RT_LIBDISPATCH_INSTALL_PATH
181 "Specify if libdispatch is installed in a custom location" "")
182 if (COMPILER_RT_INTERCEPT_LIBDISPATCH AND NOT APPLE)
183 set(COMPILER_RT_LIBDISPATCH_CFLAGS -fblocks)
184 set(COMPILER_RT_TEST_LIBDISPATCH_CFLAGS)
185 if (COMPILER_RT_LIBDISPATCH_INSTALL_PATH)
186 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS
187 -I${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/include
188 -L${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib
189 -Wl,-rpath=${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib)
191 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS -lBlocksRuntime -ldispatch)
193 if (APPLE) # Always enable on Apple platforms.
194 set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON)
196 pythonize_bool(COMPILER_RT_INTERCEPT_LIBDISPATCH)
198 if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
199 # Mac OS X prior to 10.9 had problems with exporting symbols from
201 set(cxxabi_supported OFF)
203 set(cxxabi_supported ON)
206 option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON)
208 set(SANITIZER_CAN_USE_CXXABI OFF)
209 if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI)
210 set(SANITIZER_CAN_USE_CXXABI ON)
212 pythonize_bool(SANITIZER_CAN_USE_CXXABI)
214 macro(handle_default_cxx_lib var)
215 # Specifying -stdlib= in CMAKE_CXX_FLAGS overrides the defaults.
216 if (CMAKE_CXX_FLAGS MATCHES "-stdlib=([a-zA-Z+]*)")
217 set(${var}_LIBNAME "${CMAKE_MATCH_1}")
219 elseif (${var} STREQUAL "default")
220 if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
221 set(${var}_LIBNAME "libc++")
224 set(${var}_LIBNAME "libc++")
227 set(${var}_LIBNAME "libstdc++")
231 set(${var}_LIBNAME "${${var}}")
236 # This is either directly the C++ ABI library or the full C++ library
237 # which pulls in the ABI transitively.
238 # TODO: Mark this as internal flag, most users should use COMPILER_RT_CXX_LIBRARY.
239 set(SANITIZER_CXX_ABI "default" CACHE STRING
240 "Specify C++ ABI library to use.")
241 set(CXXABIS none default libstdc++ libc++ libcxxabi)
242 set_property(CACHE SANITIZER_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
243 handle_default_cxx_lib(SANITIZER_CXX_ABI)
245 # This needs to be a full C++ library for linking gtest and unit tests.
246 # TODO: Mark this as internal flag, most users should use COMPILER_RT_CXX_LIBRARY.
247 set(SANITIZER_TEST_CXX "default" CACHE STRING
248 "Specify C++ library to use for tests.")
249 set(CXXLIBS none default libstdc++ libc++)
250 set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS})
251 handle_default_cxx_lib(SANITIZER_TEST_CXX)
253 option(COMPILER_RT_USE_LLVM_UNWINDER "Use the LLVM unwinder." OFF)
254 cmake_dependent_option(COMPILER_RT_ENABLE_STATIC_UNWINDER
255 "Statically link the LLVM unwinder." OFF
256 "COMPILER_RT_USE_LLVM_UNWINDER" OFF)
258 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER OFF)
260 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
261 elseif (DEFINED LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_SHARED)
262 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
265 option(SANITIZER_USE_STATIC_LLVM_UNWINDER
266 "Use static LLVM unwinder." ${DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER})
267 pythonize_bool(SANITIZER_USE_STATIC_LLVM_UNWINDER)
269 set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI OFF)
270 if (DEFINED LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_SHARED)
271 set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI ON)
274 option(SANITIZER_USE_STATIC_CXX_ABI
275 "Use static libc++abi." ${DEFAULT_SANITIZER_USE_STATIC_CXX_ABI})
276 pythonize_bool(SANITIZER_USE_STATIC_CXX_ABI)
278 set(DEFAULT_SANITIZER_USE_STATIC_TEST_CXX OFF)
279 if (DEFINED LIBCXX_ENABLE_SHARED AND NOT LIBCXX_ENABLE_SHARED)
280 set(DEFAULT_SANITIZER_USE_STATIC_TEST_CXX ON)
283 option(SANITIZER_USE_STATIC_TEST_CXX
284 "Use static libc++ for tests." ${DEFAULT_SANITIZER_USE_STATIC_TEST_CXX})
285 pythonize_bool(SANITIZER_USE_STATIC_TEST_CXX)
287 set(COMPILER_RT_SUPPORTED_CXX_LIBRARIES none default libcxx)
288 set(COMPILER_RT_CXX_LIBRARY "default" CACHE STRING "Specify C++ library to use. Supported values are ${COMPILER_RT_SUPPORTED_CXX_LIBRARIES}.")
289 if (NOT "${COMPILER_RT_CXX_LIBRARY}" IN_LIST COMPILER_RT_SUPPORTED_CXX_LIBRARIES)
290 message(FATAL_ERROR "Unsupported C++ library: '${COMPILER_RT_CXX_LIBRARY}'. Supported values are ${COMPILER_RT_SUPPORTED_CXX_LIBRARIES}.")
292 cmake_dependent_option(COMPILER_RT_STATIC_CXX_LIBRARY
293 "Statically link the C++ library." OFF
294 "COMPILER_RT_CXX_LIBRARY" OFF)
296 set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY OFF)
298 set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY ON)
301 option(COMPILER_RT_USE_BUILTINS_LIBRARY
302 "Use compiler-rt builtins instead of libgcc" ${DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY})
306 #================================
307 # Setup Compiler Flags
308 #================================
310 # fcf-protection is a gcc/clang option for CET support on Linux platforms.
311 # We need to handle MSVC CET option on Windows platforms.
313 if (COMPILER_RT_ENABLE_CET AND NOT COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
314 message(FATAL_ERROR "Compiler used to build compiler-rt doesn't support CET!")
319 # Override any existing /W flags with /W4. This is what LLVM does. Failing to
320 # remove other /W[0-4] flags will result in a warning about overriding a
322 if (COMPILER_RT_HAS_W4_FLAG)
323 string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
324 string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
325 append_string_if(COMPILER_RT_HAS_W4_FLAG /W4 CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
328 append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
330 if(COMPILER_RT_ENABLE_WERROR)
331 append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
332 append_string_if(COMPILER_RT_HAS_WX_FLAG /WX CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
335 # Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP.
336 if(NOT COMPILER_RT_HAS_FUNC_SYMBOL)
337 add_definitions(-D__func__=__FUNCTION__)
340 # Provide some common commandline flags for Sanitizer runtimes.
341 if("${ANDROID_API_LEVEL}" GREATER_EQUAL 29)
342 list(APPEND SANITIZER_COMMON_CFLAGS -fno-emulated-tls)
343 string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " -fno-emulated-tls")
346 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS)
348 append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS)
349 append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS)
350 if(NOT COMPILER_RT_DEBUG AND NOT APPLE)
351 append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS)
353 append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS)
354 append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS)
355 append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS)
356 append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS)
357 if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
358 append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
360 append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
362 # By default do not instrument or use profdata for compiler-rt.
363 if(NOT COMPILER_RT_ENABLE_PGO)
364 if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
365 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-instr-use")
367 if(LLVM_BUILD_INSTRUMENTED MATCHES IR AND COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
368 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-generate")
369 elseif((LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE) AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
370 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-instr-generate")
371 if(LLVM_BUILD_INSTRUMENTED_COVERAGE AND COMPILER_RT_HAS_FNO_COVERAGE_MAPPING_FLAG)
372 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-coverage-mapping")
377 # The following is a workaround for powerpc64le. This is the only architecture
378 # that requires -fno-function-sections to work properly. If lacking, the ASan
379 # Linux test function-sections-are-bad.cpp fails with the following error:
380 # 'undefined symbol: __sanitizer_unaligned_load32'.
381 if(DEFINED TARGET_powerpc64le_CFLAGS)
382 if(CMAKE_CXX_COMPILER_ID MATCHES "XL")
383 append("-qnofuncsect" TARGET_powerpc64le_CFLAGS)
385 append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections TARGET_powerpc64le_CFLAGS)
389 # The following is a workaround for s390x. This avoids creation of "partial
390 # inline" function fragments when building the asan libraries with certain
391 # GCC versions. The presence of those fragments, in particular for the
392 # interceptors, changes backtraces seen in asan error cases, which causes
393 # testsuite failures.
394 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
395 append_list_if(COMPILER_RT_HAS_FNO_PARTIAL_INLINING_FLAG -fno-partial-inlining SANITIZER_COMMON_CFLAGS)
399 # Replace the /M[DT][d] flags with /MT, and strip any definitions of _DEBUG,
400 # which cause definition mismatches at link time.
401 # FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
402 if(COMPILER_RT_HAS_MT_FLAG)
404 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
405 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
406 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
407 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
408 string(REGEX REPLACE "/M[DT]d" "/MT" ${flag_var} "${${flag_var}}")
409 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
410 string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
413 append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
414 append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)
416 # Disable thread safe initialization for static locals. ASan shouldn't need
417 # it. Thread safe initialization assumes that the CRT has already been
418 # initialized, but ASan initializes before the CRT.
419 list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-)
422 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS)
424 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG -Wthread-safety THREAD_SAFETY_FLAGS)
425 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_REFERENCE_FLAG -Wthread-safety-reference THREAD_SAFETY_FLAGS)
426 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_BETA_FLAG -Wthread-safety-beta THREAD_SAFETY_FLAGS)
427 list(APPEND SANITIZER_COMMON_CFLAGS ${THREAD_SAFETY_FLAGS})
428 string(REPLACE ";" " " thread_safety_flags_space_sep "${THREAD_SAFETY_FLAGS}")
429 string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${thread_safety_flags_space_sep}")
431 # If we're using MSVC,
432 # always respect the optimization flags set by CMAKE_BUILD_TYPE instead.
435 # Build with optimization, unless we're in debug mode.
436 if(COMPILER_RT_DEBUG)
437 list(APPEND SANITIZER_COMMON_CFLAGS -O1)
439 list(APPEND SANITIZER_COMMON_CFLAGS -O3)
443 # Determine if we should restrict stack frame sizes.
444 # Stack frames on PowerPC, Mips, SystemZ and in debug build can be much larger than
446 # FIXME: Fix all sanitizers and add -Wframe-larger-than to
447 # SANITIZER_COMMON_FLAGS
448 if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG
449 AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips|s390x")
450 set(SANITIZER_LIMIT_FRAME_SIZE TRUE)
452 set(SANITIZER_LIMIT_FRAME_SIZE FALSE)
456 set(SANITIZER_USE_SYMBOLS TRUE)
458 set(SANITIZER_USE_SYMBOLS FALSE)
461 # Build sanitizer runtimes with debug info.
463 # Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
464 # warning from the MS linker complaining that it can't find the 'vc140.pdb'
465 # file used by our object library compilations.
466 list(APPEND SANITIZER_COMMON_CFLAGS /Z7)
467 foreach(var_to_update
469 CMAKE_CXX_FLAGS_DEBUG
470 CMAKE_CXX_FLAGS_RELWITHDEBINFO)
471 string(REGEX REPLACE "(^| )/Z[i7I]($| )" " /Z7 "
472 "${var_to_update}" "${${var_to_update}}")
475 # On Apple platforms use full debug info (i.e. not `-gline-tables-only`)
476 # for all build types so that the runtime can be debugged.
477 if(NOT COMPILER_RT_HAS_G_FLAG)
478 message(FATAL_ERROR "-g is not supported by host compiler")
480 list(APPEND SANITIZER_COMMON_CFLAGS -g)
481 elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
482 list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
483 elseif(COMPILER_RT_HAS_G_FLAG)
484 list(APPEND SANITIZER_COMMON_CFLAGS -g)
487 if(LLVM_ENABLE_MODULES)
488 # Sanitizers cannot be built with -fmodules. The interceptors intentionally
489 # don't include system headers, which is incompatible with modules.
490 list(APPEND SANITIZER_COMMON_CFLAGS -fno-modules)
493 # Turn off several warnings.
494 append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS)
495 append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS)
496 append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS)
497 # format-pedantic warns about passing T* for %p, which is not useful.
498 append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS)
499 append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS)
500 append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS)
501 append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS)
502 append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS)
504 append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS)
506 # When lsan scans the stack for detecting reachable pointers, it's possible for
507 # a leaked pointer, which was pushed to the stack on an earlier function call,
508 # to still exist on the stack when doing a leak check if that part of the stack
509 # was not overwritten. In particular, if there's any uninitialized data in the
510 # lsan runtime, and the SP we start from is sufficiently deep into the runtime,
511 # then a leaked pointer could be marked as reachable. Such instances could be
512 # mitigated by clobbering any uninitialized data. Note that this won't cover
513 # all possible uninitialized stack contents, such as those used for register
514 # spill slots, unused portions for alignment, or even local variables not
515 # yet in scope at a certain point in the function.
517 # Note that this type of issue was discovered with lsan, but can apply to other
519 append_list_if(COMPILER_RT_HAS_TRIVIAL_AUTO_INIT -ftrivial-auto-var-init=pattern SANITIZER_COMMON_CFLAGS)
521 # Set common link flags.
522 # TODO: We should consider using the same model as libc++, that is use either
523 # -nostdlib++ and --unwindlib=none if supported, or -nodefaultlibs otherwise.
524 append_list_if(C_SUPPORTS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS)
525 append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
527 # Only necessary for 32-bit SPARC. Solaris 11.2+ ld uses -z ignore/-z record
528 # natively, but supports --as-needed/--no-as-needed for GNU ld compatibility.
529 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
530 list(APPEND SANITIZER_COMMON_LINK_LIBS -Wl,--as-needed atomic -Wl,--no-as-needed)
533 if (COMPILER_RT_USE_BUILTINS_LIBRARY)
534 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
537 append_list_if(COMPILER_RT_HAS_GCC_LIB gcc SANITIZER_COMMON_LINK_LIBS)
539 append_list_if(COMPILER_RT_HAS_GCC_S_LIB gcc_s SANITIZER_COMMON_LINK_LIBS)
543 append_list_if(COMPILER_RT_HAS_LIBC c SANITIZER_COMMON_LINK_LIBS)
544 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
545 list(APPEND SANITIZER_COMMON_LINK_LIBS zircon)
548 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
549 set(SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT ON)
551 set(SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT OFF)
553 option(SANITIZER_NO_UNDEFINED_SYMBOLS "Report error on unresolved symbol references" ${SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT})
554 if (SANITIZER_NO_UNDEFINED_SYMBOLS)
555 list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs)
558 # TODO: COMPILER_RT_COMMON_CFLAGS and COMPILER_RT_COMMON_LINK_FLAGS are
559 # intended for use in non-sanitizer runtimes such as libFuzzer, profile or XRay,
560 # move these higher to include common flags, then derive SANITIZER_COMMON_CFLAGS
561 # and SANITIZER_COMMON_LINK_FLAGS from those and append sanitizer-specific flags.
562 set(COMPILER_RT_COMMON_CFLAGS ${SANITIZER_COMMON_CFLAGS})
563 set(COMPILER_RT_COMMON_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
565 # We don't use the C++ standard library, so avoid including it by mistake.
566 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ SANITIZER_COMMON_CFLAGS)
567 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SANITIZER_COMMON_LINK_FLAGS)
569 # Remove -stdlib= which is unused when passing -nostdinc++...
570 string(REGEX MATCHALL "-stdlib=[a-zA-Z+]*" stdlib_flag "${CMAKE_CXX_FLAGS}")
571 string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
573 # ...we need it to build some runtimes and tests so readd it where appropriate.
574 list(APPEND COMPILER_RT_COMMON_CFLAGS ${stdlib_flag})
575 list(APPEND COMPILER_RT_COMMON_LINK_FLAGS ${stdlib_flag})
577 # TODO: There's a lot of duplication across lib/*/tests/CMakeLists.txt files,
578 # move some of the common flags to COMPILER_RT_UNITTEST_CFLAGS.
580 # Unittests need access to C++ standard library.
581 string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${stdlib_flag}")
583 # When cross-compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help in compilation
584 # and linking of unittests.
585 string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
586 set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS})
588 if(COMPILER_RT_USE_LLVM_UNWINDER)
589 # We're linking directly against the libunwind that we're building so don't
590 # try to link in the toolchain's default libunwind which may be missing.
591 append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none COMPILER_RT_COMMON_LINK_FLAGS)
592 append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none COMPILER_RT_UNITTEST_LINK_FLAGS)
593 if (COMPILER_RT_ENABLE_STATIC_UNWINDER)
594 list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "$<TARGET_LINKER_FILE:unwind_static>")
596 list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:unwind_shared>,unwind_shared,unwind_static>>")
600 if (COMPILER_RT_CXX_LIBRARY STREQUAL "libcxx")
601 # We are using the in-tree libc++ so avoid including the default one.
602 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS)
603 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_COMMON_LINK_FLAGS)
604 # Use the in-tree libc++ through explicit include and library paths.
605 set(COMPILER_RT_CXX_CFLAGS "$<$<TARGET_EXISTS:cxx-headers>:$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>$<JOIN:$<TARGET_PROPERTY:cxx-headers,INTERFACE_INCLUDE_DIRECTORIES>,$<SEMICOLON>$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>>>")
606 if (COMPILER_RT_STATIC_CXX_LIBRARY)
607 set(COMPILER_RT_CXX_LINK_LIBS "$<TARGET_LINKER_FILE:cxx_static>")
609 set(COMPILER_RT_CXX_LINK_LIBS "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:cxx_shared>,cxx_shared,cxx_static>>")
611 elseif (COMPILER_RT_CXX_LIBRARY STREQUAL "none")
612 # We aren't using any C++ standard library so avoid including the default one.
613 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS)
614 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_COMMON_LINK_FLAGS)
616 # Nothing to be done for `default`.
619 if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++")
620 if (SANITIZER_CXX_ABI_INTREE)
621 # TODO: We don't need to add --unwindlib=none to SANITIZER_COMMON_LINK_FLAGS
622 # because we added -nodefaultlibs there earlier, and adding would result in
623 # a warning, but if we switch to -nostdlib++, we would need to add it here.
624 # append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SANITIZER_COMMON_LINK_FLAGS)
625 if(SANITIZER_USE_STATIC_CXX_ABI)
626 if(TARGET libcxx-abi-static)
627 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-static)
630 if(TARGET libcxx-abi-shared)
631 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-shared)
632 elseif(TARGET libcxx-abi-static)
633 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-static)
637 append_list_if(COMPILER_RT_HAS_LIBCXX c++ SANITIZER_CXX_ABI_LIBRARIES)
639 elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libcxxabi")
640 list(APPEND SANITIZER_CXX_ABI_LIBRARIES "c++abi")
641 elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libstdc++")
642 append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARIES)
645 if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++")
646 if (SANITIZER_TEST_CXX_INTREE)
647 list(APPEND SANITIZER_TEST_CXX_CFLAGS "$<$<TARGET_EXISTS:cxx-headers>:$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>$<JOIN:$<TARGET_PROPERTY:cxx-headers,INTERFACE_INCLUDE_DIRECTORIES>,$<SEMICOLON>$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>>>")
648 if (SANITIZER_USE_STATIC_TEST_CXX)
649 list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$<TARGET_LINKER_FILE:cxx_static>")
651 list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:cxx_shared>,cxx_shared,cxx_static>>")
653 # We are using the in tree libc++ so avoid including the default one.
654 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_UNITTEST_CFLAGS)
655 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_UNITTEST_LINK_FLAGS)
657 append_list_if(COMPILER_RT_HAS_LIBCXX -lc++ SANITIZER_TEST_CXX_LIBRARIES)
659 elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++")
660 append_list_if(COMPILER_RT_HAS_LIBSTDCXX -lstdc++ SANITIZER_TEST_CXX_LIBRARIES)
664 # FIXME: When compiler-rt is build using -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON, then
665 # The LLVM_THIRD_PARTY_DIR variable is not set.
666 if (NOT LLVM_THIRD_PARTY_DIR)
667 set(LLVM_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../third-party")
670 set(COMPILER_RT_GTEST_PATH ${LLVM_THIRD_PARTY_DIR}/unittest/googletest)
671 set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
672 set(COMPILER_RT_GTEST_CFLAGS
673 -DGTEST_NO_LLVM_SUPPORT=1
675 -I${COMPILER_RT_GTEST_PATH}/include
676 -I${COMPILER_RT_GTEST_PATH}
680 set(COMPILER_RT_GMOCK_PATH ${LLVM_THIRD_PARTY_DIR}/unittest/googlemock)
681 set(COMPILER_RT_GMOCK_SOURCE ${COMPILER_RT_GMOCK_PATH}/src/gmock-all.cc)
682 set(COMPILER_RT_GMOCK_CFLAGS
683 -DGTEST_NO_LLVM_SUPPORT=1
685 -I${COMPILER_RT_GMOCK_PATH}/include
686 -I${COMPILER_RT_GMOCK_PATH}
689 if(COMPILER_RT_HAS_G_FLAG)
690 list(APPEND COMPILER_RT_UNITTEST_CFLAGS -g)
692 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS)
693 append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS)
694 append_list_if(COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override COMPILER_RT_UNITTEST_CFLAGS)
697 # gtest use a lot of stuff marked as deprecated on Windows.
698 list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations)
701 # Warnings to turn off for all libraries, not just sanitizers.
702 append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
704 if (CMAKE_LINKER MATCHES "link.exe$")
705 # Silence MSVC linker warnings caused by empty object files. The
706 # sanitizer libraries intentionally use ifdefs that result in empty
707 # files, rather than skipping these files in the build system.
708 # Ideally, we would pass this flag only for the libraries that need
709 # it, but CMake doesn't seem to have a way to set linker flags for
710 # individual static libraries, so we enable the suppression flag for
711 # the whole compiler-rt project.
712 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221")
715 add_subdirectory(include)
717 option(COMPILER_RT_USE_LIBCXX
718 "Enable compiler-rt to use libc++ from the source tree" ON)
719 if(COMPILER_RT_USE_LIBCXX)
720 if(LLVM_ENABLE_PROJECTS_USED)
721 # Don't use libcxx if LLVM_ENABLE_PROJECTS does not enable it.
722 set(COMPILER_RT_LIBCXX_PATH ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
723 set(COMPILER_RT_LIBCXXABI_PATH ${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
725 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxx
726 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxx
727 ${LLVM_MAIN_SRC_DIR}/../libcxx
728 ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
729 if(IS_DIRECTORY ${path})
730 set(COMPILER_RT_LIBCXX_PATH ${path})
734 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi
735 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi
736 ${LLVM_MAIN_SRC_DIR}/../libcxxabi
737 ${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
738 if(IS_DIRECTORY ${path})
739 set(COMPILER_RT_LIBCXXABI_PATH ${path})
746 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
747 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
748 set(COMPILER_RT_HAS_LLD TRUE)
750 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/../lld)
751 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
752 set(COMPILER_RT_HAS_LLD TRUE)
757 set(COMPILER_RT_HAS_LLD TRUE)
758 set(COMPILER_RT_TEST_USE_LLD TRUE)
759 append_list_if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG -fuse-ld=lld SANITIZER_COMMON_LINK_FLAGS)
760 append_list_if(COMPILER_RT_HAS_LLD -fuse-ld=lld COMPILER_RT_UNITTEST_LINK_FLAGS)
762 pythonize_bool(COMPILER_RT_HAS_LLD)
763 pythonize_bool(COMPILER_RT_TEST_USE_LLD)
765 add_subdirectory(lib)
767 if(COMPILER_RT_INCLUDE_TESTS)
768 add_subdirectory(unittests)
769 add_subdirectory(test)
770 # Don't build llvm-lit for runtimes-build, it will clean up map_config.
771 if (COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
772 # If we have a valid source tree, generate llvm-lit into the bin directory.
773 # The user can still choose to have the check targets *use* a different lit
774 # by specifying -DLLVM_EXTERNAL_LIT, but we generate it regardless.
775 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
776 # Needed for lit support in standalone builds.
778 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
779 elseif(NOT EXISTS ${LLVM_EXTERNAL_LIT})
780 message(WARNING "Could not find LLVM source directory and LLVM_EXTERNAL_LIT does not"
781 "point to a valid file. You will not be able to run tests.")
786 add_subdirectory(tools)