Skip to content

Commit 4462cdb

Browse files
[libc] Fix scanf cmake for targets without FILE
Another followup fix to #121215 The new cmake wouldn't define the readerat all if the target wasn't GPU or didn't have a definition of FILE. This patch rewrites the cmake to be more general. As a followup, I'd like to make `use_system_file` consistent between /test and /src. Currently in /src it includes the `COMPILE_OPTIONS` and in /test it does not.
1 parent d1dde17 commit 4462cdb

File tree

2 files changed

+34
-40
lines changed

2 files changed

+34
-40
lines changed

libc/src/stdio/scanf_core/CMakeLists.txt

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ if(scanf_config_copts)
88
list(PREPEND scanf_config_copts "COMPILE_OPTIONS")
99
endif()
1010

11+
12+
list(APPEND file_deps
13+
libc.hdr.types.FILE
14+
)
15+
if(LIBC_TARGET_OS_IS_GPU)
16+
list(APPEND file_deps
17+
libc.src.stdio.getc
18+
libc.src.stdio.ungetc
19+
libc.src.stdio.ferror
20+
)
21+
elseif(LLVM_LIBC_FULL_BUILD)
22+
list(APPEND file_deps
23+
libc.src.__support.File.file
24+
)
25+
endif()
26+
1127
add_header_library(
1228
scanf_config
1329
HDRS
@@ -52,30 +68,19 @@ add_object_library(
5268
.converter
5369
.core_structs
5470
libc.src.__support.arg_list
71+
${file_deps}
72+
${use_system_file}
5573
)
5674

57-
if(LIBC_TARGET_OS_IS_GPU)
5875
add_header_library(
5976
reader
6077
HDRS
6178
reader.h
6279
DEPENDS
6380
libc.src.__support.macros.attributes
64-
libc.src.stdio.getc
65-
libc.src.stdio.ungetc
66-
)
67-
elseif((TARGET libc.src.__support.File.file) OR (NOT LLVM_LIBC_FULL_BUILD))
68-
add_header_library(
69-
reader
70-
HDRS
71-
reader.h
72-
DEPENDS
73-
libc.src.__support.macros.attributes
74-
libc.hdr.types.FILE
75-
libc.src.__support.File.file
81+
${file_deps}
7682
${use_system_file}
7783
)
78-
endif()
7984

8085
add_object_library(
8186
converter
@@ -103,33 +108,19 @@ add_object_library(
103108
libc.src.__support.CPP.limits
104109
libc.src.__support.char_vector
105110
libc.src.__support.str_to_float
111+
${file_deps}
112+
${use_system_file}
106113
)
107114

108-
if(LIBC_TARGET_OS_IS_GPU)
109-
add_header_library(
110-
vfscanf_internal
111-
HDRS
112-
vfscanf_internal.h
113-
DEPENDS
114-
.reader
115-
.scanf_main
116-
libc.include.stdio
117-
libc.src.__support.arg_list
118-
libc.src.stdio.getc
119-
libc.src.stdio.ungetc
120-
libc.src.stdio.ferror
121-
)
122-
elseif(TARGET libc.src.__support.File.file OR (NOT LLVM_LIBC_FULL_BUILD))
123-
add_header_library(
115+
#TODO: condense the file-related code as possible.
116+
add_header_library(
124117
vfscanf_internal
125118
HDRS
126119
vfscanf_internal.h
127120
DEPENDS
128121
.reader
129122
.scanf_main
130-
libc.include.stdio
131-
libc.src.__support.File.file
132123
libc.src.__support.arg_list
124+
${file_deps}
133125
${use_system_file}
134-
)
135-
endif()
126+
)

libc/test/src/stdio/scanf_core/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
if(NOT(LLVM_LIBC_FULL_BUILD))
2+
# in overlay mode, use the system's file to test the reader.
3+
set(use_system_file "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
4+
endif()
5+
16
add_libc_unittest(
27
parser_test
38
SUITE
@@ -22,14 +27,10 @@ add_libc_unittest(
2227
DEPENDS
2328
libc.src.stdio.scanf_core.reader
2429
libc.src.__support.CPP.string_view
30+
COMPILE_OPTIONS
31+
${use_system_file}
2532
)
2633

27-
if(NOT (TARGET libc.src.__support.File.file))
28-
# Not all platforms have a file implementation. If file is unvailable,
29-
# then we must skip all the parts that need file.
30-
return()
31-
endif()
32-
3334
add_libc_unittest(
3435
converter_test
3536
SUITE
@@ -40,4 +41,6 @@ add_libc_unittest(
4041
libc.src.stdio.scanf_core.reader
4142
libc.src.stdio.scanf_core.converter
4243
libc.src.__support.CPP.string_view
44+
COMPILE_OPTIONS
45+
${use_system_file}
4346
)

0 commit comments

Comments
 (0)