1 include(CompilerRTCompile)
3 set(GWP_ASAN_UNITTEST_CFLAGS
4 ${COMPILER_RT_UNITTEST_CFLAGS}
5 ${COMPILER_RT_GTEST_CFLAGS}
6 ${SANITIZER_TEST_CXX_CFLAGS}
8 -I${COMPILER_RT_SOURCE_DIR}/lib/
11 -fno-omit-frame-pointer)
13 file(GLOB GWP_ASAN_HEADERS ../*.h)
14 set(GWP_ASAN_UNITTESTS
15 platform_specific/printf_sanitizer_common.cpp
33 set(GWP_ASAN_UNIT_TEST_HEADERS
37 add_custom_target(GwpAsanUnitTests)
38 set_target_properties(GwpAsanUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
40 set(GWP_ASAN_UNITTEST_LINK_FLAGS
41 ${COMPILER_RT_UNITTEST_LINK_FLAGS} -ldl
42 ${COMPILER_RT_UNWINDER_LINK_LIBS}
43 ${SANITIZER_TEST_CXX_LIBRARIES})
44 list(APPEND GWP_ASAN_UNITTEST_LINK_FLAGS --driver-mode=g++)
46 list(APPEND GWP_ASAN_UNITTEST_LINK_FLAGS -pthread)
49 if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST GWP_ASAN_SUPPORTED_ARCH)
50 # GWP-ASan unit tests are only run on the host machine.
51 set(arch ${COMPILER_RT_DEFAULT_TARGET_ARCH})
53 set(GWP_ASAN_TEST_RUNTIME RTGwpAsanTest.${arch})
55 set(GWP_ASAN_TEST_RUNTIME_OBJECTS
56 $<TARGET_OBJECTS:RTGwpAsan.${arch}>
57 $<TARGET_OBJECTS:RTGwpAsanBacktraceSanitizerCommon.${arch}>
58 $<TARGET_OBJECTS:RTGwpAsanSegvHandler.${arch}>
59 $<TARGET_OBJECTS:RTGwpAsanOptionsParser.${arch}>
60 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
61 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
62 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
63 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>)
65 add_library(${GWP_ASAN_TEST_RUNTIME} STATIC
66 ${GWP_ASAN_TEST_RUNTIME_OBJECTS})
68 set_target_properties(${GWP_ASAN_TEST_RUNTIME} PROPERTIES
69 ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
70 FOLDER "Compiler-RT Runtime tests")
72 set(GwpAsanTestObjects)
73 generate_compiler_rt_tests(GwpAsanTestObjects
74 GwpAsanUnitTests "GwpAsan-${arch}-Test" ${arch}
75 SOURCES ${GWP_ASAN_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
76 RUNTIME ${GWP_ASAN_TEST_RUNTIME}
77 DEPS llvm_gtest ${GWP_ASAN_UNIT_TEST_HEADERS}
78 CFLAGS ${GWP_ASAN_UNITTEST_CFLAGS}
79 LINK_FLAGS ${GWP_ASAN_UNITTEST_LINK_FLAGS})
80 set_target_properties(GwpAsanUnitTests PROPERTIES
81 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})