11adb55b1SChris Appleinclude(CompilerRTCompile) 21adb55b1SChris Apple 31adb55b1SChris Appleinclude_directories(..) 41adb55b1SChris Apple 51adb55b1SChris Appleset(RTSAN_UNITTEST_CFLAGS 61adb55b1SChris Apple ${COMPILER_RT_UNITTEST_CFLAGS} 71adb55b1SChris Apple ${COMPILER_RT_GTEST_CFLAGS} 81adb55b1SChris Apple ${COMPILER_RT_GMOCK_CFLAGS} 91adb55b1SChris Apple ${SANITIZER_TEST_CXX_CFLAGS} 101adb55b1SChris Apple -I${COMPILER_RT_SOURCE_DIR}/lib/ 111adb55b1SChris Apple -I${COMPILER_RT_SOURCE_DIR}/include/ 121adb55b1SChris Apple -I${COMPILER_RT_SOURCE_DIR}/lib/rtsan 131adb55b1SChris Apple -I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/tests 141adb55b1SChris Apple -DSANITIZER_COMMON_NO_REDEFINE_BUILTINS 151adb55b1SChris Apple -O2) 161adb55b1SChris Apple 171adb55b1SChris Appleset(RTSAN_INST_TEST_SOURCES 181adb55b1SChris Apple rtsan_test_functional.cpp 19*1e07c480SChris Apple rtsan_test_interceptors_posix.cpp 201adb55b1SChris Apple rtsan_test_main.cpp) 211adb55b1SChris Apple 221adb55b1SChris Appleset(RTSAN_NOINST_TEST_SOURCES 231adb55b1SChris Apple ../rtsan_preinit.cpp 24cf85b33eSdavidtrevelyan rtsan_test_assertions.cpp 251adb55b1SChris Apple rtsan_test_context.cpp 261adb55b1SChris Apple rtsan_test_main.cpp) 271adb55b1SChris Apple 281adb55b1SChris Appleset(RTSAN_UNITTEST_HEADERS 291adb55b1SChris Apple rtsan_test_utilities.h) 301adb55b1SChris Apple 311adb55b1SChris Appleadd_custom_target(RtsanUnitTests) 321adb55b1SChris Appleset_target_properties(RtsanUnitTests PROPERTIES FOLDER "Compiler-RT Tests") 331adb55b1SChris Apple 341adb55b1SChris Appleset(RTSAN_UNITTEST_LINK_FLAGS 351adb55b1SChris Apple ${COMPILER_RT_UNITTEST_LINK_FLAGS} 361adb55b1SChris Apple ${COMPILER_RT_UNWINDER_LINK_LIBS} 371adb55b1SChris Apple ${SANITIZER_TEST_CXX_LIBRARIES} 381adb55b1SChris Apple -no-pie) 391adb55b1SChris Apple 4026a4edf6SPetr Hosekif (COMPILER_RT_USE_ATOMIC_LIBRARY) 4126a4edf6SPetr Hosek list(APPEND RTSAN_UNITTEST_LINK_FLAGS ${COMPILER_RT_ATOMIC_LIBRARY}) 4226a4edf6SPetr Hosek if (NOT WIN32) 4326a4edf6SPetr Hosek get_filename_component(atomic_dir ${COMPILER_RT_ATOMIC_LIBRARY} DIRECTORY) 4426a4edf6SPetr Hosek list(APPEND RTSAN_UNITTEST_LINK_FLAGS "-Wl,-rpath,${atomic_dir}") 4526a4edf6SPetr Hosek endif() 4626a4edf6SPetr Hosekelse() 47b8461769SChris Apple append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic RTSAN_UNITTEST_LINK_FLAGS) 4826a4edf6SPetr Hosekendif() 497b96d133SChris Appleappend_list_if(COMPILER_RT_HAS_LIBDL -ldl RTSAN_UNITTEST_LINK_FLAGS) 507b96d133SChris Appleappend_list_if(COMPILER_RT_HAS_LIBRT -lrt RTSAN_UNITTEST_LINK_FLAGS) 517b96d133SChris Appleappend_list_if(COMPILER_RT_HAS_LIBM -lm RTSAN_UNITTEST_LINK_FLAGS) 522080af56SChris Appleappend_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread RTSAN_UNITTEST_LINK_FLAGS) 537b96d133SChris Appleappend_list_if(COMPILER_RT_HAS_LIBLOG -llog RTSAN_UNITTEST_LINK_FLAGS) 542080af56SChris Apple 551adb55b1SChris Appleif (APPLE) 561adb55b1SChris Apple add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS) 571adb55b1SChris Apple list(APPEND RTSAN_UNITTEST_LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}) 581adb55b1SChris Apple list(APPEND RTSAN_UNITTEST_LINK_FLAGS ${DARWIN_osx_LINK_FLAGS}) 591adb55b1SChris Apple list(APPEND RTSAN_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS}) 601adb55b1SChris Appleendif() 611adb55b1SChris Apple 621adb55b1SChris Appleset(COMPILER_RT_GOOGLETEST_SOURCES ${COMPILER_RT_GTEST_SOURCE} ${COMPILER_RT_GMOCK_SOURCE}) 631adb55b1SChris Apple 641adb55b1SChris Appleset(RTSAN_TEST_ARCH ${RTSAN_SUPPORTED_ARCH}) 651adb55b1SChris Appleif(APPLE) 661adb55b1SChris Apple darwin_filter_host_archs(RTSAN_SUPPORTED_ARCH RTSAN_TEST_ARCH) 671adb55b1SChris Appleendif() 681adb55b1SChris Apple 691adb55b1SChris Appleforeach(arch ${RTSAN_TEST_ARCH}) 701adb55b1SChris Apple set(RtsanTestObjects) 711adb55b1SChris Apple 72ca95bee6SChris Apple generate_compiler_rt_tests(RtsanTestObjects 73ca95bee6SChris Apple RtsanUnitTests "Rtsan-${arch}-Test" ${arch} 74ca95bee6SChris Apple COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS} 75ca95bee6SChris Apple SOURCES ${RTSAN_INST_TEST_SOURCES} ${COMPILER_RT_GOOGLETEST_SOURCES} 76ca95bee6SChris Apple DEPS rtsan 77ca95bee6SChris Apple CFLAGS ${RTSAN_UNITTEST_CFLAGS} -fsanitize=realtime 78ca95bee6SChris Apple LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} -fsanitize=realtime) 791adb55b1SChris Apple 8003635b32SChris Apple check_symbol_exists(__GLIBC__ stdio.h RTSAN_USING_GLIBC) 8103635b32SChris Apple if (RTSAN_USING_GLIBC) 8203635b32SChris Apple set(RtsanTestObjects_FileOffset64) 8303635b32SChris Apple generate_compiler_rt_tests(RtsanTestObjects_FileOffset64 8403635b32SChris Apple RtsanUnitTests "Rtsan-${arch}-FileOffset64-Test" ${arch} 8503635b32SChris Apple COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS} 8603635b32SChris Apple SOURCES ${RTSAN_INST_TEST_SOURCES} ${COMPILER_RT_GOOGLETEST_SOURCES} 8703635b32SChris Apple DEPS rtsan 8803635b32SChris Apple CFLAGS ${RTSAN_UNITTEST_CFLAGS} -D_FILE_OFFSET_BITS=64 -fsanitize=realtime 8903635b32SChris Apple LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} -fsanitize=realtime) 9003635b32SChris Apple endif() 9103635b32SChris Apple 921adb55b1SChris Apple set(RTSAN_TEST_RUNTIME RTRtsanTest.${arch}) 931adb55b1SChris Apple if(APPLE) 941adb55b1SChris Apple set(RTSAN_TEST_RUNTIME_OBJECTS 951adb55b1SChris Apple $<TARGET_OBJECTS:RTRtsan.osx> 961adb55b1SChris Apple $<TARGET_OBJECTS:RTInterception.osx> 971adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommon.osx> 981adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommonLibc.osx> 991adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommonCoverage.osx> 1001adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.osx>) 1011adb55b1SChris Apple else() 1021adb55b1SChris Apple set(RTSAN_TEST_RUNTIME_OBJECTS 1031adb55b1SChris Apple $<TARGET_OBJECTS:RTRtsan.${arch}> 1041adb55b1SChris Apple $<TARGET_OBJECTS:RTInterception.${arch}> 1051adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> 1061adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> 1071adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommonCoverage.${arch}> 1081adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}> 1091adb55b1SChris Apple $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>) 1101adb55b1SChris Apple endif() 1111adb55b1SChris Apple add_library(${RTSAN_TEST_RUNTIME} STATIC ${RTSAN_TEST_RUNTIME_OBJECTS}) 1121adb55b1SChris Apple set_target_properties(${RTSAN_TEST_RUNTIME} PROPERTIES 1131adb55b1SChris Apple ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 1141adb55b1SChris Apple FOLDER "Compiler-RT Runtime tests") 1151adb55b1SChris Apple 1161adb55b1SChris Apple set(RtsanNoInstTestObjects) 1171adb55b1SChris Apple generate_compiler_rt_tests(RtsanNoInstTestObjects 1181adb55b1SChris Apple RtsanUnitTests "Rtsan-${arch}-NoInstTest" ${arch} 1191adb55b1SChris Apple COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS} 1201adb55b1SChris Apple SOURCES ${RTSAN_NOINST_TEST_SOURCES} 1211adb55b1SChris Apple ${COMPILER_RT_GOOGLETEST_SOURCES} 1221adb55b1SChris Apple CFLAGS ${RTSAN_UNITTEST_CFLAGS} 1231adb55b1SChris Apple LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} 1241adb55b1SChris Apple RUNTIME ${RTSAN_TEST_RUNTIME}) 1251adb55b1SChris Apple set_target_properties(RtsanUnitTests PROPERTIES 1261adb55b1SChris Apple RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 1271adb55b1SChris Appleendforeach() 128