@@ -10,6 +10,17 @@ if (SPHINX_FOUND)
1010 COMMAND "${CMAKE_COMMAND} " -E copy_directory
1111 "${CMAKE_CURRENT_SOURCE_DIR} " "${CMAKE_CURRENT_BINARY_DIR} " )
1212
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+
1324 # Change sphinx to build from $build_dir/libc/docs/ rather than
1425 # llvm-project/libc/docs/.
1526 add_sphinx_target(html libc SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR} " )
@@ -21,6 +32,7 @@ if (SPHINX_FOUND)
2132 # math.h), those should be omitted and exist statically in
2233 # libc/docs/headers/.
2334 list (APPEND docgen_list
35+ arpa/inet
2436 assert
2537 ctype
2638 errno
@@ -34,19 +46,25 @@ if (SPHINX_FOUND)
3446 stdlib
3547 string
3648 strings
49+ sys/mman
3750 threads
3851 uchar
3952 wchar
4053 wctype
4154 )
4255
4356 foreach (stem IN LISTS docgen_list)
57+ # It is an error in cmake to have a target name that contains a "/", but
58+ # docgen relies on the "/" to find headers nested under directories.
59+ # Replace with underscore.
60+ string (REPLACE "/" "_" stem_rst ${stem} )
61+
4462 # docgen invocation.
45- add_custom_target (${stem} _rst
63+ add_custom_target (${stem_rst}
4664 COMMAND ${CMAKE_CURRENT_SOURCE_DIR} /../utils/docgen/docgen.py ${stem} .h >
4765 ${CMAKE_CURRENT_BINARY_DIR} /headers/${stem} .rst)
4866 # depend on the docgen invocation.
49- add_dependencies (docs-libc-html ${stem} _rst )
67+ add_dependencies (docs-libc-html ${stem_rst} )
5068 endforeach ()
5169 endif ()
5270endif ()
0 commit comments