CMakeLists.txt revision 62f294020ce5d60dc51883e7708a56247c366d14
1# Build for the AddressSanitizer runtime support library.
2
3set(ASAN_SOURCES
4  asan_allocator.cc
5  asan_globals.cc
6  asan_interceptors.cc
7  asan_linux.cc
8  asan_mac.cc
9  asan_malloc_linux.cc
10  asan_malloc_mac.cc
11  asan_malloc_win.cc
12  asan_new_delete.cc
13  asan_poisoning.cc
14  asan_posix.cc
15  asan_printf.cc
16  asan_rtl.cc
17  asan_stack.cc
18  asan_stats.cc
19  asan_thread.cc
20  asan_thread_registry.cc
21  asan_win.cc
22  )
23
24include_directories(..)
25
26set(ASAN_CFLAGS
27  -fPIC
28  -fno-exceptions
29  -funwind-tables
30  -fvisibility=hidden
31  )
32if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
33  list(APPEND ASAN_CFLAGS -Wno-variadic-macros)
34endif ()
35
36set(ASAN_COMMON_DEFINITIONS
37  ASAN_HAS_EXCEPTIONS=1
38  ASAN_NEEDS_SEGV=1
39  )
40
41if(CAN_TARGET_X86_64)
42  add_library(clang_rt.asan-x86_64 STATIC
43    ${ASAN_SOURCES}
44    $<TARGET_OBJECTS:RTInterception.x86_64>
45    $<TARGET_OBJECTS:RTSanitizerCommon.x86_64>
46    )
47  set_target_compile_flags(clang_rt.asan-x86_64
48    ${ASAN_CFLAGS}
49    ${TARGET_X86_64_CFLAGS}
50    )
51  set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY COMPILE_DEFINITIONS
52    ${ASAN_COMMON_DEFINITIONS})
53endif()
54if(CAN_TARGET_I386)
55  add_library(clang_rt.asan-i386 STATIC
56    ${ASAN_SOURCES}
57    $<TARGET_OBJECTS:RTInterception.i386>
58    $<TARGET_OBJECTS:RTSanitizerCommon.i386>
59    )
60  set_target_compile_flags(clang_rt.asan-i386
61    ${ASAN_CFLAGS}
62    ${TARGET_I386_CFLAGS}
63    )
64  set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY COMPILE_DEFINITIONS
65    ${ASAN_COMMON_DEFINITIONS})
66endif()
67
68if(LLVM_INCLUDE_TESTS)
69  add_subdirectory(tests)
70endif()
71