[AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (#94647)
[llvm-project.git] / compiler-rt / lib / interception / tests / CMakeLists.txt
blobf348c35cbe22fe455770ed8eecdfe6d49f33f30a
1 include(CompilerRTCompile)
3 filter_available_targets(INTERCEPTION_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el)
5 set(INTERCEPTION_UNITTESTS
6   interception_linux_test.cpp
7   interception_linux_foreign_test.cpp
8   interception_test_main.cpp
9   interception_win_test.cpp
10   )
12 set(INTERCEPTION_TEST_HEADERS)
14 set(INTERCEPTION_TEST_CFLAGS_COMMON
15   ${COMPILER_RT_UNITTEST_CFLAGS}
16   ${COMPILER_RT_GTEST_CFLAGS}
17   ${SANITIZER_TEST_CXX_CFLAGS}
18   -I${COMPILER_RT_SOURCE_DIR}/include
19   -I${COMPILER_RT_SOURCE_DIR}/lib
20   -I${COMPILER_RT_SOURCE_DIR}/lib/interception
21   -DSANITIZER_COMMON_NO_REDEFINE_BUILTINS
22   -fno-rtti
23   -fno-builtin-isdigit
24   -fno-builtin-isalpha
25   -fno-builtin-isalnum
26   -fno-builtin-islower
27   -O2
28   -Werror=sign-compare)
30 set(INTERCEPTION_TEST_LINK_FLAGS_COMMON
31   ${COMPILER_RT_UNITTEST_LINK_FLAGS}
32   ${COMPILER_RT_UNWINDER_LINK_LIBS}
33   ${SANITIZER_TEST_CXX_LIBRARIES})
35 # -gline-tables-only must be enough for these tests, so use it if possible.
36 if(COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang")
37   list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -gline-tables-only)
38 else()
39   list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -g)
40 endif()
41 if(MSVC)
42   list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -gcodeview)
43   list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON
44     -Wl,-largeaddressaware
45     -Wl,-nodefaultlib:libcmt,-defaultlib:msvcrt,-defaultlib:oldnames
46     )
47 endif()
48 if(MINGW)
49   list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON
50     -Wl,--large-address-aware
51     )
52 endif()
53 list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON -g)
55 if(NOT MSVC)
56   list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON --driver-mode=g++)
57 endif()
59 if(ANDROID)
60   list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON -pie)
61 endif()
63 set(INTERCEPTION_TEST_LINK_LIBS)
64 append_list_if(COMPILER_RT_HAS_LIBLOG log INTERCEPTION_TEST_LINK_LIBS)
66 append_list_if(COMPILER_RT_HAS_LIBDL -ldl INTERCEPTION_TEST_LINK_FLAGS_COMMON)
67 append_list_if(COMPILER_RT_HAS_LIBRT -lrt INTERCEPTION_TEST_LINK_FLAGS_COMMON)
68 append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread INTERCEPTION_TEST_LINK_FLAGS_COMMON)
69 # x86_64 FreeBSD 9.2 additionally requires libc++ to build the tests. Also,
70 # 'libm' shall be specified explicitly to build i386 tests.
71 if(CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE")
72   list(APPEND INTERCEPTION_TEST_LINK_FLAGS_COMMON "-lc++ -lm")
73 endif()
75 include_directories(..)
76 include_directories(../..)
78 # Adds static library which contains interception object file
79 # (universal binary on Mac and arch-specific object files on Linux).
80 macro(add_interceptor_lib library)
81   add_library(${library} STATIC ${ARGN})
82   set_target_properties(${library} PROPERTIES
83     ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
84     FOLDER "Compiler-RT/Tests/Runtime")
85 endmacro()
87 function(get_interception_lib_for_arch arch lib)
88   if(APPLE)
89     set(tgt_name "RTInterception.test.osx")
90   else()
91     set(tgt_name "RTInterception.test.${arch}")
92   endif()
93   set(${lib} "${tgt_name}" PARENT_SCOPE)
94 endfunction()
96 # Interception unit tests testsuite.
97 add_custom_target(InterceptionUnitTests)
98 set_target_properties(InterceptionUnitTests PROPERTIES
99   FOLDER "Compiler-RT/Tests")
101 # Adds interception tests for architecture.
102 macro(add_interception_tests_for_arch arch)
103   set(INTERCEPTION_TEST_OBJECTS)
104   get_interception_lib_for_arch(${arch} INTERCEPTION_COMMON_LIB)
105   generate_compiler_rt_tests(INTERCEPTION_TEST_OBJECTS
106     InterceptionUnitTests "Interception-${arch}-Test" ${arch}
107     RUNTIME ${INTERCEPTION_COMMON_LIB}
108     SOURCES ${INTERCEPTION_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
109     COMPILE_DEPS ${INTERCEPTION_TEST_HEADERS}
110     CFLAGS ${INTERCEPTION_TEST_CFLAGS_COMMON}
111     LINK_FLAGS ${INTERCEPTION_TEST_LINK_FLAGS_COMMON})
112 endmacro()
114 if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID AND NOT APPLE)
115   # We use just-built clang to build interception unittests, so we must
116   # be sure that produced binaries would work.
117   if(APPLE)
118     add_interceptor_lib("RTInterception.test.osx"
119                         $<TARGET_OBJECTS:RTInterception.osx>)
120   else()
121     foreach(arch ${INTERCEPTION_UNITTEST_SUPPORTED_ARCH})
122       add_interceptor_lib("RTInterception.test.${arch}"
123                           $<TARGET_OBJECTS:RTInterception.${arch}>)
124     endforeach()
125   endif()
126   foreach(arch ${INTERCEPTION_UNITTEST_SUPPORTED_ARCH})
127     add_interception_tests_for_arch(${arch})
128   endforeach()
129 endif()