]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/interception/tests/CMakeLists.txt
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / lib / interception / tests / CMakeLists.txt
1 include(CompilerRTCompile)
2
3 filter_available_targets(INTERCEPTION_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el)
4
5 set(INTERCEPTION_UNITTESTS
6 interception_linux_test.cc
7 interception_test_main.cc
8 interception_win_test.cc
9 )
10
11 set(INTERCEPTION_TEST_HEADERS)
12
13 set(INTERCEPTION_TEST_CFLAGS_COMMON
14 ${COMPILER_RT_UNITTEST_CFLAGS}
15 ${COMPILER_RT_GTEST_CFLAGS}
16 -I${COMPILER_RT_SOURCE_DIR}/include
17 -I${COMPILER_RT_SOURCE_DIR}/lib
18 -I${COMPILER_RT_SOURCE_DIR}/lib/interception
19 -fno-rtti
20 -O2
21 -Werror=sign-compare
22 -Wno-non-virtual-dtor)
23
24 # -gline-tables-only must be enough for these tests, so use it if possible.
25 if(COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang")
26 list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -gline-tables-only)
27 else()
28 list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -g)
29 endif()
30 if(MSVC)
31 list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -gcodeview)
32 list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON -Wl,-largeaddressaware)
33 endif()
34 list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON -g)
35
36 if(NOT MSVC)
37 list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON --driver-mode=g++)
38 endif()
39
40 if(ANDROID)
41 list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON -pie)
42 endif()
43
44 set(INTERCEPTION_TEST_LINK_LIBS)
45 append_list_if(COMPILER_RT_HAS_LIBLOG log INTERCEPTION_TEST_LINK_LIBS)
46 # NDK r10 requires -latomic almost always.
47 append_list_if(ANDROID atomic INTERCEPTION_TEST_LINK_LIBS)
48
49 append_list_if(COMPILER_RT_HAS_LIBDL -ldl INTERCEPTION_TEST_LINK_FLAGS_COMMON)
50 append_list_if(COMPILER_RT_HAS_LIBRT -lrt INTERCEPTION_TEST_LINK_FLAGS_COMMON)
51 append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread INTERCEPTION_TEST_LINK_FLAGS_COMMON)
52 # x86_64 FreeBSD 9.2 additionally requires libc++ to build the tests. Also,
53 # 'libm' shall be specified explicitly to build i386 tests.
54 if(CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE")
55 list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON "-lc++ -lm")
56 endif()
57
58 include_directories(..)
59 include_directories(../..)
60
61 # Adds static library which contains interception object file
62 # (universal binary on Mac and arch-specific object files on Linux).
63 macro(add_interceptor_lib library)
64 add_library(${library} STATIC ${ARGN})
65 set_target_properties(${library} PROPERTIES
66 ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
67 FOLDER "Compiler-RT Runtime tests")
68 endmacro()
69
70 function(get_interception_lib_for_arch arch lib)
71 if(APPLE)
72 set(tgt_name "RTInterception.test.osx")
73 else()
74 set(tgt_name "RTInterception.test.${arch}")
75 endif()
76 set(${lib} "${tgt_name}" PARENT_SCOPE)
77 endfunction()
78
79 # Interception unit tests testsuite.
80 add_custom_target(InterceptionUnitTests)
81 set_target_properties(InterceptionUnitTests PROPERTIES
82 FOLDER "Compiler-RT Tests")
83
84 # Adds interception tests for architecture.
85 macro(add_interception_tests_for_arch arch)
86 set(INTERCEPTION_TEST_OBJECTS)
87 get_interception_lib_for_arch(${arch} INTERCEPTION_COMMON_LIB)
88 generate_compiler_rt_tests(INTERCEPTION_TEST_OBJECTS
89 InterceptionUnitTests "Interception-${arch}-Test" ${arch}
90 RUNTIME ${INTERCEPTION_COMMON_LIB}
91 SOURCES ${INTERCEPTION_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
92 COMPILE_DEPS ${INTERCEPTION_TEST_HEADERS}
93 DEPS gtest
94 CFLAGS ${INTERCEPTION_TEST_CFLAGS_COMMON}
95 LINK_FLAGS ${INTERCEPTION_TEST_LINK_FLAGS_COMMON})
96 endmacro()
97
98 if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID AND NOT APPLE)
99 # We use just-built clang to build interception unittests, so we must
100 # be sure that produced binaries would work.
101 if(APPLE)
102 add_interceptor_lib("RTInterception.test.osx"
103 $<TARGET_OBJECTS:RTInterception.osx>)
104 else()
105 foreach(arch ${INTERCEPTION_UNITTEST_SUPPORTED_ARCH})
106 add_interceptor_lib("RTInterception.test.${arch}"
107 $<TARGET_OBJECTS:RTInterception.${arch}>)
108 endforeach()
109 endif()
110 foreach(arch ${INTERCEPTION_UNITTEST_SUPPORTED_ARCH})
111 add_interception_tests_for_arch(${arch})
112 endforeach()
113 endif()