|
1 |
| - |
2 | 1 | if (LLVM_ENABLE_SPHINX)
|
3 | 2 | include(AddSphinxTarget)
|
4 | 3 | if (SPHINX_FOUND)
|
5 | 4 | if (${SPHINX_OUTPUT_HTML})
|
6 |
| - add_sphinx_target(html libc) |
| 5 | + # Similar to clang, we copy our static .rst files from libc/docs/ to the |
| 6 | + # $build_dir/libc/docs/. That way, we can have a mix of both static |
| 7 | + # (committed) .rst files, and dynamically generated .rst files. We don't |
| 8 | + # want the dynamically generated .rst files to pollute the source tree. |
| 9 | + add_custom_target(copy-libc-rst-docs |
| 10 | + COMMAND "${CMAKE_COMMAND}" -E copy_directory |
| 11 | + "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") |
| 12 | + |
| 13 | + # For headers that are nested in directories, we need to |
| 14 | + # `mkdir $build_dir/libc/docs/headers/$dir` since the above copy_directory |
| 15 | + # command does not create such copies. Otherwise, the invocation of docgen |
| 16 | + # below will fail since the output file would be placed in a directory that |
| 17 | + # does not exist, leading to a `No such file or directory` error from the |
| 18 | + # shell. |
| 19 | + file(MAKE_DIRECTORY |
| 20 | + "${CMAKE_CURRENT_BINARY_DIR}/headers/arpa/" |
| 21 | + "${CMAKE_CURRENT_BINARY_DIR}/headers/sys/" |
| 22 | + ) |
| 23 | + |
| 24 | + # Change sphinx to build from $build_dir/libc/docs/ rather than |
| 25 | + # llvm-project/libc/docs/. |
| 26 | + add_sphinx_target(html libc SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}") |
| 27 | + # Depend on the copy target. |
| 28 | + add_dependencies(docs-libc-html copy-libc-rst-docs) |
| 29 | + |
| 30 | + # Maintain a list of headers for which we dynamically generate html docs |
| 31 | + # for via docgen. For more complex docs (such as per arch support, a la |
| 32 | + # math.h), those should be omitted and exist statically in |
| 33 | + # libc/docs/headers/. |
| 34 | + list(APPEND docgen_list |
| 35 | + arpa/inet |
| 36 | + assert |
| 37 | + ctype |
| 38 | + errno |
| 39 | + fenv |
| 40 | + float |
| 41 | + inttypes |
| 42 | + locale |
| 43 | + setjmp |
| 44 | + signal |
| 45 | + stdbit |
| 46 | + stdio |
| 47 | + stdlib |
| 48 | + string |
| 49 | + strings |
| 50 | + sys/mman |
| 51 | + threads |
| 52 | + uchar |
| 53 | + wchar |
| 54 | + wctype |
| 55 | + ) |
| 56 | + |
| 57 | + foreach(stem IN LISTS docgen_list) |
| 58 | + # It is an error in cmake to have a target name that contains a "/", but |
| 59 | + # docgen relies on the "/" to find headers nested under directories. |
| 60 | + # Replace with underscore. |
| 61 | + string(REPLACE "/" "_" stem_rst ${stem}) |
| 62 | + |
| 63 | + # docgen invocation. |
| 64 | + add_custom_target(${stem_rst} |
| 65 | + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../utils/docgen/docgen.py ${stem}.h > |
| 66 | + ${CMAKE_CURRENT_BINARY_DIR}/headers/${stem}.rst) |
| 67 | + # depend on the docgen invocation. |
| 68 | + add_dependencies(docs-libc-html ${stem_rst}) |
| 69 | + endforeach() |
7 | 70 | endif()
|
8 | 71 | endif()
|
9 | 72 | endif()
|
0 commit comments