1function(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 ) 9 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() 16 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) 21 22 add_libc_unittest( 23 ${name} 24 LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}" 25 "${MATH_UNITTEST_UNPARSED_ARGUMENTS}" 26 ) 27endfunction(add_fp_unittest) 28 29add_subdirectory(__support) 30add_subdirectory(ctype) 31add_subdirectory(errno) 32add_subdirectory(fenv) 33add_subdirectory(inttypes) 34add_subdirectory(math) 35add_subdirectory(string) 36add_subdirectory(stdlib) 37 38if(${LIBC_TARGET_OS} STREQUAL "linux") 39 add_subdirectory(fcntl) 40 add_subdirectory(sys) 41 add_subdirectory(unistd) 42endif() 43 44if(NOT LLVM_LIBC_FULL_BUILD) 45 return() 46endif() 47 48add_subdirectory(dirent) 49# The signal API is currently disabled as signal.h is incorrect. 50# since assert uses the signal API, we disable assert also. 51# add_subdirectory(assert) 52# add_subdirectory(signal) 53add_subdirectory(stdio) 54add_subdirectory(time) 55 56if(${LIBC_TARGET_OS} STREQUAL "linux") 57 add_subdirectory(pthread) 58endif() 59 60set(public_test ${CMAKE_CURRENT_BINARY_DIR}/public_api_test.cpp) 61 62set(entrypoints_name_list "") 63foreach(entry IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS) 64 get_target_property(entry_name ${entry} "ENTRYPOINT_NAME") 65 list(APPEND entrypoints_name_list ${entry_name}) 66endforeach() 67 68# TODO: Remove these when they are added to the TableGen. 69list(REMOVE_ITEM entrypoints_name_list "__assert_fail" "__errno_location") 70list(TRANSFORM entrypoints_name_list PREPEND "-e=") 71 72file(GLOB spec_files ${LIBC_SOURCE_DIR}/spec/*.td) 73 74# Generate api test souce code. 75add_custom_command( 76 OUTPUT ${public_test} 77 COMMAND $<TARGET_FILE:libc-prototype-testgen> -o ${public_test} 78 ${entrypoints_name_list} 79 -I ${LIBC_SOURCE_DIR} 80 ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td 81 82 DEPENDS ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td ${spec_files} 83 libc-prototype-testgen ${TARGET_PUBLIC_HEADERS} 84 llvmlibc 85) 86 87add_executable( 88 libc-api-test 89 EXCLUDE_FROM_ALL 90 ${public_test} 91) 92# Blank out default include directories to prevent accidentally including 93# system headers or our own internal headers. 94set_target_properties( 95 libc-api-test 96 PROPERTIES 97 INCLUDE_DIRECTORIES "" 98) 99target_link_libraries(libc-api-test llvmlibc) 100 101# Only include we need is the include for cpp::IsSame and our generated 102# public headers. 103target_include_directories( 104 libc-api-test BEFORE 105 PRIVATE 106 "${LIBC_SOURCE_DIR}/src/__support/CPP" 107 "${LIBC_BUILD_DIR}/include" 108) 109target_compile_options( 110 libc-api-test 111 PRIVATE 112 -ffreestanding 113) 114target_link_options( 115 libc-api-test 116 PRIVATE "-nostdlib" 117) 118set(library_files) 119foreach(library_name IN LISTS "llvmlibc") 120 get_target_property(library_file ${library_name} "LIBRARY_FILE") 121 list(APPEND library_files ${library_file}) 122endforeach() 123 124if(COMPILER_RESOURCE_DIR AND LLVM_LIBC_ENABLE_LINTING) 125 add_custom_target( 126 libc-api-test-tidy 127 VERBATIM 128 COMMAND $<TARGET_FILE:clang-tidy> --system-headers 129 --checks=-*,llvmlibc-restrict-system-libc-headers 130 "--extra-arg=-resource-dir=${COMPILER_RESOURCE_DIR}" 131 --header-filter=.* 132 --warnings-as-errors=llvmlibc-* 133 "-config={CheckOptions: [{key: llvmlibc-restrict-system-libc-headers.Includes, value: '-*, linux/*, asm/*.h, asm-generic/*.h'}]}" 134 --quiet 135 -p ${PROJECT_BINARY_DIR} 136 ${public_test} 137 DEPENDS 138 clang-tidy ${public_test} 139 ) 140 add_dependencies(libc-api-test libc-api-test-tidy) 141endif() 142 143target_link_libraries(libc-api-test 144 PRIVATE 145 ${library_files} 146) 147