Skip to content

Commit 599eade

Browse files
authored
[libc] Propagate printf config options from a single config header library. (#66979)
printf_core.parser is not yet updated to use the printf config options. It does not use them currently anyway and the corresponding parser_test should be updated to respect the config options.
1 parent 1ff958c commit 599eade

File tree

6 files changed

+46
-38
lines changed

6 files changed

+46
-38
lines changed

libc/cmake/modules/LLVMLibCHeaderRules.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,13 @@ function(add_gen_header target_name)
177177
${target_name}
178178
HDRS
179179
${out_file}
180-
DEPENDS
181-
${generated_hdr_target}
182180
)
183181

182+
# We add the dependencies separately and not list under add_header_library's
183+
# DEPENDS option above. This is because, deps of add_header_library are
184+
# used with target_link_libraries.
185+
add_dependencies(${fq_target_name} ${generated_hdr_target})
186+
184187
set_target_properties(
185188
${fq_target_name}
186189
PROPERTIES

libc/cmake/modules/LLVMLibCLibraryRules.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ function(create_header_library fq_target_name)
173173
target_sources(${fq_target_name} INTERFACE ${ADD_HEADER_HDRS})
174174
if(ADD_HEADER_DEPENDS)
175175
add_dependencies(${fq_target_name} ${ADD_HEADER_DEPENDS})
176+
target_link_libraries(${fq_target_name} INTERFACE ${ADD_HEADER_DEPENDS})
176177
endif()
177178
if(ADD_HEADER_COMPILE_OPTIONS)
178179
target_compile_options(${fq_target_name} INTERFACE ${ADD_HEADER_COMPILE_OPTIONS})

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ function(create_object_library fq_target_name)
383383

384384
if(fq_deps_list)
385385
add_dependencies(${fq_target_name} ${fq_deps_list})
386+
# Add deps as link libraries to inherit interface compile and link options.
387+
target_link_libraries(${fq_target_name} PUBLIC ${fq_deps_list})
386388
endif()
387389

388390
if(NOT ADD_OBJECT_CXX_STANDARD)

libc/src/__support/StringUtil/tables/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ add_header_library(
2828
add_header_library(
2929
linux_platform_errors
3030
HDRS
31-
linux_platform_errors
31+
linux_platform_errors.h
3232
DEPENDS
3333
.linux_extension_errors
3434
.posix_errors
@@ -38,7 +38,7 @@ add_header_library(
3838
add_header_library(
3939
minimal_platform_errors
4040
HDRS
41-
minimal_platform_errors
41+
minimal_platform_errors.h
4242
DEPENDS
4343
.stdc_errors
4444
)
@@ -73,7 +73,7 @@ add_header_library(
7373
add_header_library(
7474
linux_platform_signals
7575
HDRS
76-
linux_platform_signals
76+
linux_platform_signals.h
7777
DEPENDS
7878
.linux_extension_signals
7979
.posix_signals
@@ -83,7 +83,7 @@ add_header_library(
8383
add_header_library(
8484
minimal_platform_signals
8585
HDRS
86-
minimal_platform_signals
86+
minimal_platform_signals.h
8787
DEPENDS
8888
.stdc_signals
8989
)

libc/src/stdio/CMakeLists.txt

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
2626
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
2727
endif()
2828

29+
if(NOT LLVM_LIBC_FULL_BUILD)
30+
list(APPEND use_system_file "COMPILE_OPTIONS" "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
31+
endif()
32+
2933
add_entrypoint_object(
3034
flockfile
3135
SRCS
@@ -111,8 +115,6 @@ if(LLVM_LIBC_FULL_BUILD)
111115
libc.src.__support.File.platform_file
112116
libc.src.__support.File.platform_stdin
113117
)
114-
else()
115-
list(APPEND scanf_copts "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
116118
endif()
117119

118120
add_entrypoint_object(
@@ -135,8 +137,7 @@ add_entrypoint_object(
135137
fscanf.h
136138
DEPENDS
137139
${scanf_deps}
138-
COMPILE_OPTIONS
139-
${scanf_copts}
140+
${use_system_file}
140141
)
141142

142143
add_entrypoint_object(
@@ -147,8 +148,7 @@ add_entrypoint_object(
147148
scanf.h
148149
DEPENDS
149150
${scanf_deps}
150-
COMPILE_OPTIONS
151-
${scanf_copts}
151+
${use_system_file}
152152
)
153153

154154
add_entrypoint_object(
@@ -178,27 +178,12 @@ list(APPEND printf_deps
178178
libc.src.stdio.printf_core.vfprintf_internal
179179
)
180180

181-
if(LIBC_CONF_PRINTF_DISABLE_FLOAT)
182-
list(APPEND printf_copts "-DLIBC_COPT_PRINTF_DISABLE_FLOAT")
183-
endif()
184-
if(LIBC_CONF_PRINTF_DISABLE_INDEX_MODE)
185-
list(APPEND printf_copts "-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE")
186-
endif()
187-
if(LIBC_CONF_PRINTF_DISABLE_WRITE_INT)
188-
list(APPEND printf_copts "-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT")
189-
endif()
190-
if(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE)
191-
list(APPEND printf_copts "-DLIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE")
192-
endif()
193-
194181
if(LLVM_LIBC_FULL_BUILD)
195182
list(APPEND printf_deps
196183
libc.src.__support.File.file
197184
libc.src.__support.File.platform_file
198185
libc.src.__support.File.platform_stdout
199186
)
200-
else()
201-
list(APPEND printf_copts "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
202187
endif()
203188

204189
add_entrypoint_object(
@@ -209,8 +194,7 @@ add_entrypoint_object(
209194
printf.h
210195
DEPENDS
211196
${printf_deps}
212-
COMPILE_OPTIONS
213-
${printf_copts}
197+
${use_system_file}
214198
)
215199

216200
add_entrypoint_object(
@@ -222,8 +206,7 @@ add_entrypoint_object(
222206
DEPENDS
223207
libc.src.__support.arg_list
224208
libc.src.stdio.printf_core.vfprintf_internal
225-
COMPILE_OPTIONS
226-
${printf_copts}
209+
${use_system_file}
227210
)
228211

229212
add_entrypoint_object(
@@ -256,8 +239,7 @@ add_entrypoint_object(
256239
vprintf.h
257240
DEPENDS
258241
${printf_deps}
259-
COMPILE_OPTIONS
260-
${printf_copts}
242+
${use_system_file}
261243
)
262244

263245
add_entrypoint_object(
@@ -269,8 +251,7 @@ add_entrypoint_object(
269251
DEPENDS
270252
libc.src.__support.arg_list
271253
libc.src.stdio.printf_core.vfprintf_internal
272-
COMPILE_OPTIONS
273-
${printf_copts}
254+
${use_system_file}
274255
)
275256

276257
add_subdirectory(printf_core)

libc/src/stdio/printf_core/CMakeLists.txt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
if(LIBC_CONF_PRINTF_DISABLE_FLOAT)
2+
list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_FLOAT")
3+
endif()
4+
if(LIBC_CONF_PRINTF_DISABLE_INDEX_MODE)
5+
list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE")
6+
endif()
7+
if(LIBC_CONF_PRINTF_DISABLE_WRITE_INT)
8+
list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT")
9+
endif()
10+
if(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE)
11+
list(APPEND printf_config_copts "-DLIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE")
12+
endif()
13+
if(printf_config_copts)
14+
list(PREPEND printf_config_copts "COMPILE_OPTIONS")
15+
endif()
16+
17+
add_header_library(
18+
printf_config
19+
HDRS
20+
printf_config.h
21+
${printf_config_copts}
22+
)
123

224
add_header_library(
325
core_structs
@@ -31,11 +53,11 @@ add_object_library(
3153
HDRS
3254
writer.h
3355
DEPENDS
56+
.core_structs
3457
libc.src.__support.CPP.string_view
3558
libc.src.__support.macros.optimization
3659
libc.src.string.memory_utils.inline_memcpy
3760
libc.src.string.memory_utils.inline_memset
38-
.core_structs
3961
)
4062

4163
add_object_library(
@@ -57,6 +79,7 @@ add_object_library(
5779
DEPENDS
5880
.writer
5981
.core_structs
82+
.printf_config
6083
libc.src.__support.CPP.limits
6184
libc.src.__support.CPP.span
6285
libc.src.__support.CPP.string_view
@@ -69,8 +92,6 @@ add_object_library(
6992
libc.src.__support.uint128
7093
libc.src.__support.integer_to_string
7194
libc.src.__support.float_to_string
72-
COMPILE_OPTIONS
73-
${printf_copts}
7495
)
7596

7697

0 commit comments

Comments
 (0)