[NFC] Fix pattern name.
[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   append_list_if(COMPILER_RT_HAS_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTINS_TEST_TARGET_CFLAGS)
48   string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
49
50   # Compute builtins available in library and add them as lit features.
51   if(APPLE)
52     # TODO: Support other Apple platforms.
53     set(BUILTIN_LIB_TARGET_NAME "clang_rt.builtins_${arch}_osx")
54   else()
55     set(BUILTIN_LIB_TARGET_NAME "clang_rt.builtins-${arch}")
56   endif()
57   if (NOT TARGET "${BUILTIN_LIB_TARGET_NAME}")
58     message(FATAL_ERROR "Target ${BUILTIN_LIB_TARGET_NAME} does not exist")
59   endif()
60   get_target_property(BUILTIN_LIB_SOURCES "${BUILTIN_LIB_TARGET_NAME}" SOURCES)
61   list(LENGTH BUILTIN_LIB_SOURCES BUILTIN_LIB_SOURCES_LENGTH)
62   if (BUILTIN_LIB_SOURCES_LENGTH EQUAL 0)
63     message(FATAL_ERROR "Failed to find source files for ${arch} builtin library")
64   endif()
65   set(BUILTINS_LIT_SOURCE_FEATURES "")
66   foreach (file_name ${BUILTIN_LIB_SOURCES})
67     # Strip off any directories and file extensions. This approach means we add
68     # add a single feature if there is a C source file or assembly override
69     # present in the builtin library.
70     # E.g.
71     # "hexagon/udivsi3.S" => "udivsi3"
72     # "udivsi3.c" => "udivsi3"
73     get_filename_component(FILE_NAME_FILTERED "${file_name}" NAME_WE)
74     list(APPEND BUILTINS_LIT_SOURCE_FEATURES "librt_has_${FILE_NAME_FILTERED}")
75   endforeach()
76
77   string(TOUPPER ${arch} ARCH_UPPER_CASE)
78   set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
79   configure_lit_site_cfg(
80     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
81     ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py
82     )
83   list(APPEND BUILTINS_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
84 endforeach()
85
86 # TODO: Add support for running tests on iOS and iOS simulator.
87
88 add_lit_testsuite(check-builtins "Running the Builtins tests"
89   ${BUILTINS_TESTSUITES}
90   DEPENDS ${BUILTINS_TEST_DEPS})
91 set_target_properties(check-builtins PROPERTIES FOLDER "Compiler-RT Misc")