[libc] Use best-fit binary trie to make malloc logarithmic (#106259)
[llvm-project.git] / libc / src / stdio / CMakeLists.txt
blobb9bc904471df9ad49ef3a2c6e1ee131772767a8b
1 # Helper function that creates an alias if a target specific implementation
2 # exists, otherwise it uses a generic one.
3 function(add_stdio_entrypoint_object name)
4   if(TARGET libc.src.stdio.${LIBC_TARGET_OS}.${name})
5     add_entrypoint_object(
6       ${name}
7       ALIAS
8       DEPENDS
9         .${LIBC_TARGET_OS}.${name}
10     )
11   elseif(TARGET libc.src.stdio.generic.${name})
12     add_entrypoint_object(
13       ${name}
14       ALIAS
15       DEPENDS
16         .generic.${name}
17     )
18   endif()
19 endfunction(add_stdio_entrypoint_object)
21 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
22   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
23 endif()
25 if(NOT LIBC_TARGET_OS_IS_BAREMETAL AND NOT LIBC_TARGET_OS_IS_GPU)
26   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
27 endif()
29 if(NOT LLVM_LIBC_FULL_BUILD)
30   list(APPEND use_system_file "COMPILE_OPTIONS" "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
31 endif()
33 add_entrypoint_object(
34   flockfile
35   SRCS
36     flockfile.cpp
37   HDRS
38     flockfile.h
39   DEPENDS
40     libc.hdr.types.FILE
41     libc.src.__support.File.file
42     libc.src.__support.File.platform_file
45 add_entrypoint_object(
46   funlockfile
47   SRCS
48     funlockfile.cpp
49   HDRS
50     funlockfile.h
51   DEPENDS
52     libc.hdr.types.FILE
53     libc.src.__support.File.file
54     libc.src.__support.File.platform_file
57 add_entrypoint_object(
58   fopencookie
59   SRCS
60     fopencookie.cpp
61   HDRS
62     fopencookie.h
63   DEPENDS
64     libc.hdr.stdio_macros
65     libc.hdr.types.off_t
66     libc.hdr.types.cookie_io_functions_t
67     libc.hdr.types.FILE
68     libc.src.__support.CPP.new
69     libc.src.__support.File.file
72 add_entrypoint_object(
73   setbuf
74   SRCS
75     setbuf.cpp
76   HDRS
77     setbuf.h
78   DEPENDS
79     libc.src.errno.errno
80     libc.hdr.types.off_t
81     libc.src.__support.File.file
82     libc.src.__support.File.platform_file
85 add_entrypoint_object(
86   setvbuf
87   SRCS
88     setvbuf.cpp
89   HDRS
90     setvbuf.h
91   DEPENDS
92     libc.src.errno.errno
93     libc.hdr.types.FILE
94     libc.src.__support.File.file
95     libc.src.__support.File.platform_file
98 list(APPEND scanf_deps
99       libc.src.__support.arg_list
100       libc.src.stdio.scanf_core.vfscanf_internal
101       libc.hdr.types.FILE
104 if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_OS_IS_GPU)
105   list(APPEND scanf_deps
106       libc.src.__support.File.file
107       libc.src.__support.File.platform_file
108       libc.src.__support.File.platform_stdin
109   )
110 endif()
112 add_entrypoint_object(
113   sscanf
114   SRCS
115     sscanf.cpp
116   HDRS
117     sscanf.h
118   DEPENDS
119     libc.src.__support.arg_list
120     libc.src.stdio.scanf_core.reader
121     libc.src.stdio.scanf_core.scanf_main
124 add_entrypoint_object(
125   vsscanf
126   SRCS
127     vsscanf.cpp
128   HDRS
129     vsscanf.h
130   DEPENDS
131     libc.src.__support.arg_list
132     libc.src.stdio.scanf_core.reader
133     libc.src.stdio.scanf_core.scanf_main
136 add_entrypoint_object(
137   fscanf
138   SRCS
139     fscanf.cpp
140   HDRS
141     fscanf.h
142   DEPENDS
143     ${scanf_deps}
146 add_entrypoint_object(
147   vfscanf
148   SRCS
149     vfscanf.cpp
150   HDRS
151     vfscanf.h
152   DEPENDS
153     ${scanf_deps}
156 add_entrypoint_object(
157   scanf
158   SRCS
159     scanf.cpp
160   HDRS
161     scanf.h
162   DEPENDS
163     ${scanf_deps}
166 add_entrypoint_object(
167   vscanf
168   SRCS
169     vscanf.cpp
170   HDRS
171     vscanf.h
172   DEPENDS
173     ${scanf_deps}
176 add_entrypoint_object(
177   sprintf
178   SRCS
179     sprintf.cpp
180   HDRS
181     sprintf.h
182   DEPENDS
183     libc.src.stdio.printf_core.printf_main
184     libc.src.stdio.printf_core.writer
187 add_entrypoint_object(
188   snprintf
189   SRCS
190     snprintf.cpp
191   HDRS
192     snprintf.h
193   DEPENDS
194     libc.src.stdio.printf_core.printf_main
195     libc.src.stdio.printf_core.writer
198 add_entrypoint_object(
199   asprintf
200   SRCS
201     asprintf.cpp
202   HDRS
203     asprintf.h
204   DEPENDS
205     libc.src.stdio.printf_core.vasprintf_internal
208 add_entrypoint_object(
209   vsprintf
210   SRCS
211     vsprintf.cpp
212   HDRS
213     vsprintf.h
214   DEPENDS
215     libc.src.stdio.printf_core.printf_main
216     libc.src.stdio.printf_core.writer
219 add_entrypoint_object(
220   vsnprintf
221   SRCS
222     vsnprintf.cpp
223   HDRS
224     vsnprintf.h
225   DEPENDS
226     libc.src.stdio.printf_core.printf_main
227     libc.src.stdio.printf_core.writer
230 add_entrypoint_object(
231   vasprintf
232   SRCS
233     vasprintf.cpp
234   HDRS
235     vasprintf.h
236   DEPENDS
237     libc.src.stdio.printf_core.vasprintf_internal
240 add_subdirectory(printf_core)
241 add_subdirectory(scanf_core)
243 add_entrypoint_object(
244   remove
245   ALIAS
246   DEPENDS
247     .${LIBC_TARGET_OS}.remove
250 add_entrypoint_object(
251   rename
252   ALIAS
253   DEPENDS
254     .${LIBC_TARGET_OS}.rename
257 add_entrypoint_object(
258   fdopen
259   ALIAS
260   DEPENDS
261     .${LIBC_TARGET_OS}.fdopen
264 # These entrypoints have multiple potential implementations.
265 add_stdio_entrypoint_object(feof)
266 add_stdio_entrypoint_object(feof_unlocked)
267 add_stdio_entrypoint_object(ferror)
268 add_stdio_entrypoint_object(ferror_unlocked)
269 add_stdio_entrypoint_object(fseek)
270 add_stdio_entrypoint_object(ftell)
271 add_stdio_entrypoint_object(fseeko)
272 add_stdio_entrypoint_object(fileno)
273 add_stdio_entrypoint_object(ftello)
274 add_stdio_entrypoint_object(fflush)
275 add_stdio_entrypoint_object(clearerr)
276 add_stdio_entrypoint_object(clearerr_unlocked)
277 add_stdio_entrypoint_object(fopen)
278 add_stdio_entrypoint_object(fclose)
279 add_stdio_entrypoint_object(fread_unlocked)
280 add_stdio_entrypoint_object(fread)
281 add_stdio_entrypoint_object(puts)
282 add_stdio_entrypoint_object(fputs)
283 add_stdio_entrypoint_object(fwrite_unlocked)
284 add_stdio_entrypoint_object(fwrite)
285 add_stdio_entrypoint_object(fputc)
286 add_stdio_entrypoint_object(putc)
287 add_stdio_entrypoint_object(putchar)
288 add_stdio_entrypoint_object(printf)
289 add_stdio_entrypoint_object(fprintf)
290 add_stdio_entrypoint_object(fgetc)
291 add_stdio_entrypoint_object(fgetc_unlocked)
292 add_stdio_entrypoint_object(getc)
293 add_stdio_entrypoint_object(getc_unlocked)
294 add_stdio_entrypoint_object(getchar)
295 add_stdio_entrypoint_object(getchar_unlocked)
296 add_stdio_entrypoint_object(fgets)
297 add_stdio_entrypoint_object(ungetc)
298 add_stdio_entrypoint_object(stdin)
299 add_stdio_entrypoint_object(stdout)
300 add_stdio_entrypoint_object(stderr)
301 add_stdio_entrypoint_object(vprintf)
302 add_stdio_entrypoint_object(vfprintf)