Remove check for Android in Mips.cpp (#123793)
[llvm-project.git] / compiler-rt / lib / xray / tests / CMakeLists.txt
blob6b9d9ced9a1dffc6844f35d9c3268eec36b78617
1 include_directories(..)
3 add_custom_target(XRayUnitTests)
4 set_target_properties(XRayUnitTests PROPERTIES FOLDER "Compiler-RT/Tests")
6 # Sanity check XRAY_ALL_SOURCE_FILES_ABS_PATHS
7 list(LENGTH XRAY_ALL_SOURCE_FILES_ABS_PATHS XASFAP_LENGTH)
8 if (${XASFAP_LENGTH} EQUAL 0)
9   message(FATAL_ERROR "XRAY_ALL_SOURCE_FILES_ABS_PATHS cannot be empty")
10 endif()
11 unset(XASFAP_LENGTH)
12 foreach (src_file ${XRAY_ALL_SOURCE_FILES_ABS_PATHS})
13   if (NOT EXISTS "${src_file}")
14     message(FATAL_ERROR "Source file \"${src_file}\" does not exist")
15   endif()
16 endforeach()
18 set(XRAY_UNITTEST_CFLAGS
19   ${XRAY_CFLAGS}
20   ${COMPILER_RT_UNITTEST_CFLAGS}
21   ${COMPILER_RT_GTEST_CFLAGS}
22   ${COMPILER_RT_GMOCK_CFLAGS}
23   -I${COMPILER_RT_SOURCE_DIR}/include
24   -I${COMPILER_RT_SOURCE_DIR}/lib/xray
25   -I${COMPILER_RT_SOURCE_DIR}/lib
26   )
28 # We add the include directories one at a time in our CFLAGS.
29 foreach (DIR ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
30   list(APPEND XRAY_UNITTEST_CFLAGS -I${DIR})
31 endforeach()
33 function(add_xray_lib library)
34   add_library(${library} STATIC ${ARGN})
35   set_target_properties(${library} PROPERTIES
36     ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
37     FOLDER "Compiler-RT/Tests/Runtime")
38 endfunction()
40 function(get_xray_lib_for_arch arch lib)
41   if(APPLE)
42     set(tgt_name "RTXRay.test.osx")
43   else()
44     set(tgt_name "RTXRay.test.${arch}")
45   endif()
46   set(${lib} "${tgt_name}" PARENT_SCOPE)
47 endfunction()
49 set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH})
50 set(XRAY_UNITTEST_LINK_FLAGS
51   ${COMPILER_RT_UNITTEST_LINK_FLAGS}
52   ${CMAKE_THREAD_LIBS_INIT}
53   ${COMPILER_RT_UNWINDER_LINK_LIBS}
54   ${COMPILER_RT_CXX_LINK_LIBS})
56 if (NOT APPLE)
57   # We add the library directories one at a time in our CFLAGS.
58   foreach (DIR ${LLVM_LIBRARY_DIR})
59     list(APPEND XRAY_UNITTEST_LINK_FLAGS -L${DIR})
60   endforeach()
62   if (COMPILER_RT_STANDALONE_BUILD)
63     if (COMPILER_RT_HAS_LLVMXRAY OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
64       if (LLVM_LINK_LLVM_DYLIB)
65         list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVM)
66       endif()
67     else()
68       if (COMPILER_RT_HAS_LLVMXRAY)
69         list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay)
70       endif()
71       if (COMPILER_RT_HAS_TESTINGSUPPORT)
72         list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMTestingSupport)
73       endif()
74       list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMSupport -lLLVMDemangle)
75     endif()
76   else()
77     # We also add the actual libraries to link as dependencies.
78     list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay -lLLVMSupport -lLLVMDemangle -lLLVMTestingSupport)
79   endif()
81   append_list_if(COMPILER_RT_HAS_LIBM -lm XRAY_UNITTEST_LINK_FLAGS)
82   append_list_if(COMPILER_RT_HAS_LIBRT -lrt XRAY_UNITTEST_LINK_FLAGS)
83   append_list_if(COMPILER_RT_HAS_LIBDL -ldl XRAY_UNITTEST_LINK_FLAGS)
84   append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread XRAY_UNITTEST_LINK_FLAGS)
85   append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo XRAY_UNITTEST_LINK_FLAGS)
86 endif()
88 macro(add_xray_unittest testname)
89   cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
90   if(UNIX AND NOT APPLE)
91     set(CMAKE_DL_LIBS_INIT "")
92     foreach(arch ${XRAY_TEST_ARCH})
93       set(TEST_OBJECTS)
94       get_xray_lib_for_arch(${arch} XRAY_RUNTIME_LIBS)
95       generate_compiler_rt_tests(TEST_OBJECTS
96         XRayUnitTests "${testname}-${arch}-Test" "${arch}"
97         SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
98                 ${COMPILER_RT_GMOCK_SOURCE}
100         # Note that any change in the implementations will cause all the unit
101         # tests to be re-built. This is by design, but may be cumbersome during
102         # the build/test cycle.
103         COMPILE_DEPS ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
104         ${XRAY_HEADERS} ${XRAY_ALL_SOURCE_FILES_ABS_PATHS}
105         "test_helpers.h"
106         RUNTIME "${XRAY_RUNTIME_LIBS}"
107         DEPS xray llvm-xray LLVMXRay LLVMTestingSupport
108         CFLAGS ${XRAY_UNITTEST_CFLAGS}
109         LINK_FLAGS ${TARGET_LINK_FLAGS} ${XRAY_UNITTEST_LINK_FLAGS}
110         )
111       set_target_properties(XRayUnitTests
112         PROPERTIES
113         RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
114     endforeach()
115   endif()
116 endmacro()
118 if(COMPILER_RT_CAN_EXECUTE_TESTS)
119   if (APPLE)
120     add_xray_lib("RTXRay.test.osx"
121       $<TARGET_OBJECTS:RTXray.osx>
122       $<TARGET_OBJECTS:RTXrayFDR.osx>
123       $<TARGET_OBJECTS:RTXrayPROFILING.osx>
124       $<TARGET_OBJECTS:RTSanitizerCommon.osx>
125       $<TARGET_OBJECTS:RTSanitizerCommonLibc.osx>)
126   else()
127   foreach(arch ${XRAY_SUPPORTED_ARCH})
128     add_xray_lib("RTXRay.test.${arch}"
129       $<TARGET_OBJECTS:RTXray.${arch}>
130       $<TARGET_OBJECTS:RTXrayFDR.${arch}>
131       $<TARGET_OBJECTS:RTXrayPROFILING.${arch}>
132       $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
133       $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
134   endforeach()
135   endif()
136   add_subdirectory(unit)
137 endif()