[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
Tue Sep 26 08:15:32 PDT 2023
https://github.com/sivachandra updated https://github.com/llvm/llvm-project/pull/66979
>From 74ef1a1f68404a03a2da4270774e0f4ece3ee9d3 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 1/2] [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 9146271898ffaa5..0ec4c608ad8425f 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(
flockfile
SRCS
@@ -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(
@@ -135,8 +137,7 @@ add_entrypoint_object(
fscanf.h
DEPENDS
${scanf_deps}
- COMPILE_OPTIONS
- ${scanf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -147,8 +148,7 @@ add_entrypoint_object(
scanf.h
DEPENDS
${scanf_deps}
- COMPILE_OPTIONS
- ${scanf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -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(
@@ -209,8 +194,7 @@ add_entrypoint_object(
printf.h
DEPENDS
${printf_deps}
- COMPILE_OPTIONS
- ${printf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -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(
@@ -256,8 +239,7 @@ add_entrypoint_object(
vprintf.h
DEPENDS
${printf_deps}
- COMPILE_OPTIONS
- ${printf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -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)
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}
)
>From 51eb7062a456f8ea045218ad04845b40d7ffa152 Mon Sep 17 00:00:00 2001
From: Siva Chandra Reddy <sivachandra at google.com>
Date: Tue, 26 Sep 2023 06:39:47 +0000
Subject: [PATCH 2/2] [libc] Add add_gen_header deps separately.
---
libc/cmake/modules/LLVMLibCHeaderRules.cmake | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCHeaderRules.cmake b/libc/cmake/modules/LLVMLibCHeaderRules.cmake
index 1027a55946d5f8b..9e9b598721ab372 100644
--- a/libc/cmake/modules/LLVMLibCHeaderRules.cmake
+++ b/libc/cmake/modules/LLVMLibCHeaderRules.cmake
@@ -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
More information about the libc-commits
mailing list