[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
Wed Sep 20 23:01:26 PDT 2023


https://github.com/sivachandra created https://github.com/llvm/llvm-project/pull/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.


>From 301d73990d2a93b69250c11eee5655ad18e7c578 Mon Sep 17 00:00:00 2001
From: Siva Chandra Reddy <sivachandra at google.com>
Date: Thu, 21 Sep 2023 04:38:02 +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/LLVMLibCObjectRules.cmake |  2 ++
 libc/src/stdio/CMakeLists.txt                | 27 ++++---------------
 libc/src/stdio/printf_core/CMakeLists.txt    | 28 +++++++++++++++++---
 3 files changed, 32 insertions(+), 25 deletions(-)

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}
 )
 
 



More information about the libc-commits mailing list