@@ -47,7 +47,6 @@ function(read_libc_config config_file opt_list)
47
47
# to load. If there are no config options, it is better to remove that
48
48
# config.json file instead of including an empty file.
49
49
message (FATAL_ERROR "${config_file} : Does not contain any config option groups" )
50
- return ()
51
50
endif ()
52
51
math (EXPR group_count_1 "${group_count} - 1" )
53
52
@@ -135,3 +134,84 @@ function(load_libc_config config_file)
135
134
set (${opt_name} ${opt_value} PARENT_SCOPE)
136
135
endforeach ()
137
136
endfunction ()
137
+
138
+ function (generate_config_doc config_file doc_file)
139
+ if (NOT EXISTS ${config_file} )
140
+ message (FATAL_ERROR "${config_file} does not exist" )
141
+ endif ()
142
+ file (READ ${config_file} json_config)
143
+ string (JSON group_count ERROR_VARIABLE json_error LENGTH ${json_config} )
144
+ if (json_error)
145
+ message (FATAL_ERROR "${config_file} : ${json_error} " )
146
+ endif ()
147
+ if (${group_count} EQUAL 0)
148
+ message (FATAL_ERROR "${config_file} : Does not contain any config option groups" )
149
+ endif ()
150
+ math (EXPR group_count_1 "${group_count} - 1" )
151
+
152
+ set (doc_string ".. _configure:\n "
153
+ "..\n "
154
+ " Do not edit this file directly. CMake will auto generate it.\n "
155
+ " If the changes are intended, add this file to your commit.\n "
156
+ "\n "
157
+ "==========================\n "
158
+ "Configure Options\n "
159
+ "==========================\n "
160
+ "\n "
161
+ "Below is the full set of options one can use to configure the libc build.\n "
162
+ "An option can be given an explicit value on the CMake command line using\n "
163
+ "the following syntax:\n "
164
+ "\n "
165
+ ".. code-block:: sh\n "
166
+ "\n "
167
+ " $> cmake <other build options> -D<libc config option name>=<option value> <more options>\n "
168
+ "\n "
169
+ "For example:\n "
170
+ "\n "
171
+ ".. code-block:: sh\n "
172
+ "\n "
173
+ " $> cmake <other build options> -DLIBC_CONF_PRINTF_DISABLE_FLOAT=ON <more options>\n "
174
+ "\n "
175
+ "See the main ``config/config.json``, and the platform and architecture specific\n "
176
+ "overrides in ``config/<platform>/config.json`` and ``config/<platform>/<arch>/config.json,``\n "
177
+ "to learn about the defaults for your platform and target.\n "
178
+ "\n " )
179
+
180
+ foreach (group_num RANGE ${group_count_1} )
181
+ string (JSON group_name ERROR_VARIABLE json_error MEMBER ${json_config} ${group_num} )
182
+ if (json_error)
183
+ message (FATAL_ERROR "${config_file} : ${json_error} " )
184
+ endif ()
185
+ string (APPEND doc_string "* **\" ${group_name} \" options**\n " )
186
+ string (JSON option_map ERROR_VARIABLE json_error GET ${json_config} ${group_name} )
187
+ if (json_error)
188
+ message (FATAL_ERROR ${json_error} )
189
+ endif ()
190
+ string (JSON option_count ERROR_VARIABLE jsor_error LENGTH ${option_map} )
191
+ if (json_error)
192
+ message (FATAL_ERROR ${json_error} )
193
+ endif ()
194
+ if (${option_count} EQUAL 0)
195
+ message (FATAL_ERROR "${config_file} : No options listed against the config option group '${group_name} '" )
196
+ endif ()
197
+
198
+ math (EXPR option_count_1 "${option_count} - 1" )
199
+ foreach (opt_num RANGE ${option_count_1} )
200
+ string (JSON option_name ERROR_VARIABLE json_error MEMBER ${option_map} ${opt_num} )
201
+ if (json_error)
202
+ message (FATAL_ERROR ${json_error} )
203
+ endif ()
204
+ string (JSON opt_object ERROR_VARIABLE json_error GET ${option_map} ${option_name} )
205
+ if (json_error)
206
+ message (FATAL_ERROR "Error generating ${doc_file} : ${json_error} \n ${opt_object} " )
207
+ endif ()
208
+ string (JSON opt_doc ERROR_VARIABLE json_error GET ${opt_object} "doc" )
209
+ if (json_error)
210
+ message (FATAL_ERROR "Error generating ${doc_file} : ${json_error} " )
211
+ endif ()
212
+ string (APPEND doc_string " - ``${option_name} ``: ${opt_doc} \n " )
213
+ endforeach ()
214
+ endforeach ()
215
+ message (STATUS "Writing config doc to ${doc_file} " )
216
+ file (WRITE ${doc_file} ${doc_string} )
217
+ endfunction ()
0 commit comments