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