@@ -103,12 +103,41 @@ option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF)
103
103
option (LIBC_GPU_BUILD "Build libc for the GPU. All CPU build options will be ignored." OFF )
104
104
set (LIBC_TARGET_TRIPLE "" CACHE STRING "The target triple for the libc build." )
105
105
106
+ option (LIBC_CONFIG_PATH "The path to user provided folder that configures the build for the target system." OFF )
107
+
106
108
set (LIBC_ENABLE_UNITTESTS ON )
107
109
set (LIBC_ENABLE_HERMETIC_TESTS ${LLVM_LIBC_FULL_BUILD} )
108
110
109
111
# Defines LIBC_TARGET_ARCHITECTURE and associated macros.
110
112
include (LLVMLibCArchitectures )
111
113
114
+ set (LIBC_CONFIG_JSON_FILE_LIST "" )
115
+
116
+ if (NOT LIBC_CONFIG_PATH )
117
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
118
+ if (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
119
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
120
+ set (LIBC_CONFIG_PATH "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
121
+ elseif (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
122
+ set (LIBC_CONFIG_PATH "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
123
+ endif ()
124
+ else ()
125
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_CONFIG_PATH} " )
126
+ endif ()
127
+
128
+ if (NOT LIBC_CONFIG_PATH )
129
+ message (FATAL_ERROR "Configs for the platform '${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} ' do not exist and LIBC_CONFIG_PATH is not set." )
130
+ elseif (LIBC_CMAKE_VERBOSE_LOGGING )
131
+ message (STATUS "Path for config files is: ${LIBC_CONFIG_PATH} " )
132
+ endif ()
133
+
134
+ # option(LIBC_ENABLE_WIDE_CHARACTERS
135
+ # "Whether to enable wide character functions on supported platforms. This may
136
+ # also set flags to enable or disable wide character support within other
137
+ # functions (e.g. printf)." ON)
138
+
139
+ #TODO: Add carve-out specific config files to the list here.
140
+
112
141
include (LibcConfig )
113
142
# Config loading happens in three steps:
114
143
# 1. Load the config file config/config.json and set up config vars.
@@ -147,8 +176,14 @@ foreach(opt IN LISTS global_config)
147
176
set (${opt_name} ${opt_value} )
148
177
endforeach ()
149
178
generate_config_doc (${main_config_file} ${LIBC_SOURCE_DIR} /docs/configure.rst )
150
- load_libc_config (${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS}/config.json ${cmd_line_conf} )
151
- load_libc_config (${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/config.json ${cmd_line_conf} )
179
+
180
+ # Load each target specific config.
181
+ foreach (config_path IN LISTS LIBC_CONFIG_JSON_FILE_LIST )
182
+ if (LIBC_CMAKE_VERBOSE_LOGGING )
183
+ message (STATUS "Loading additional config: '${config_path} /config.json'" )
184
+ endif ()
185
+ load_libc_config (${config_path} /config.json ${cmd_line_conf} )
186
+ endforeach ()
152
187
153
188
if (LIBC_TARGET_ARCHITECTURE_IS_GPU )
154
189
set (LIBC_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} /include )
@@ -248,21 +283,41 @@ include(LLVMLibCCheckCpuFeatures)
248
283
include (CheckCompilerFeatures )
249
284
include (LLVMLibCRules )
250
285
251
- if (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} /entrypoints.txt" )
252
- set (entrypoint_file "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} /entrypoints.txt" )
253
- elseif (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /entrypoints.txt" )
254
- set (entrypoint_file "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /entrypoints.txt" )
286
+ set (TARGET_LLVMLIBC_ENTRYPOINTS "" )
287
+ set (TARGET_LIBC_ENTRYPOINTS "" )
288
+ set (TARGET_LIBM_ENTRYPOINTS "" )
289
+ set (TARGET_LLVMLIBC_REMOVED_ENTRYPOINTS "" )
290
+
291
+ # Check entrypoints.txt
292
+ if (EXISTS "${LIBC_CONFIG_PATH} /entrypoints.txt" )
293
+ include ("${LIBC_CONFIG_PATH} /entrypoints.txt" )
255
294
else ()
256
- message (FATAL_ERROR "entrypoints.txt file for the target platform '${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} ' not found." )
295
+ message (FATAL_ERROR "${LIBC_CONFIG_PATH} /entrypoints.txt file not found." )
296
+ endif ()
297
+
298
+ # Check headers.txt
299
+ if (EXISTS "${LIBC_CONFIG_PATH} /headers.txt" )
300
+ include ("${LIBC_CONFIG_PATH} /headers.txt" )
301
+ elseif (LLVM_LIBC_FULL_BUILD )
302
+ message (FATAL_ERROR "${LIBC_CONFIG_PATH} /headers.txt file not found and fullbuild requested." )
257
303
endif ()
258
- include (${entrypoint_file} )
259
304
260
- if (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} /headers.txt" )
261
- include ("${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} /headers.txt" )
262
- elseif (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /headers.txt" )
263
- include ("${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /headers.txt" )
305
+ # Check exclude.txt that appends to LIBC_EXCLUDE_ENTRYPOINTS list
306
+ if (EXISTS "${LIBC_CONFIG_PATH} /exclude.txt" )
307
+ include ("${LIBC_CONFIG_PATH} /exclude.txt" )
264
308
endif ()
265
309
310
+ # #TODO: Set up support for premade configs adding their own exclude lists.
311
+
312
+ foreach (removed_entrypoint IN LISTS TARGET_LLVMLIBC_REMOVED_ENTRYPOINTS )
313
+ if (LIBC_CMAKE_VERBOSE_LOGGING )
314
+ message (STATUS "Removing entrypoint ${removed_entrypoint} " )
315
+ endif ()
316
+ list (REMOVE_ITEM TARGET_LLVMLIBC_ENTRYPOINTS ${removed_entrypoint} )
317
+ list (REMOVE_ITEM TARGET_LIBC_ENTRYPOINTS ${removed_entrypoint} )
318
+ list (REMOVE_ITEM TARGET_LIBM_ENTRYPOINTS ${removed_entrypoint} )
319
+ endforeach ()
320
+
266
321
set (TARGET_ENTRYPOINT_NAME_LIST "" )
267
322
foreach (entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS )
268
323
string (FIND ${entrypoint} "." last_dot_loc REVERSE )
0 commit comments