210 lines · plain
1function(add_unittest_framework_library name)2 cmake_parse_arguments(3 "TEST_LIB"4 "" # No optional arguments5 "" # No single value arguments6 "SRCS;HDRS;DEPENDS" # Multi value arguments7 ${ARGN}8 )9 if(NOT TEST_LIB_SRCS)10 message(FATAL_ERROR "'add_unittest_framework_library' requires SRCS; for "11 "header only libraries, use 'add_header_library'")12 endif()13 14 foreach(lib IN ITEMS ${name}.unit ${name}.hermetic)15 add_library(16 ${lib}17 STATIC18 EXCLUDE_FROM_ALL19 ${TEST_LIB_SRCS}20 ${TEST_LIB_HDRS}21 )22 target_include_directories(${lib} PRIVATE ${LIBC_SOURCE_DIR})23 if(TARGET libc.src.time.clock)24 target_compile_definitions(${lib} PRIVATE TARGET_SUPPORTS_CLOCK)25 endif()26 endforeach()27 28 if(LLVM_LIBC_FULL_BUILD)29 # TODO: Build test framework with LIBC_FULL_BUILD in full build mode after30 # making LibcFPExceptionHelpers and LibcDeathTestExecutors hermetic.31 set(LLVM_LIBC_FULL_BUILD "")32 _get_common_test_compile_options(compile_options "" "")33 target_compile_options(${name}.unit PRIVATE ${compile_options})34 set(LLVM_LIBC_FULL_BUILD ON)35 else()36 _get_common_test_compile_options(compile_options "" "")37 target_compile_options(${name}.unit PRIVATE ${compile_options})38 endif()39 40 _get_hermetic_test_compile_options(compile_options "")41 target_include_directories(${name}.hermetic PRIVATE ${LIBC_INCLUDE_DIR})42 target_compile_options(${name}.hermetic PRIVATE ${compile_options} -nostdinc++)43 44 if(TEST_LIB_DEPENDS)45 foreach(dep IN ITEMS ${TEST_LIB_DEPENDS})46 if(TARGET ${dep}.unit)47 add_dependencies(${name}.unit ${dep}.unit)48 else()49 add_dependencies(${name}.unit ${dep})50 endif()51 if(TARGET ${dep}.hermetic)52 add_dependencies(${name}.hermetic ${dep}.hermetic)53 else()54 add_dependencies(${name}.hermetic ${dep})55 endif()56 endforeach()57 endif()58endfunction()59 60add_unittest_framework_library(61 LibcTest62 SRCS63 CmakeFilePath.cpp64 LibcTest.cpp65 LibcTestMain.cpp66 TestLogger.cpp67 HDRS68 LibcTest.h69 Test.h70 TestLogger.h71 DEPENDS72 libc.hdr.stdint_proxy73 libc.src.__support.big_int74 libc.src.__support.c_string75 libc.src.__support.CPP.string76 libc.src.__support.CPP.string_view77 libc.src.__support.CPP.type_traits78 libc.src.__support.fixed_point.fx_rep79 libc.src.__support.macros.properties.compiler80 libc.src.__support.macros.properties.types81 libc.src.__support.OSUtil.osutil82 libc.src.__support.uint12883)84 85set(libc_death_test_srcs LibcDeathTestExecutors.cpp)86if(${LIBC_TARGET_OS} STREQUAL "linux" OR ${LIBC_TARGET_OS} STREQUAL "darwin")87 list(APPEND libc_death_test_srcs ExecuteFunctionUnix.cpp)88endif()89 90add_unittest_framework_library(91 LibcDeathTestExecutors92 SRCS93 ${libc_death_test_srcs}94 HDRS95 ExecuteFunction.h96 DEPENDS97 libc.hdr.stdint_proxy98)99 100add_unittest_framework_library(101 LibcHermeticTestSupport102 SRCS103 HermeticTestUtils.cpp104 DEPENDS105 libc.hdr.stdint_proxy106)107 108add_header_library(109 string_utils110 HDRS111 StringUtils.h112 DEPENDS113 libc.src.__support.big_int114 libc.src.__support.CPP.string115 libc.src.__support.CPP.type_traits116)117 118add_unittest_framework_library(119 LibcFPTestHelpers120 SRCS121 FEnvSafeTest.cpp122 RoundingModeUtils.cpp123 HDRS124 FEnvSafeTest.h125 FPMatcher.h126 RoundingModeUtils.h127 DEPENDS128 LibcTest129 libc.test.UnitTest.ErrnoCheckingTest130 libc.test.UnitTest.string_utils131 libc.src.__support.CPP.array132 libc.src.__support.FPUtil.fp_bits133 libc.src.__support.FPUtil.fpbits_str134 libc.src.__support.FPUtil.fenv_impl135 libc.src.__support.FPUtil.rounding_mode136)137 138add_unittest_framework_library(139 LibcFPExceptionHelpers140 SRCS141 FPExceptMatcher.cpp142 HDRS143 FPExceptMatcher.h144 DEPENDS145 LibcTest146 libc.src.__support.FPUtil.fp_bits147 libc.src.__support.FPUtil.fenv_impl148 libc.hdr.types.fenv_t149)150 151add_unittest_framework_library(152 LibcMemoryHelpers153 SRCS154 MemoryMatcher.cpp155 HDRS156 MemoryMatcher.h157 DEPENDS158 LibcTest159 libc.src.__support.CPP.span160)161 162add_unittest_framework_library(163 LibcPrintfHelpers164 SRCS165 PrintfMatcher.cpp166 HDRS167 PrintfMatcher.h168 DEPENDS169 LibcTest170 libc.hdr.stdint_proxy171 libc.src.__support.FPUtil.fp_bits172 libc.src.stdio.printf_core.core_structs173 libc.test.UnitTest.string_utils174)175 176add_unittest_framework_library(177 LibcScanfHelpers178 SRCS179 ScanfMatcher.cpp180 HDRS181 ScanfMatcher.h182 DEPENDS183 LibcTest184 libc.hdr.stdint_proxy185 libc.src.__support.FPUtil.fp_bits186 libc.src.stdio.scanf_core.core_structs187 libc.test.UnitTest.string_utils188)189 190add_header_library(191 ErrnoSetterMatcher192 HDRS193 ErrnoSetterMatcher.h194 DEPENDS195 libc.src.__support.common196 libc.src.__support.FPUtil.fp_bits197 libc.src.__support.StringUtil.error_to_string198 libc.src.errno.errno199)200 201add_header_library(202 ErrnoCheckingTest203 HDRS204 ErrnoCheckingTest.h205 DEPENDS206 libc.src.__support.common207 libc.src.__support.macros.properties.architectures208 libc.src.errno.errno209)210