Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / UnitTest / CMakeLists.txt
blob4d384535581267d5e96473d38356c1ba5f78c857
1 function(add_unittest_framework_library name)
2   cmake_parse_arguments(
3     "TEST_LIB"
4     "" # No optional arguments
5     "" # No single value arguments
6     "SRCS;HDRS;DEPENDS" # Multi value arguments
7     ${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()
14   # The Nvidia 'nvlink' linker does not support static libraries.
15   if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
16     set(library_type OBJECT)
17   else()
18     set(library_type STATIC)
19   endif()
21   foreach(lib IN ITEMS ${name}.unit ${name}.hermetic)
22     add_library(
23       ${lib}
24       ${library_type}
25       EXCLUDE_FROM_ALL
26       ${TEST_LIB_SRCS}
27       ${TEST_LIB_HDRS}
28     )
29     target_include_directories(${lib} PUBLIC ${LIBC_SOURCE_DIR})
30     target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti)
31   endforeach()
32   target_include_directories(${name}.hermetic PRIVATE ${LIBC_BUILD_DIR}/include)
33   target_compile_options(${name}.hermetic
34       PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} -ffreestanding -nostdinc++)
36   if(TEST_LIB_DEPENDS)
37     foreach(dep IN LISTS ${TEST_LIB_DEPENDS})
38       if(TARGET ${dep}.unit)
39         add_dependencies(${name}.unit ${dep}.unit)
40       else()
41         add_dependencies(${name}.unit ${dep})
42       endif()
43       if(TARGET ${dep}.hermetic)
44         add_dependencies(${name}.hermetic ${dep}.hermetic)
45       else()
46         add_dependencies(${name}.hermetic ${dep})
47       endif()
48     endforeach()
49   endif()
50 endfunction()
52 add_unittest_framework_library(
53   LibcTest
54   SRCS
55     CmakeFilePath.cpp
56     LibcTest.cpp
57     LibcTestMain.cpp
58     TestLogger.cpp
59   HDRS
60     LibcTest.h
61     Test.h
62     TestLogger.h
63   DEPENDS
64     libc.src.__support.c_string
65     libc.src.__support.CPP.string
66     libc.src.__support.CPP.string_view
67     libc.src.__support.CPP.type_traits
68     libc.src.__support.OSUtil.osutil
69     libc.src.__support.uint128
72 set(libc_death_test_srcs LibcDeathTestExecutors.cpp)
73 if(${LIBC_TARGET_OS} STREQUAL "linux")
74   list(APPEND libc_death_test_srcs ExecuteFunctionUnix.cpp)
75 endif()
77 add_unittest_framework_library(
78   LibcDeathTestExecutors
79   SRCS
80     ${libc_death_test_srcs}
81   HDRS
82     ExecuteFunction.h
85 add_unittest_framework_library(
86   LibcHermeticTestSupport
87   SRCS
88     HermeticTestUtils.cpp
91 add_header_library(
92   string_utils
93   HDRS
94     StringUtils.h
95   DEPENDS
96     libc.src.__support.CPP.string
97     libc.src.__support.CPP.type_traits
100 add_unittest_framework_library(
101   LibcFPTestHelpers
102   SRCS
103     RoundingModeUtils.cpp
104   HDRS
105     FPMatcher.h
106     RoundingModeUtils.h
107   DEPENDS
108     LibcTest
109     libc.test.UnitTest.string_utils
110     libc.src.__support.FPUtil.fp_bits
111     libc.src.__support.FPUtil.fpbits_str
112     libc.src.__support.FPUtil.fenv_impl
113     libc.src.__support.FPUtil.rounding_mode
116 add_unittest_framework_library(
117   LibcFPExceptionHelpers
118   SRCS
119     FPExceptMatcher.cpp
120   HDRS
121     FPExceptMatcher.h
122   DEPENDS
123     LibcTest
124     libc.src.__support.FPUtil.fp_bits
125     libc.src.__support.FPUtil.fenv_impl
128 add_unittest_framework_library(
129   LibcMemoryHelpers
130   SRCS
131     MemoryMatcher.cpp
132   HDRS
133     MemoryMatcher.h
134   DEPENDS
135     LibcTest
136     libc.src.__support.CPP.span
139 add_unittest_framework_library(
140   LibcPrintfHelpers
141   SRCS
142     PrintfMatcher.cpp
143   HDRS
144     PrintfMatcher.h
145   DEPENDS
146     LibcTest
147     libc.src.__support.FPUtil.fp_bits
148     libc.src.stdio.printf_core.core_structs
149     libc.test.UnitTest.string_utils
152 add_unittest_framework_library(
153   LibcScanfHelpers
154   SRCS
155     ScanfMatcher.cpp
156   HDRS
157     ScanfMatcher.h
158   DEPENDS
159     LibcTest
160     libc.src.__support.FPUtil.fp_bits
161     libc.src.stdio.scanf_core.core_structs
162     libc.test.UnitTest.string_utils
165 add_header_library(
166   ErrnoSetterMatcher
167   HDRS
168     ErrnoSetterMatcher.h
169   DEPENDS
170     libc.src.__support.common
171     libc.src.__support.FPUtil.fp_bits
172     libc.src.__support.StringUtil.error_to_string
173     libc.src.errno.errno