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")
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")
18 set(XRAY_UNITTEST_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
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})
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")
40 function(get_xray_lib_for_arch arch lib)
42 set(tgt_name "RTXRay.test.osx")
44 set(tgt_name "RTXRay.test.${arch}")
46 set(${lib} "${tgt_name}" PARENT_SCOPE)
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})
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})
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)
68 if (COMPILER_RT_HAS_LLVMXRAY)
69 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay)
71 if (COMPILER_RT_HAS_TESTINGSUPPORT)
72 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMTestingSupport)
74 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMSupport -lLLVMDemangle)
77 # We also add the actual libraries to link as dependencies.
78 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay -lLLVMSupport -lLLVMDemangle -lLLVMTestingSupport)
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)
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})
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}
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}
111 set_target_properties(XRayUnitTests
113 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
118 if(COMPILER_RT_CAN_EXECUTE_TESTS)
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>)
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}>)
136 add_subdirectory(unit)