97 lines · plain
1if (LLVM_ENABLE_SPHINX)2include(AddSphinxTarget)3if (SPHINX_FOUND)4 if (${SPHINX_OUTPUT_HTML})5 # Similar to clang, we copy our static .rst files from libc/docs/ to the6 # $build_dir/libc/docs/. That way, we can have a mix of both static7 # (committed) .rst files, and dynamically generated .rst files. We don't8 # want the dynamically generated .rst files to pollute the source tree.9 add_custom_target(copy-libc-rst-docs10 COMMAND "${CMAKE_COMMAND}" -E copy_directory11 "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}"12 13 COMMAND "${CMAKE_COMMAND}" -E copy_if_different14 "${CMAKE_CURRENT_SOURCE_DIR}/../Maintainers.rst"15 "${CMAKE_CURRENT_BINARY_DIR}"16 )17 18 # For headers that are nested in directories, we need to19 # `mkdir $build_dir/libc/docs/headers/$dir` since the above copy_directory20 # command does not create such copies. Otherwise, the invocation of docgen21 # below will fail since the output file would be placed in a directory that22 # does not exist, leading to a `No such file or directory` error from the23 # shell.24 file(MAKE_DIRECTORY25 "${CMAKE_CURRENT_BINARY_DIR}/headers/arpa/"26 "${CMAKE_CURRENT_BINARY_DIR}/headers/net/"27 "${CMAKE_CURRENT_BINARY_DIR}/headers/netinet/"28 "${CMAKE_CURRENT_BINARY_DIR}/headers/sys/"29 )30 31 # Change sphinx to build from $build_dir/libc/docs/ rather than32 # llvm-project/libc/docs/.33 add_sphinx_target(html libc SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")34 # Depend on the copy target.35 add_dependencies(docs-libc-html copy-libc-rst-docs)36 37 # Maintain a list of headers for which we dynamically generate html docs38 # for via docgen. For more complex docs (such as per arch support, a la39 # math.h), those should be omitted and exist statically in40 # libc/docs/headers/.41 list(APPEND docgen_list42 aio43 arpa/inet44 assert45 cpio46 ctype47 dirent48 endian49 errno50 fenv51 float52 glob53 inttypes54 locale55 net/if56 netinet/in57 # TODO: https://github.com/llvm/llvm-project/issues/12382158 # pthread59 setjmp60 signal61 stdbit62 stdio63 stdlib64 string65 strings66 sys/mman67 sys/resource68 sys/stat69 sys/statvfs70 sys/time71 sys/utsname72 sys/wait73 termios74 threads75 uchar76 unistd77 wchar78 wctype79 )80 81 foreach(stem IN LISTS docgen_list)82 # It is an error in cmake to have a target name that contains a "/", but83 # docgen relies on the "/" to find headers nested under directories.84 # Replace with underscore.85 string(REPLACE "/" "_" stem_rst ${stem})86 87 # docgen invocation.88 add_custom_target(${stem_rst}89 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../utils/docgen/docgen.py ${stem}.h >90 ${CMAKE_CURRENT_BINARY_DIR}/headers/${stem}.rst)91 # depend on the docgen invocation.92 add_dependencies(docs-libc-html ${stem_rst})93 endforeach()94 endif()95endif()96endif()97