[libc-commits] [libc] [libc] Propagate printf config options from a single config header library. (PR #66979)
via libc-commits
libc-commits at lists.llvm.org
Wed Sep 20 23:02:42 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/66979.diff
3 Files Affected:
- (modified) libc/cmake/modules/LLVMLibCObjectRules.cmake (+2)
- (modified) libc/src/stdio/CMakeLists.txt (+5-22)
- (modified) libc/src/stdio/printf_core/CMakeLists.txt (+25-3)
``````````diff
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index c10b81f1af8cba3..8c4b92e4fb4577b 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} ${fq_deps_list})
endif()
if(NOT ADD_OBJECT_CXX_STANDARD)
diff --git a/libc/src/stdio/CMakeLists.txt b/libc/src/stdio/CMakeLists.txt
index f3a75fb965c6e16..9f23362ab16ca2f 100644
--- a/libc/src/stdio/CMakeLists.txt
+++ b/libc/src/stdio/CMakeLists.txt
@@ -188,19 +188,6 @@ 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
@@ -208,7 +195,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.__support.File.platform_stdout
)
else()
- list(APPEND printf_copts "-DLIBC_COPT_PRINTF_USE_SYSTEM_FILE")
+ list(APPEND use_system_file "COMPILE_OPTIONS" "-DLIBC_COPT_PRINTF_USE_SYSTEM_FILE")
endif()
add_entrypoint_object(
@@ -219,8 +206,7 @@ add_entrypoint_object(
printf.h
DEPENDS
${printf_deps}
- COMPILE_OPTIONS
- ${printf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -232,8 +218,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(
@@ -266,8 +251,7 @@ add_entrypoint_object(
vprintf.h
DEPENDS
${printf_deps}
- COMPILE_OPTIONS
- ${printf_copts}
+ ${use_system_file}
)
add_entrypoint_object(
@@ -279,8 +263,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 7087d28ede66e8b..07f1e0aeb7ef322 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
@@ -34,6 +56,7 @@ add_object_library(
parser.h
DEPENDS
.core_structs
+ .printf_config
libc.src.__support.arg_list
libc.src.__support.ctype_utils
libc.src.__support.str_to_integer
@@ -53,11 +76,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(
@@ -79,6 +102,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
@@ -91,8 +115,6 @@ add_object_library(
libc.src.__support.uint128
libc.src.__support.integer_to_string
libc.src.__support.float_to_string
- COMPILE_OPTIONS
- ${printf_copts}
)
``````````
</details>
https://github.com/llvm/llvm-project/pull/66979
More information about the libc-commits
mailing list