[libc-commits] [libc] [libc] Propagate printf config options from a single config header library. (PR #66979)
Siva Chandra via libc-commits
libc-commits at lists.llvm.org
Mon Sep 25 15:38:21 PDT 2023
https://github.com/sivachandra updated https://github.com/llvm/llvm-project/pull/66979
>From 2a2365982cd3d973ee4247ba42c167ad1ba7edca Mon Sep 17 00:00:00 2001
From: Siva Chandra Reddy <sivachandra at google.com>
Date: Mon, 25 Sep 2023 22:36:48 +0000
Subject: [PATCH] [libc] Propagate printf config options from a single config
header library.
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.
---
libc/cmake/modules/LLVMLibCLibraryRules.cmake | 1 +
libc/cmake/modules/LLVMLibCObjectRules.cmake | 2 +
.../StringUtil/tables/CMakeLists.txt | 8 ++--
libc/src/stdio/CMakeLists.txt | 39 +++++--------------
libc/src/stdio/printf_core/CMakeLists.txt | 27 +++++++++++--
5 files changed, 41 insertions(+), 36 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCLibraryRules.cmake b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
index 76852f714afd3a8..e6cfd79e65a085a 100644
--- a/libc/cmake/modules/LLVMLibCLibraryRules.cmake
+++ b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
@@ -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})
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index c10b81f1af8cba3..7caa3b2db75dd2f 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -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)
diff --git a/libc/src/__support/StringUtil/tables/CMakeLists.txt b/libc/src/__support/StringUtil/tables/CMakeLists.txt
index faba4fdb86b7d8c..b7bb33ee0a0fe28 100644
--- a/libc/src/__support/StringUtil/tables/CMakeLists.txt
+++ b/libc/src/__support/StringUtil/tables/CMakeLists.txt
@@ -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
@@ -38,7 +38,7 @@ add_header_library(
add_header_library(
minimal_platform_errors
HDRS
- minimal_platform_errors
+ minimal_platform_errors.h
DEPENDS
.stdc_errors
)
@@ -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
@@ -83,7 +83,7 @@ add_header_library(
add_header_library(
minimal_platform_signals
HDRS
- minimal_platform_signals
+ minimal_platform_signals.h
DEPENDS
.stdc_signals
)
diff --git a/libc/src/stdio/CMakeLists.txt b/libc/src/stdio/CMakeLists.txt
index 9c24c567b6c1d5b..62f33a3497fd601 100644
--- a/libc/src/stdio/CMakeLists.txt
+++ b/libc/src/stdio/CMakeLists.txt
@@ -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(
fflush
SRCS
@@ -137,8 +141,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(
@@ -161,8 +163,7 @@ add_entrypoint_object(
fscanf.h
DEPENDS
${scanf_deps}
- COMPILE_OPTIONS
- ${scanf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -173,8 +174,7 @@ add_entrypoint_object(
scanf.h
DEPENDS
${scanf_deps}
- COMPILE_OPTIONS
- ${scanf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -204,27 +204,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(
@@ -235,8 +220,7 @@ add_entrypoint_object(
printf.h
DEPENDS
${printf_deps}
- COMPILE_OPTIONS
- ${printf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -248,8 +232,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(
@@ -282,8 +265,7 @@ add_entrypoint_object(
vprintf.h
DEPENDS
${printf_deps}
- COMPILE_OPTIONS
- ${printf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -295,8 +277,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)
diff --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt
index c1a4b8cda85c90d..1b6f763e084be9b 100644
--- a/libc/src/stdio/printf_core/CMakeLists.txt
+++ b/libc/src/stdio/printf_core/CMakeLists.txt
@@ -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
@@ -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(
@@ -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
@@ -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}
)
More information about the libc-commits
mailing list