[ASan] hacking cmake build: after generating asan runtime, copy it to the Clang lib directory where Clang driver expects to find it.

llvm-svn: 160669
This commit is contained in:
Alexey Samsonov 2012-07-24 11:49:55 +00:00
parent 465834c85f
commit 3397013606
1 changed files with 27 additions and 1 deletions

View File

@ -28,6 +28,9 @@ set(ASAN_CFLAGS
-fno-exceptions
-funwind-tables
-fvisibility=hidden
-fno-builtin
-fomit-frame-pointer
-O3
)
if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
list(APPEND ASAN_CFLAGS -Wno-variadic-macros)
@ -38,6 +41,21 @@ set(ASAN_COMMON_DEFINITIONS
ASAN_NEEDS_SEGV=1
)
# Compute the Clang version from the LLVM version.
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
${PACKAGE_VERSION})
# Set up paths to ASan runtime that Clang driver passes to linker.
if (APPLE)
# FIXME: We need to build OS X universal binary libclang_rt.asan-osx.a
# instead of two arch-specific binaries.
set(clang_lib_dir ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION}/lib/darwin)
list(APPEND ASAN_CFLAGS -mmacosx-version-min=10.5)
elseif (UNIX)
# Assume Linux.
set(clang_lib_dir ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION}/lib/linux)
endif()
if(CAN_TARGET_X86_64)
add_library(clang_rt.asan-x86_64 STATIC
${ASAN_SOURCES}
@ -50,6 +68,10 @@ if(CAN_TARGET_X86_64)
)
set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY COMPILE_DEFINITIONS
${ASAN_COMMON_DEFINITIONS})
add_custom_command (TARGET clang_rt.asan-x86_64 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:clang_rt.asan-x86_64>
${clang_lib_dir}/libclang_rt.asan-x86_64.a
COMMENT "Copying libclang_rt.asan-x86_64.a to Clang lib dir...")
endif()
if(CAN_TARGET_I386)
add_library(clang_rt.asan-i386 STATIC
@ -61,8 +83,12 @@ if(CAN_TARGET_I386)
${ASAN_CFLAGS}
${TARGET_I386_CFLAGS}
)
set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY COMPILE_DEFINITIONS
set_property(TARGET clang_rt.asan-i386 APPEND PROPERTY COMPILE_DEFINITIONS
${ASAN_COMMON_DEFINITIONS})
add_custom_command (TARGET clang_rt.asan-i386 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:clang_rt.asan-i386>
${clang_lib_dir}/libclang_rt.asan-i386.a
COMMENT "Copying libclang_rt.asan-i386.a to Clang lib dir...")
endif()
if(LLVM_INCLUDE_TESTS)