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
35 set(GWP_ASAN_UNIT_TEST_HEADERS
39 add_custom_target(GwpAsanUnitTests)
40 set_target_properties(GwpAsanUnitTests PROPERTIES FOLDER "Compiler-RT/Tests")
42 set(GWP_ASAN_UNITTEST_LINK_FLAGS
43 ${COMPILER_RT_UNITTEST_LINK_FLAGS} -ldl
44 ${COMPILER_RT_UNWINDER_LINK_LIBS}
45 ${SANITIZER_TEST_CXX_LIBRARIES})
46 list(APPEND GWP_ASAN_UNITTEST_LINK_FLAGS --driver-mode=g++)
48 list(APPEND GWP_ASAN_UNITTEST_LINK_FLAGS -pthread)
51 if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST GWP_ASAN_SUPPORTED_ARCH)
52 # GWP-ASan unit tests are only run on the host machine.
53 set(arch ${COMPILER_RT_DEFAULT_TARGET_ARCH})
55 set(GWP_ASAN_TEST_RUNTIME RTGwpAsanTest.${arch})
57 set(GWP_ASAN_TEST_RUNTIME_OBJECTS
58 $<TARGET_OBJECTS:RTGwpAsan.${arch}>
59 $<TARGET_OBJECTS:RTGwpAsanBacktraceSanitizerCommon.${arch}>
60 $<TARGET_OBJECTS:RTGwpAsanSegvHandler.${arch}>
61 $<TARGET_OBJECTS:RTGwpAsanOptionsParser.${arch}>
62 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
63 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
64 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
65 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>)
67 add_library(${GWP_ASAN_TEST_RUNTIME} STATIC
68 ${GWP_ASAN_TEST_RUNTIME_OBJECTS})
70 set_target_properties(${GWP_ASAN_TEST_RUNTIME} PROPERTIES
71 ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
72 FOLDER "Compiler-RT/Tests/Runtime")
74 set(GwpAsanTestObjects)
75 generate_compiler_rt_tests(GwpAsanTestObjects
76 GwpAsanUnitTests "GwpAsan-${arch}-Test" ${arch}
77 SOURCES ${GWP_ASAN_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
78 RUNTIME ${GWP_ASAN_TEST_RUNTIME}
79 DEPS ${GWP_ASAN_UNIT_TEST_HEADERS}
80 CFLAGS ${GWP_ASAN_UNITTEST_CFLAGS}
81 LINK_FLAGS ${GWP_ASAN_UNITTEST_LINK_FLAGS})
82 set_target_properties(GwpAsanUnitTests PROPERTIES
83 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})