aboutsummaryrefslogtreecommitdiff
path: root/libc/CMakeLists.txt
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2023-08-29 07:32:52 +0000
committerSiva Chandra Reddy <sivachandra@google.com>2023-09-05 14:19:18 +0000
commit0f1507af411b08c66e9807684858893f2e921ee2 (patch)
treeff91f4df5e9849b0cb6e9e72e0a72b0a172d8744 /libc/CMakeLists.txt
parent5647f2908de90fe07b0805e988cd2e91a1751928 (diff)
downloadllvm-0f1507af411b08c66e9807684858893f2e921ee2.zip
llvm-0f1507af411b08c66e9807684858893f2e921ee2.tar.gz
llvm-0f1507af411b08c66e9807684858893f2e921ee2.tar.bz2
[libc] Add a JSON based config option system.
Few printf config options have been setup using this new config system along with their baremetal overrides. A follow up patch will add generation of doc/config.rst, which will contain the full list of libc config options and short description explaining how they affect the libc. Reviewed By: gchatelet Differential Revision: https://reviews.llvm.org/D159158
Diffstat (limited to 'libc/CMakeLists.txt')
-rw-r--r--libc/CMakeLists.txt40
1 files changed, 40 insertions, 0 deletions
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index c885080..549d1fb 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -93,6 +93,46 @@ set(LIBC_ENABLE_HERMETIC_TESTS ${LLVM_LIBC_FULL_BUILD})
# Defines LIBC_TARGET_ARCHITECTURE and associated macros.
include(LLVMLibCArchitectures)
+include(LibcConfig)
+# Config loading happens in three steps:
+# 1. Load the config file config/config.json and set up config vars.
+# 2. Load config/${LIBC_TARGET_OS}/config.json if available and override
+# vars as suitable.
+# 3. Load config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCH}/config.json is
+# available and override vars as suitable.
+# All the three steps will not override options already set from the
+# CMake command line. That is, the CMake command line option values take
+# precedence over the values in config.json files.
+set(main_config_file ${LIBC_SOURCE_DIR}/config/config.json)
+read_libc_config(${main_config_file} global_config)
+foreach(opt IN LISTS global_config)
+ string(JSON opt_name ERROR_VARIABLE json_error MEMBER ${opt} 0)
+ if(json_error)
+ message(FATAL_ERROR ${json_error})
+ endif()
+ if(DEFINED ${opt_name})
+ # The option is already defined from the command line so we ignore it here.
+ # We still make note of it so that further config load can also ignore
+ # this option.
+ message(STATUS "${opt_name}: ${${opt_name}} (from command line)")
+ list(APPEND cmd_line_conf ${opt_name})
+ continue()
+ endif()
+
+ string(JSON opt_object ERROR_VARIABLE json_error GET ${opt} ${opt_name})
+ if(json_error)
+ message(FATAL_ERROR "Error reading info of option '${opt_name}': ${json_error}")
+ endif()
+ string(JSON opt_value ERROR_VARIABLE json_error GET ${opt_object} "value")
+ if(json_error)
+ message(FATAL_ERROR ${json_error})
+ endif()
+ message(STATUS "${opt_name}: ${opt_value}")
+ set(${opt_name} ${opt_value})
+endforeach()
+load_libc_config(${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/config.json ${cmd_line_conf})
+load_libc_config(${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/config.json ${cmd_line_conf})
+
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
set(LIBC_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
set(LIBC_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/gpu-none-llvm)