diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 0665cf0f7a1d9..12fff25c197e2 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -143,6 +143,7 @@ foreach(opt IN LISTS global_config) message(STATUS "${opt_name}: ${opt_value}") set(${opt_name} ${opt_value}) endforeach() +generate_config_doc(${main_config_file} ${LIBC_SOURCE_DIR}/docs/configure.rst) 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}) diff --git a/libc/cmake/modules/LibcConfig.cmake b/libc/cmake/modules/LibcConfig.cmake index a9c69de8a310a..7a3e6066b3cc0 100644 --- a/libc/cmake/modules/LibcConfig.cmake +++ b/libc/cmake/modules/LibcConfig.cmake @@ -47,7 +47,6 @@ function(read_libc_config config_file opt_list) # to load. If there are no config options, it is better to remove that # config.json file instead of including an empty file. message(FATAL_ERROR "${config_file}: Does not contain any config option groups") - return() endif() math(EXPR group_count_1 "${group_count} - 1") @@ -135,3 +134,84 @@ function(load_libc_config config_file) set(${opt_name} ${opt_value} PARENT_SCOPE) endforeach() endfunction() + +function(generate_config_doc config_file doc_file) + if(NOT EXISTS ${config_file}) + message(FATAL_ERROR "${config_file} does not exist") + endif() + file(READ ${config_file} json_config) + string(JSON group_count ERROR_VARIABLE json_error LENGTH ${json_config}) + if(json_error) + message(FATAL_ERROR "${config_file}: ${json_error}") + endif() + if(${group_count} EQUAL 0) + message(FATAL_ERROR "${config_file}: Does not contain any config option groups") + endif() + math(EXPR group_count_1 "${group_count} - 1") + + set(doc_string ".. _configure:\n" + "..\n" + " Do not edit this file directly. CMake will auto generate it.\n" + " If the changes are intended, add this file to your commit.\n" + "\n" + "==========================\n" + "Configure Options\n" + "==========================\n" + "\n" + "Below is the full set of options one can use to configure the libc build.\n" + "An option can be given an explicit value on the CMake command line using\n" + "the following syntax:\n" + "\n" + ".. code-block:: sh\n" + "\n" + " $> cmake -D=