[CMake] Make append_if semantics similar to those used in LLVM
[blocksruntime.git] / lib / dfsan / CMakeLists.txt
blobbcf335df95d2f4a6ec18f227c5335f6a502a8c0b
1 include_directories(..)
3 # Runtime library sources and build flags.
4 set(DFSAN_RTL_SOURCES
5   dfsan.cc
6   dfsan_custom.cc
7   dfsan_interceptors.cc)
8 set(DFSAN_COMMON_CFLAGS ${SANITIZER_COMMON_CFLAGS})
9 # Prevent clang from generating libc calls.
10 append_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding DFSAN_COMMON_CFLAGS)
12 # Static runtime library.
13 add_custom_target(dfsan)
14 set(arch "x86_64")
15 if(CAN_TARGET_${arch})
16   set(DFSAN_CFLAGS ${DFSAN_COMMON_CFLAGS})
17   append_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE DFSAN_CFLAGS)
18   add_compiler_rt_static_runtime(clang_rt.dfsan-${arch} ${arch}
19     SOURCES ${DFSAN_RTL_SOURCES}
20             $<TARGET_OBJECTS:RTInterception.${arch}>
21             $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
22             $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
23     CFLAGS ${DFSAN_CFLAGS})
24   set(DFSAN_NOLIBC_CFLAGS ${DFSAN_COMMON_CFLAGS} -DDFSAN_NOLIBC)
25   add_compiler_rt_static_runtime(clang_rt.dfsan-libc-${arch} ${arch}
26     SOURCES ${DFSAN_RTL_SOURCES}
27             $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
28             CFLAGS ${DFSAN_NOLIBC_CFLAGS})
29   add_sanitizer_rt_symbols(clang_rt.dfsan-${arch} dfsan.syms.extra)
30   add_dependencies(dfsan
31     clang_rt.dfsan-${arch}
32     clang_rt.dfsan-${arch}-symbols)
33 endif()
35 set(dfsan_abilist_filename ${COMPILER_RT_OUTPUT_DIR}/dfsan_abilist.txt)
36 add_custom_target(dfsan_abilist ALL
37   SOURCES ${dfsan_abilist_filename})
38 add_custom_command(OUTPUT ${dfsan_abilist_filename}
39                    VERBATIM
40                    COMMAND
41                      cat ${CMAKE_CURRENT_SOURCE_DIR}/done_abilist.txt
42                          ${CMAKE_CURRENT_SOURCE_DIR}/libc_ubuntu1204_abilist.txt
43                          > ${dfsan_abilist_filename}
44                    DEPENDS done_abilist.txt libc_ubuntu1204_abilist.txt)
45 add_dependencies(dfsan dfsan_abilist)
46 install(FILES ${dfsan_abilist_filename}
47         DESTINATION ${COMPILER_RT_INSTALL_PATH})
49 add_dependencies(compiler-rt dfsan)