1include(CompilerRTCompile) 2 3set(GWP_ASAN_UNITTEST_CFLAGS 4 ${COMPILER_RT_UNITTEST_CFLAGS} 5 ${COMPILER_RT_GTEST_CFLAGS} 6 -I${COMPILER_RT_SOURCE_DIR}/lib/ 7 -O2 8 -g 9 -fno-omit-frame-pointer) 10 11file(GLOB GWP_ASAN_HEADERS ../*.h) 12set(GWP_ASAN_UNITTESTS 13 optional/printf_sanitizer_common.cpp 14 alignment.cpp 15 backtrace.cpp 16 basic.cpp 17 compression.cpp 18 iterate.cpp 19 crash_handler_api.cpp 20 driver.cpp 21 mutex_test.cpp 22 slot_reuse.cpp 23 thread_contention.cpp 24 harness.cpp 25 enable_disable.cpp 26 late_init.cpp) 27 28set(GWP_ASAN_UNIT_TEST_HEADERS 29 ${GWP_ASAN_HEADERS} 30 harness.h) 31 32add_custom_target(GwpAsanUnitTests) 33set_target_properties(GwpAsanUnitTests PROPERTIES FOLDER "Compiler-RT Tests") 34 35set(GWP_ASAN_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS} -ldl) 36list(APPEND GWP_ASAN_UNITTEST_LINK_FLAGS --driver-mode=g++) 37if(NOT WIN32) 38 list(APPEND GWP_ASAN_UNITTEST_LINK_FLAGS -pthread) 39endif() 40 41if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST GWP_ASAN_SUPPORTED_ARCH) 42 # GWP-ASan unit tests are only run on the host machine. 43 set(arch ${COMPILER_RT_DEFAULT_TARGET_ARCH}) 44 45 set(GWP_ASAN_TEST_RUNTIME RTGwpAsanTest.${arch}) 46 47 set(GWP_ASAN_TEST_RUNTIME_OBJECTS 48 $<TARGET_OBJECTS:RTGwpAsan.${arch}> 49 $<TARGET_OBJECTS:RTGwpAsanBacktraceSanitizerCommon.${arch}> 50 $<TARGET_OBJECTS:RTGwpAsanSegvHandler.${arch}> 51 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> 52 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> 53 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>) 54 55 add_library(${GWP_ASAN_TEST_RUNTIME} STATIC 56 ${GWP_ASAN_TEST_RUNTIME_OBJECTS}) 57 58 set_target_properties(${GWP_ASAN_TEST_RUNTIME} PROPERTIES 59 ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 60 FOLDER "Compiler-RT Runtime tests") 61 62 set(GwpAsanTestObjects) 63 generate_compiler_rt_tests(GwpAsanTestObjects 64 GwpAsanUnitTests "GwpAsan-${arch}-Test" ${arch} 65 SOURCES ${GWP_ASAN_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE} 66 RUNTIME ${GWP_ASAN_TEST_RUNTIME} 67 DEPS gtest ${GWP_ASAN_UNIT_TEST_HEADERS} 68 CFLAGS ${GWP_ASAN_UNITTEST_CFLAGS} 69 LINK_FLAGS ${GWP_ASAN_UNITTEST_LINK_FLAGS}) 70 set_target_properties(GwpAsanUnitTests PROPERTIES 71 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 72endif() 73