Skip to content

[libc] Propagate printf config options from a single config header library. #66979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions libc/cmake/modules/LLVMLibCHeaderRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ function(add_gen_header target_name)
${target_name}
HDRS
${out_file}
DEPENDS
${generated_hdr_target}
)

# We add the dependencies separately and not list under add_header_library's
# DEPENDS option above. This is because, deps of add_header_library are
# used with target_link_libraries.
add_dependencies(${fq_target_name} ${generated_hdr_target})

set_target_properties(
${fq_target_name}
PROPERTIES
Expand Down
1 change: 1 addition & 0 deletions libc/cmake/modules/LLVMLibCLibraryRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function(create_header_library fq_target_name)
target_sources(${fq_target_name} INTERFACE ${ADD_HEADER_HDRS})
if(ADD_HEADER_DEPENDS)
add_dependencies(${fq_target_name} ${ADD_HEADER_DEPENDS})
target_link_libraries(${fq_target_name} INTERFACE ${ADD_HEADER_DEPENDS})
endif()
if(ADD_HEADER_COMPILE_OPTIONS)
target_compile_options(${fq_target_name} INTERFACE ${ADD_HEADER_COMPILE_OPTIONS})
Expand Down
2 changes: 2 additions & 0 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ function(create_object_library fq_target_name)

if(fq_deps_list)
add_dependencies(${fq_target_name} ${fq_deps_list})
# Add deps as link libraries to inherit interface compile and link options.
target_link_libraries(${fq_target_name} PUBLIC ${fq_deps_list})
endif()

if(NOT ADD_OBJECT_CXX_STANDARD)
Expand Down
8 changes: 4 additions & 4 deletions libc/src/__support/StringUtil/tables/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ add_header_library(
add_header_library(
linux_platform_errors
HDRS
linux_platform_errors
linux_platform_errors.h
DEPENDS
.linux_extension_errors
.posix_errors
Expand All @@ -38,7 +38,7 @@ add_header_library(
add_header_library(
minimal_platform_errors
HDRS
minimal_platform_errors
minimal_platform_errors.h
DEPENDS
.stdc_errors
)
Expand Down Expand Up @@ -73,7 +73,7 @@ add_header_library(
add_header_library(
linux_platform_signals
HDRS
linux_platform_signals
linux_platform_signals.h
DEPENDS
.linux_extension_signals
.posix_signals
Expand All @@ -83,7 +83,7 @@ add_header_library(
add_header_library(
minimal_platform_signals
HDRS
minimal_platform_signals
minimal_platform_signals.h
DEPENDS
.stdc_signals
)
39 changes: 10 additions & 29 deletions libc/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
endif()

if(NOT LLVM_LIBC_FULL_BUILD)
list(APPEND use_system_file "COMPILE_OPTIONS" "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
endif()

add_entrypoint_object(
flockfile
SRCS
Expand Down Expand Up @@ -111,8 +115,6 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.__support.File.platform_file
libc.src.__support.File.platform_stdin
)
else()
list(APPEND scanf_copts "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
endif()

add_entrypoint_object(
Expand All @@ -135,8 +137,7 @@ add_entrypoint_object(
fscanf.h
DEPENDS
${scanf_deps}
COMPILE_OPTIONS
${scanf_copts}
${use_system_file}
)

add_entrypoint_object(
Expand All @@ -147,8 +148,7 @@ add_entrypoint_object(
scanf.h
DEPENDS
${scanf_deps}
COMPILE_OPTIONS
${scanf_copts}
${use_system_file}
)

add_entrypoint_object(
Expand Down Expand Up @@ -178,27 +178,12 @@ list(APPEND printf_deps
libc.src.stdio.printf_core.vfprintf_internal
)

if(LIBC_CONF_PRINTF_DISABLE_FLOAT)
list(APPEND printf_copts "-DLIBC_COPT_PRINTF_DISABLE_FLOAT")
endif()
if(LIBC_CONF_PRINTF_DISABLE_INDEX_MODE)
list(APPEND printf_copts "-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE")
endif()
if(LIBC_CONF_PRINTF_DISABLE_WRITE_INT)
list(APPEND printf_copts "-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT")
endif()
if(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE)
list(APPEND printf_copts "-DLIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE")
endif()

if(LLVM_LIBC_FULL_BUILD)
list(APPEND printf_deps
libc.src.__support.File.file
libc.src.__support.File.platform_file
libc.src.__support.File.platform_stdout
)
else()
list(APPEND printf_copts "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")
endif()

add_entrypoint_object(
Expand All @@ -209,8 +194,7 @@ add_entrypoint_object(
printf.h
DEPENDS
${printf_deps}
COMPILE_OPTIONS
${printf_copts}
${use_system_file}
)

add_entrypoint_object(
Expand All @@ -222,8 +206,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.arg_list
libc.src.stdio.printf_core.vfprintf_internal
COMPILE_OPTIONS
${printf_copts}
${use_system_file}
)

add_entrypoint_object(
Expand Down Expand Up @@ -256,8 +239,7 @@ add_entrypoint_object(
vprintf.h
DEPENDS
${printf_deps}
COMPILE_OPTIONS
${printf_copts}
${use_system_file}
)

add_entrypoint_object(
Expand All @@ -269,8 +251,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.arg_list
libc.src.stdio.printf_core.vfprintf_internal
COMPILE_OPTIONS
${printf_copts}
${use_system_file}
)

add_subdirectory(printf_core)
Expand Down
27 changes: 24 additions & 3 deletions libc/src/stdio/printf_core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
if(LIBC_CONF_PRINTF_DISABLE_FLOAT)
list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_FLOAT")
endif()
if(LIBC_CONF_PRINTF_DISABLE_INDEX_MODE)
list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE")
endif()
if(LIBC_CONF_PRINTF_DISABLE_WRITE_INT)
list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT")
endif()
if(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE)
list(APPEND printf_config_copts "-DLIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE")
endif()
if(printf_config_copts)
list(PREPEND printf_config_copts "COMPILE_OPTIONS")
endif()

add_header_library(
printf_config
HDRS
printf_config.h
${printf_config_copts}
)

add_header_library(
core_structs
Expand Down Expand Up @@ -31,11 +53,11 @@ add_object_library(
HDRS
writer.h
DEPENDS
.core_structs
libc.src.__support.CPP.string_view
libc.src.__support.macros.optimization
libc.src.string.memory_utils.inline_memcpy
libc.src.string.memory_utils.inline_memset
.core_structs
)

add_object_library(
Expand All @@ -57,6 +79,7 @@ add_object_library(
DEPENDS
.writer
.core_structs
.printf_config
libc.src.__support.CPP.limits
libc.src.__support.CPP.span
libc.src.__support.CPP.string_view
Expand All @@ -69,8 +92,6 @@ add_object_library(
libc.src.__support.uint128
libc.src.__support.integer_to_string
libc.src.__support.float_to_string
COMPILE_OPTIONS
${printf_copts}
)


Expand Down