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