1 include_directories(..)
3 add_custom_target(XRayUnitTests)
4 set_target_properties(XRayUnitTests PROPERTIES FOLDER "XRay unittests")
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 Runtime tests")
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 # Needed by LLVMSupport.
60 -l${COMPILER_RT_TERMINFO_LIB} XRAY_UNITTEST_LINK_FLAGS)
62 # We add the library directories one at a time in our CFLAGS.
63 foreach (DIR ${LLVM_LIBRARY_DIR})
64 list(APPEND XRAY_UNITTEST_LINK_FLAGS -L${DIR})
67 if (COMPILER_RT_STANDALONE_BUILD)
68 if (COMPILER_RT_HAS_LLVMXRAY OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
69 if (LLVM_LINK_LLVM_DYLIB)
70 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVM)
73 if (COMPILER_RT_HAS_LLVMXRAY)
74 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay)
76 if (COMPILER_RT_HAS_TESTINGSUPPORT)
77 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMTestingSupport)
79 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMSupport -lLLVMDemangle)
82 # We also add the actual libraries to link as dependencies.
83 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay -lLLVMSupport -lLLVMDemangle -lLLVMTestingSupport)
86 append_list_if(COMPILER_RT_HAS_LIBM -lm XRAY_UNITTEST_LINK_FLAGS)
87 append_list_if(COMPILER_RT_HAS_LIBRT -lrt XRAY_UNITTEST_LINK_FLAGS)
88 append_list_if(COMPILER_RT_HAS_LIBDL -ldl XRAY_UNITTEST_LINK_FLAGS)
89 append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread XRAY_UNITTEST_LINK_FLAGS)
90 append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo XRAY_UNITTEST_LINK_FLAGS)
93 macro(add_xray_unittest testname)
94 cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
95 if(UNIX AND NOT APPLE)
96 set(CMAKE_DL_LIBS_INIT "")
97 foreach(arch ${XRAY_TEST_ARCH})
99 get_xray_lib_for_arch(${arch} XRAY_RUNTIME_LIBS)
100 generate_compiler_rt_tests(TEST_OBJECTS
101 XRayUnitTests "${testname}-${arch}-Test" "${arch}"
102 SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
103 ${COMPILER_RT_GMOCK_SOURCE}
105 # Note that any change in the implementations will cause all the unit
106 # tests to be re-built. This is by design, but may be cumbersome during
107 # the build/test cycle.
108 COMPILE_DEPS ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
109 ${XRAY_HEADERS} ${XRAY_ALL_SOURCE_FILES_ABS_PATHS}
111 RUNTIME "${XRAY_RUNTIME_LIBS}"
112 DEPS llvm_gtest xray llvm-xray LLVMXRay LLVMTestingSupport
113 CFLAGS ${XRAY_UNITTEST_CFLAGS}
114 LINK_FLAGS ${TARGET_LINK_FLAGS} ${XRAY_UNITTEST_LINK_FLAGS}
116 set_target_properties(XRayUnitTests
118 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
123 if(COMPILER_RT_CAN_EXECUTE_TESTS)
125 add_xray_lib("RTXRay.test.osx"
126 $<TARGET_OBJECTS:RTXray.osx>
127 $<TARGET_OBJECTS:RTXrayFDR.osx>
128 $<TARGET_OBJECTS:RTXrayPROFILING.osx>
129 $<TARGET_OBJECTS:RTSanitizerCommon.osx>
130 $<TARGET_OBJECTS:RTSanitizerCommonLibc.osx>)
132 foreach(arch ${XRAY_SUPPORTED_ARCH})
133 add_xray_lib("RTXRay.test.${arch}"
134 $<TARGET_OBJECTS:RTXray.${arch}>
135 $<TARGET_OBJECTS:RTXrayFDR.${arch}>
136 $<TARGET_OBJECTS:RTXrayPROFILING.${arch}>
137 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
138 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
141 add_subdirectory(unit)