CMakeLists.txt revision 1e2525d0ec9ac64e583b57316ea30cecce591fb1
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_report.cc 17 asan_rtl.cc 18 asan_stack.cc 19 asan_stats.cc 20 asan_thread.cc 21 asan_thread_registry.cc 22 asan_win.cc 23 ) 24 25set(ASAN_DYLIB_SOURCES 26 ${ASAN_SOURCES} 27 dynamic/asan_interceptors_dynamic.cc 28 ) 29 30include_directories(..) 31 32set(ASAN_CFLAGS 33 -fPIC 34 -fno-exceptions 35 -funwind-tables 36 -fvisibility=hidden 37 -fno-builtin 38 -fomit-frame-pointer 39 -O3 40 ) 41 42set(ASAN_DYLIB_DEFINITIONS 43 ${ASAN_COMMON_DEFINITIONS} 44 MAC_INTERPOSE_FUNCTIONS=1 45 ) 46 47if (SUPPORTS_NO_VARIADIC_MACROS_FLAG) 48 list(APPEND ASAN_CFLAGS -Wno-variadic-macros) 49endif () 50 51if (APPLE) 52 list(APPEND ASAN_CFLAGS -mmacosx-version-min=10.5) 53endif() 54 55set(ASAN_COMMON_DEFINITIONS 56 ASAN_HAS_EXCEPTIONS=1 57 ASAN_NEEDS_SEGV=1 58 ) 59 60set(ASAN_RUNTIME_LIBRARIES) 61if(APPLE) 62 # Build universal binary on APPLE. 63 add_library(clang_rt.asan_osx STATIC 64 ${ASAN_SOURCES} 65 $<TARGET_OBJECTS:RTInterception.osx> 66 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 67 ) 68 set_target_compile_flags(clang_rt.asan_osx ${ASAN_CFLAGS}) 69 filter_available_targets(ASAN_TARGETS x86_64 i386) 70 set_target_properties(clang_rt.asan_osx PROPERTIES 71 OSX_ARCHITECTURES "${ASAN_TARGETS}") 72 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx) 73else() 74 # Otherwise, build separate libraries for each target. 75 if(CAN_TARGET_X86_64) 76 add_library(clang_rt.asan-x86_64 STATIC 77 ${ASAN_SOURCES} 78 $<TARGET_OBJECTS:RTInterception.x86_64> 79 $<TARGET_OBJECTS:RTSanitizerCommon.x86_64> 80 ) 81 set_target_compile_flags(clang_rt.asan-x86_64 82 ${ASAN_CFLAGS} ${TARGET_X86_64_CFLAGS} 83 ) 84 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-x86_64) 85 endif() 86 if(CAN_TARGET_I386) 87 add_library(clang_rt.asan-i386 STATIC 88 ${ASAN_SOURCES} 89 $<TARGET_OBJECTS:RTInterception.i386> 90 $<TARGET_OBJECTS:RTSanitizerCommon.i386> 91 ) 92 set_target_compile_flags(clang_rt.asan-i386 93 ${ASAN_CFLAGS} ${TARGET_I386_CFLAGS} 94 ) 95 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-i386) 96 endif() 97endif() 98 99set_property(TARGET ${ASAN_RUNTIME_LIBRARIES} APPEND PROPERTY 100 COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS}) 101add_clang_runtime_static_library(${ASAN_RUNTIME_LIBRARIES}) 102 103set(ASAN_DYNAMIC_RUNTIME_LIBRARIES) 104if(APPLE) 105 # Build universal binary on APPLE. 106 add_library(clang_rt.asan_osx_dynamic SHARED 107 ${ASAN_DYLIB_SOURCES} 108 $<TARGET_OBJECTS:RTInterception.osx> 109 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 110 ) 111 set_target_compile_flags(clang_rt.asan_osx_dynamic ${ASAN_CFLAGS}) 112 filter_available_targets(ASAN_TARGETS x86_64 i386) 113 set_target_properties(clang_rt.asan_osx_dynamic PROPERTIES 114 COMPILE_DEFINITIONS ${ASAN_DYLIB_DEFINITIONS} 115 OSX_ARCHITECTURES "${ASAN_TARGETS}" 116 LINK_FLAGS "-framework Foundation") 117 list(APPEND ASAN_DYNAMIC_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic) 118endif() 119add_clang_runtime_shared_library(${ASAN_DYNAMIC_RUNTIME_LIBRARIES}) 120 121 122if(LLVM_INCLUDE_TESTS) 123 add_subdirectory(tests) 124endif() 125 126# ASan output tests. 127# FIXME: move all output tests from output_tests/ to lit_tests/ and get rid 128# of the first directory. 129add_subdirectory(lit_tests) 130