xref: /llvm-project/compiler-rt/lib/CMakeLists.txt (revision e3389365b5d62bc9781dc9a23b14d72e333018d7)
1# First, add the subdirectories which contain feature-based runtime libraries
2# and several convenience helper libraries.
3
4include(AddCompilerRT)
5include(SanitizerUtils)
6
7# Hoist the building of sanitizer_common on whether we're building either the
8# sanitizers or xray (or both).
9#
10#TODO: Refactor sanitizer_common into smaller pieces (e.g. flag parsing, utils).
11if (COMPILER_RT_HAS_SANITIZER_COMMON AND
12    (COMPILER_RT_BUILD_SANITIZERS OR COMPILER_RT_BUILD_XRAY OR COMPILER_RT_BUILD_MEMPROF OR COMPILER_RT_BUILD_CTX_PROFILE))
13  add_subdirectory(sanitizer_common)
14endif()
15
16if(COMPILER_RT_BUILD_BUILTINS)
17  add_subdirectory(builtins)
18endif()
19
20function(compiler_rt_build_runtime runtime)
21  string(TOUPPER ${runtime} runtime_uppercase)
22  if(COMPILER_RT_HAS_${runtime_uppercase})
23    if(${runtime} STREQUAL tsan)
24      add_subdirectory(tsan/dd)
25    endif()
26    if(${runtime} STREQUAL scudo_standalone)
27      add_subdirectory(scudo/standalone)
28    else()
29      add_subdirectory(${runtime})
30    endif()
31  endif()
32endfunction()
33
34if(COMPILER_RT_BUILD_SANITIZERS OR COMPILER_RT_BUILD_MEMPROF)
35  compiler_rt_build_runtime(interception)
36endif()
37
38if(COMPILER_RT_BUILD_SANITIZERS)
39  if(COMPILER_RT_HAS_SANITIZER_COMMON)
40    add_subdirectory(stats)
41    # Contains RTLSanCommon used even without COMPILER_RT_HAS_LSAN.
42    add_subdirectory(lsan)
43    # Contains RTUbsan used even without COMPILER_RT_HAS_UBSAN.
44    add_subdirectory(ubsan)
45  endif()
46
47  foreach(sanitizer ${COMPILER_RT_SANITIZERS_TO_BUILD})
48    compiler_rt_build_runtime(${sanitizer})
49  endforeach()
50endif()
51
52if(COMPILER_RT_BUILD_PROFILE)
53  compiler_rt_build_runtime(profile)
54endif()
55
56if(COMPILER_RT_BUILD_CTX_PROFILE)
57  compiler_rt_build_runtime(ctx_profile)
58endif()
59
60if(COMPILER_RT_BUILD_XRAY)
61  compiler_rt_build_runtime(xray)
62endif()
63
64if(COMPILER_RT_BUILD_LIBFUZZER)
65  compiler_rt_build_runtime(fuzzer)
66endif()
67
68if(COMPILER_RT_BUILD_MEMPROF AND COMPILER_RT_HAS_SANITIZER_COMMON)
69  compiler_rt_build_runtime(memprof)
70endif()
71
72if(COMPILER_RT_BUILD_ORC)
73  compiler_rt_build_runtime(orc)
74endif()
75
76# It doesn't normally make sense to build runtimes when a sanitizer is enabled,
77# so we don't add_subdirectory the runtimes in that case. However, the opposite
78# is true for fuzzers that exercise parts of the runtime. So we add the fuzzer
79# directories explicitly here.
80add_subdirectory(scudo/standalone/fuzz)
81