[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / CMakeLists.txt
blobbf992ce2a8c25b2b5ad6ffea52e0a9bbda7fc11f
1 function(add_fp_unittest name)
2   cmake_parse_arguments(
3     "MATH_UNITTEST"
4     "NEED_MPFR" # Optional arguments
5     "" # Single value arguments
6     "LINK_LIBRARIES" # Multi-value arguments
7     ${ARGN}
8   )
10   if(MATH_UNITTEST_NEED_MPFR)
11     if(NOT LIBC_TESTS_CAN_USE_MPFR)
12       message("WARNING: Math test ${name} will be skipped as MPFR library is not available.")
13       return()
14     endif()
15   endif()
17   if(MATH_UNITTEST_NEED_MPFR)
18     list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPFRWrapper -lmpfr -lgmp)
19   endif()
20   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
22   add_libc_unittest(
23     ${name}
24     LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
25     "${MATH_UNITTEST_UNPARSED_ARGUMENTS}"
26   )
27 endfunction(add_fp_unittest)
29 add_subdirectory(__support)
30 add_subdirectory(ctype)
31 add_subdirectory(errno)
32 add_subdirectory(fenv)
33 add_subdirectory(math)
34 add_subdirectory(string)
35 add_subdirectory(stdlib)
36 add_subdirectory(inttypes)
37 add_subdirectory(stdio)
39 if(${LIBC_TARGET_OS} STREQUAL "linux")
40   add_subdirectory(fcntl)
41   add_subdirectory(sched)
42   add_subdirectory(sys)
43   add_subdirectory(termios)
44   add_subdirectory(unistd)
45 endif()
47 if(NOT LLVM_LIBC_FULL_BUILD)
48   return()
49 endif()
51 add_subdirectory(dirent)
52 add_subdirectory(assert)
53 add_subdirectory(network)
54 add_subdirectory(setjmp)
55 add_subdirectory(signal)
56 add_subdirectory(spawn)
57 add_subdirectory(time)
59 if(${LIBC_TARGET_OS} STREQUAL "linux")
60   add_subdirectory(pthread)
61 endif()
63 if(LLVM_RUNTIMES_BUILD OR LIBC_HDRGEN_EXE)
64   # The public API test below uses tablegen to generate the test
65   # source file. Since tablegen is not available during a runtimes
66   # build, we will skip the test.
67   # If a different libc-hdrgen binary is being used, then also we
68   # skip the api-test as we cannot generate the test source file.
69   return()
70 endif()
72 set(public_test ${CMAKE_CURRENT_BINARY_DIR}/public_api_test.cpp)
74 set(entrypoints_name_list "")
75 foreach(entry IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
76   get_target_property(entry_name ${entry} "ENTRYPOINT_NAME")
77   list(APPEND entrypoints_name_list ${entry_name})
78 endforeach()
80 # TODO: Remove these when they are added to the TableGen.
81 list(REMOVE_ITEM entrypoints_name_list "__assert_fail" "__errno_location")
82 list(TRANSFORM entrypoints_name_list PREPEND "-e=")
84 file(GLOB spec_files ${LIBC_SOURCE_DIR}/spec/*.td)
86 # Generate api test souce code.
87 add_custom_command(
88   OUTPUT ${public_test}
89   COMMAND $<TARGET_FILE:libc-prototype-testgen> -o ${public_test}
90           ${entrypoints_name_list}
91           -I ${LIBC_SOURCE_DIR}
92           ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
94   DEPENDS ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td ${spec_files}
95           libc-prototype-testgen ${TARGET_PUBLIC_HEADERS}
96           ${LIBC_TARGET}
99 add_custom_target(libc-api-test)
100 set(
101   allocator_entrypoints 
102     libc.src.stdlib.malloc
103     libc.src.stdlib.calloc
104     libc.src.stdlib.realloc
105     libc.src.stdlib.aligned_alloc
106     libc.src.stdlib.free
108 set(api-test-entrypoints ${TARGET_LLVMLIBC_ENTRYPOINTS})
109 list(REMOVE_ITEM api-test-entrypoints ${allocator_entrypoints})
110 add_integration_test(
111   api-test
112   SUITE
113     libc-api-test
114   SRCS
115     ${public_test}
116   STARTUP
117     libc.startup.linux.crt1
118   DEPENDS
119     ${api-test-entrypoints}
122 if(COMPILER_RESOURCE_DIR AND LLVM_LIBC_ENABLE_LINTING)
123   add_custom_target(
124     libc-api-test-tidy
125     VERBATIM
126     COMMAND $<TARGET_FILE:clang-tidy> --system-headers
127       --checks=-*,llvmlibc-restrict-system-libc-headers
128       "--extra-arg=-resource-dir=${COMPILER_RESOURCE_DIR}"
129       --header-filter=.*
130       --warnings-as-errors=llvmlibc-*
131       "-config={CheckOptions: [{key: llvmlibc-restrict-system-libc-headers.Includes, value: '-*, linux/*, asm/*.h, asm-generic/*.h'}]}"
132       --quiet
133       -p ${PROJECT_BINARY_DIR}
134       ${public_test}
135     DEPENDS
136       clang-tidy ${public_test}
137   )
138   add_dependencies(libc-api-test libc-api-test-tidy)
139 endif()