@@ -106,6 +106,7 @@ endfunction()
106
106
# argument. Typically, these will be the options specified on the CMake
107
107
# command line.
108
108
function (load_libc_config config_file )
109
+ set (changed_vars "" )
109
110
read_libc_config (${config_file} file_opts )
110
111
foreach (opt IN LISTS file_opts )
111
112
string (JSON opt_name ERROR_VARIABLE json_error MEMBER ${opt} 0 )
@@ -132,7 +133,9 @@ function(load_libc_config config_file)
132
133
endif ()
133
134
message (STATUS "Overriding - ${opt_name} : ${opt_value} (Previous value: ${${opt_name} })" )
134
135
set (${opt_name} ${opt_value} PARENT_SCOPE )
136
+ list (APPEND changed_vars ${opt_name} )
135
137
endforeach ()
138
+ set (changed_vars "${changed_vars} " PARENT_SCOPE )
136
139
endfunction ()
137
140
138
141
function (generate_config_doc config_file doc_file )
@@ -215,3 +218,103 @@ function(generate_config_doc config_file doc_file)
215
218
message (STATUS "Writing config doc to ${doc_file} " )
216
219
file (WRITE ${doc_file} ${doc_string} )
217
220
endfunction ()
221
+
222
+ #--------------------------
223
+ # Entry point (shared between libc/libcxx)
224
+ #--------------------------
225
+
226
+ if (NOT DEFINED LIBC_SOURCE_DIR )
227
+ set (LIBC_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} /../.. )
228
+ message (WARNING "LIBC_SOURCE_DIR: ${LIBC_SOURCE_DIR} " )
229
+ endif ()
230
+
231
+ include (LLVMLibCArchitectures )
232
+
233
+ # Some targets can only support the full build.
234
+ set (default_to_full_build OFF )
235
+ if (LIBC_TARGET_OS_IS_GPU )
236
+ set (default_to_full_build ON )
237
+ endif ()
238
+
239
+ if (NOT LIBC_CONFIG_PATH )
240
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
241
+ if (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
242
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
243
+ set (LIBC_CONFIG_PATH "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
244
+ elseif (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
245
+ set (LIBC_CONFIG_PATH "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
246
+ endif ()
247
+ else ()
248
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_CONFIG_PATH} " )
249
+ endif ()
250
+
251
+ if (NOT LIBC_CONFIG_PATH )
252
+ message (FATAL_ERROR "Configs for the platform '${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} ' do not exist and LIBC_CONFIG_PATH is not set." )
253
+ elseif (LIBC_CMAKE_VERBOSE_LOGGING )
254
+ message (STATUS "Path for config files is: ${LIBC_CONFIG_PATH} " )
255
+ endif ()
256
+
257
+ # Config loading happens in three steps:
258
+ # 1. Load the config file config/config.json and set up config vars.
259
+ # 2. Load config/${LIBC_TARGET_OS}/config.json if available and override
260
+ # vars as suitable.
261
+ # 3. Load config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCH}/config.json is
262
+ # available and override vars as suitable.
263
+ # All the three steps will not override options already set from the
264
+ # CMake command line. That is, the CMake command line option values take
265
+ # precedence over the values in config.json files.
266
+ set (main_config_file ${LIBC_SOURCE_DIR} /config/config.json )
267
+ read_libc_config (${main_config_file} global_config )
268
+ foreach (opt IN LISTS global_config )
269
+ string (JSON opt_name ERROR_VARIABLE json_error MEMBER ${opt} 0 )
270
+ if (json_error )
271
+ message (FATAL_ERROR ${json_error} )
272
+ endif ()
273
+ if (DEFINED ${opt_name} )
274
+ # The option is already defined from the command line so we ignore it here.
275
+ # We still make note of it so that further config load can also ignore
276
+ # this option.
277
+ message (STATUS "${opt_name} : ${${opt_name} } (from command line)" )
278
+ list (APPEND cmd_line_conf ${opt_name} )
279
+ continue ()
280
+ endif ()
281
+
282
+ string (JSON opt_object ERROR_VARIABLE json_error GET ${opt} ${opt_name} )
283
+ if (json_error )
284
+ message (FATAL_ERROR "Error reading info of option '${opt_name} ': ${json_error} " )
285
+ endif ()
286
+ string (JSON opt_value ERROR_VARIABLE json_error GET ${opt_object} "value" )
287
+ if (json_error )
288
+ message (FATAL_ERROR ${json_error} )
289
+ endif ()
290
+ message (STATUS "${opt_name} : ${opt_value} " )
291
+ set (${opt_name} ${opt_value} )
292
+ set (${opt_name} ${opt_value} PARENT_SCOPE )
293
+ endforeach ()
294
+ generate_config_doc (${main_config_file} ${LIBC_SOURCE_DIR} /docs/configure.rst )
295
+
296
+ message (WARNING "LIBC_SOURCE_DIR: ${LIBC_SOURCE_DIR} " )
297
+ message (WARNING "LIBC_CONFIG_PATH: ${LIBC_CONFIG_PATH} " )
298
+ if (NOT LIBC_CONFIG_PATH )
299
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
300
+ if (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
301
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
302
+ set (LIBC_CONFIG_PATH "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_ARCHITECTURE} " )
303
+ elseif (EXISTS "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
304
+ set (LIBC_CONFIG_PATH "${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} " )
305
+ endif ()
306
+ else ()
307
+ list (APPEND LIBC_CONFIG_JSON_FILE_LIST "${LIBC_CONFIG_PATH} " )
308
+ endif ()
309
+
310
+ # Load each target specific config.
311
+ foreach (config_path IN LISTS LIBC_CONFIG_JSON_FILE_LIST )
312
+ if (LIBC_CMAKE_VERBOSE_LOGGING )
313
+ message (STATUS "Loading additional config: '${config_path} /config.json'" )
314
+ endif ()
315
+ load_libc_config (${config_path} /config.json ${cmd_line_conf} )
316
+ # Proprogate changed_vars
317
+ foreach (var IN LISTS changed_vars )
318
+ set (${var} "${${var} }" PARENT_SCOPE )
319
+ endforeach ()
320
+ endforeach ()
0 commit comments