Merge branch 'dietoref1-2prep-2-3-4-5-6-7-dwzpair-altlink-sharedstmt-dieref-dwz3...
[lldb.git] / compiler-rt / test / builtins / CMakeLists.txt
1 set(BUILTINS_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2
3 set(BUILTINS_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} builtins)
4 set(BUILTINS_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/TestCases)
5
6 # Test cases.
7 configure_lit_site_cfg(
8   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
9   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
10 )
11
12 #Unit tests.
13
14 include(builtin-config-ix)
15
16 # Indicate if this is an MSVC environment.
17 pythonize_bool(MSVC)
18
19 # Indicate if the compiler for the builtins library was MSVC. If the builtins
20 # compiler was clang-cl, we will enable some features that the host compiler
21 # will not, like C99 _Complex and int128.
22 set(BUILTINS_IS_MSVC OFF)
23 if (MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
24   set(BUILTINS_IS_MSVC ON)
25 endif()
26 pythonize_bool(BUILTINS_IS_MSVC)
27
28 set(BUILTIN_TEST_ARCH ${BUILTIN_SUPPORTED_ARCH})
29 if(APPLE)
30   darwin_filter_host_archs(BUILTIN_SUPPORTED_ARCH BUILTIN_TEST_ARCH)
31 endif()
32
33 foreach(arch ${BUILTIN_TEST_ARCH})
34   set(BUILTINS_TEST_TARGET_ARCH ${arch})
35   string(TOLOWER "-${arch}-${OS_NAME}" BUILTINS_TEST_CONFIG_SUFFIX)
36   get_test_cc_for_arch(${arch} BUILTINS_TEST_TARGET_CC BUILTINS_TEST_TARGET_CFLAGS)
37   if (${arch} STREQUAL "armhf")
38     list(APPEND BUILTINS_TEST_TARGET_CFLAGS -fomit-frame-pointer -DCOMPILER_RT_ARMHF_TARGET)
39     string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
40   endif()
41
42   if (${arch} STREQUAL "riscv32")
43     list(APPEND BUILTINS_TEST_TARGET_CFLAGS -fforce-enable-int128)
44     string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
45   endif()
46
47   if (${arch} MATCHES "arm|aarch64|arm64" AND COMPILER_RT_HAS_FLOAT16)
48     list(APPEND BUILTINS_TEST_TARGET_CFLAGS -DCOMPILER_RT_HAS_FLOAT16)
49     string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
50   endif()
51
52   # Compute builtins available in library and add them as lit features.
53   if(APPLE)
54     # TODO: Support other Apple platforms.
55     set(BUILTIN_LIB_TARGET_NAME "clang_rt.builtins_${arch}_osx")
56   else()
57     set(BUILTIN_LIB_TARGET_NAME "clang_rt.builtins-${arch}")
58   endif()
59   if (NOT TARGET "${BUILTIN_LIB_TARGET_NAME}")
60     message(FATAL_ERROR "Target ${BUILTIN_LIB_TARGET_NAME} does not exist")
61   endif()
62   get_target_property(BUILTIN_LIB_SOURCES "${BUILTIN_LIB_TARGET_NAME}" SOURCES)
63   list(LENGTH BUILTIN_LIB_SOURCES BUILTIN_LIB_SOURCES_LENGTH)
64   if (BUILTIN_LIB_SOURCES_LENGTH EQUAL 0)
65     message(FATAL_ERROR "Failed to find source files for ${arch} builtin library")
66   endif()
67   set(BUILTINS_LIT_SOURCE_FEATURES "")
68   foreach (file_name ${BUILTIN_LIB_SOURCES})
69     # Strip off any directories and file extensions. This approach means we add
70     # add a single feature if there is a C source file or assembly override
71     # present in the builtin library.
72     # E.g.
73     # "hexagon/udivsi3.S" => "udivsi3"
74     # "udivsi3.c" => "udivsi3"
75     get_filename_component(FILE_NAME_FILTERED "${file_name}" NAME_WE)
76     list(APPEND BUILTINS_LIT_SOURCE_FEATURES "librt_has_${FILE_NAME_FILTERED}")
77   endforeach()
78
79   string(TOUPPER ${arch} ARCH_UPPER_CASE)
80   set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
81   configure_lit_site_cfg(
82     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
83     ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py
84     )
85   list(APPEND BUILTINS_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
86 endforeach()
87
88 # TODO: Add support for running tests on iOS and iOS simulator.
89
90 add_lit_testsuite(check-builtins "Running the Builtins tests"
91   ${BUILTINS_TESTSUITES}
92   DEPENDS ${BUILTINS_TEST_DEPS})
93 set_target_properties(check-builtins PROPERTIES FOLDER "Compiler-RT Misc")