xref: /llvm-project/libc/src/stdio/CMakeLists.txt (revision b8f134faba3a41f47d2d05125118ea1acf512cb3)
1# Helper function that creates an alias if a target specific implementation
2# exists, otherwise it uses a generic one.
3function(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()
19endfunction(add_stdio_entrypoint_object)
20
21if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
22  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
23endif()
24
25if(NOT LIBC_TARGET_OS_IS_BAREMETAL AND NOT LIBC_TARGET_OS_IS_GPU)
26  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
27endif()
28
29if(NOT LLVM_LIBC_FULL_BUILD)
30  list(APPEND use_system_file "COMPILE_OPTIONS" "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
31endif()
32
33add_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
43)
44
45add_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
55)
56
57add_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
70)
71
72add_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
83)
84
85add_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
96)
97
98list(APPEND scanf_deps
99      libc.src.__support.arg_list
100      libc.src.stdio.scanf_core.vfscanf_internal
101      libc.hdr.types.FILE
102)
103
104if(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  )
110endif()
111
112add_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
122)
123
124add_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
134)
135
136add_entrypoint_object(
137  fscanf
138  SRCS
139    fscanf.cpp
140  HDRS
141    fscanf.h
142  DEPENDS
143    ${scanf_deps}
144)
145
146add_entrypoint_object(
147  vfscanf
148  SRCS
149    vfscanf.cpp
150  HDRS
151    vfscanf.h
152  DEPENDS
153    ${scanf_deps}
154)
155
156add_entrypoint_object(
157  scanf
158  SRCS
159    scanf.cpp
160  HDRS
161    scanf.h
162  DEPENDS
163    ${scanf_deps}
164)
165
166add_entrypoint_object(
167  vscanf
168  SRCS
169    vscanf.cpp
170  HDRS
171    vscanf.h
172  DEPENDS
173    ${scanf_deps}
174)
175
176add_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
185)
186
187add_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
196)
197
198add_entrypoint_object(
199  asprintf
200  SRCS
201    asprintf.cpp
202  HDRS
203    asprintf.h
204  DEPENDS
205    libc.src.stdio.printf_core.vasprintf_internal
206)
207
208add_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
217)
218
219add_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
228)
229
230add_entrypoint_object(
231  vasprintf
232  SRCS
233    vasprintf.cpp
234  HDRS
235    vasprintf.h
236  DEPENDS
237    libc.src.stdio.printf_core.vasprintf_internal
238)
239
240add_subdirectory(printf_core)
241add_subdirectory(scanf_core)
242
243add_entrypoint_object(
244  remove
245  ALIAS
246  DEPENDS
247    .${LIBC_TARGET_OS}.remove
248)
249
250add_entrypoint_object(
251  rename
252  ALIAS
253  DEPENDS
254    .${LIBC_TARGET_OS}.rename
255)
256
257add_entrypoint_object(
258  fdopen
259  ALIAS
260  DEPENDS
261    .${LIBC_TARGET_OS}.fdopen
262)
263
264# These entrypoints have multiple potential implementations.
265add_stdio_entrypoint_object(feof)
266add_stdio_entrypoint_object(feof_unlocked)
267add_stdio_entrypoint_object(ferror)
268add_stdio_entrypoint_object(ferror_unlocked)
269add_stdio_entrypoint_object(fseek)
270add_stdio_entrypoint_object(ftell)
271add_stdio_entrypoint_object(fseeko)
272add_stdio_entrypoint_object(fileno)
273add_stdio_entrypoint_object(ftello)
274add_stdio_entrypoint_object(fflush)
275add_stdio_entrypoint_object(clearerr)
276add_stdio_entrypoint_object(clearerr_unlocked)
277add_stdio_entrypoint_object(fopen)
278add_stdio_entrypoint_object(fclose)
279add_stdio_entrypoint_object(fread_unlocked)
280add_stdio_entrypoint_object(fread)
281add_stdio_entrypoint_object(puts)
282add_stdio_entrypoint_object(fputs)
283add_stdio_entrypoint_object(fwrite_unlocked)
284add_stdio_entrypoint_object(fwrite)
285add_stdio_entrypoint_object(fputc)
286add_stdio_entrypoint_object(putc)
287add_stdio_entrypoint_object(putchar)
288add_stdio_entrypoint_object(printf)
289add_stdio_entrypoint_object(fprintf)
290add_stdio_entrypoint_object(fgetc)
291add_stdio_entrypoint_object(fgetc_unlocked)
292add_stdio_entrypoint_object(getc)
293add_stdio_entrypoint_object(getc_unlocked)
294add_stdio_entrypoint_object(getchar)
295add_stdio_entrypoint_object(getchar_unlocked)
296add_stdio_entrypoint_object(fgets)
297add_stdio_entrypoint_object(ungetc)
298add_stdio_entrypoint_object(stdin)
299add_stdio_entrypoint_object(stdout)
300add_stdio_entrypoint_object(stderr)
301add_stdio_entrypoint_object(vprintf)
302add_stdio_entrypoint_object(vfprintf)
303