]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/xray/tests/CMakeLists.txt
Merge compiler-rt r291274.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / xray / tests / CMakeLists.txt
1 include_directories(..)
2
3 add_custom_target(XRayUnitTests)
4 set_target_properties(XRayUnitTests PROPERTIES FOLDER "XRay unittests")
5
6 set(XRAY_UNITTEST_CFLAGS
7   ${XRAY_CFLAGS}
8   ${COMPILER_RT_UNITTEST_CFLAGS}
9   ${COMPILER_RT_GTEST_CFLAGS}
10   -I${COMPILER_RT_SOURCE_DIR}/include
11   -I${COMPILER_RT_SOURCE_DIR}/lib/xray)
12
13 macro(xray_compile obj_list source arch)
14   get_filename_component(basename ${source} NAME)
15   set(output_obj "${basename}.${arch}.o")
16   get_target_flags_for_arch(${arch} TARGET_CFLAGS)
17   if(NOT COMPILER_RT_STANDALONE_BUILD)
18     list(APPEND COMPILE_DEPS gtest_main xray-fdr)
19   endif()
20   clang_compile(${output_obj} ${source}
21     CFLAGS ${XRAY_UNITTEST_CFLAGS} ${TARGET_CFLAGS}
22     DEPS ${COMPILE_DEPS})
23   list(APPEND ${obj_list} ${output_obj})
24 endmacro()
25
26 macro(add_xray_unittest testname)
27   set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH})
28   if (APPLE)
29     darwin_filter_host_archs(XRAY_SUPPORTED_ARCH)
30   endif()
31   if(UNIX)
32     foreach(arch ${XRAY_TEST_ARCH})
33       cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
34       set(TEST_OBJECTS)
35       foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE})
36         xray_compile(TEST_OBJECTS ${SOURCE} ${arch} ${TEST_HEADERS})
37       endforeach()
38       get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
39       set(TEST_DEPS ${TEST_OBJECTS})
40       if(NOT COMPILER_RT_STANDALONE_BUILD)
41         list(APPEND TEST_DEPS gtest_main xray-fdr)
42       endif()
43       if(NOT APPLE)
44         add_compiler_rt_test(XRayUnitTests ${testname}
45           OBJECTS ${TEST_OBJECTS}
46           DEPS ${TEST_DEPS}
47           LINK_FLAGS ${TARGET_LINK_FLAGS}
48           -lstdc++ -lm ${CMAKE_THREAD_LIBS_INIT}
49           -lpthread
50           -L${COMPILER_RT_LIBRARY_OUTPUT_DIR} -lclang_rt.xray-fdr-${arch})
51       endif()
52       # FIXME: Figure out how to run even just the unit tests on APPLE.
53     endforeach()
54   endif()
55 endmacro()
56
57 if(COMPILER_RT_CAN_EXECUTE_TESTS)
58   add_subdirectory(unit)
59 endif()