Skip to content

Commit db63fb5

Browse files
[Clang][Docs] Fix man page build
This patch fixes the man page build. It currently doesn't work as SOURCE_DIR isn't set correctly (just undefined) within the add_sphinx_target function. This patch also moves around the creation of targets for autogenerated rst files so that both the man page and html build can depend upon them as before only the html build depended on them. Fixes #62540 Reviewed By: tstellar Differential Revision: https://reviews.llvm.org/D149809
1 parent 0e8717f commit db63fb5

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

clang/docs/CMakeLists.txt

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,50 +90,60 @@ if (LLVM_ENABLE_DOXYGEN)
9090
endif()
9191
endif()
9292

93-
function (gen_rst_file_from_td output_file td_option source docs_target)
93+
function (gen_rst_file_from_td output_file td_option source docs_targets)
9494
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
9595
message(FATAL_ERROR "Cannot find source file: ${source} in ${CMAKE_CURRENT_SOURCE_DIR}")
9696
endif()
9797
get_filename_component(TABLEGEN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY)
9898
list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}")
9999
clang_tablegen(${output_file} ${td_option} SOURCE ${source} TARGET "gen-${output_file}")
100-
add_dependencies(${docs_target} "gen-${output_file}")
100+
foreach(target ${docs_targets})
101+
add_dependencies(${target} gen-${output_file})
102+
endforeach()
101103
endfunction()
102104

103105
if (LLVM_ENABLE_SPHINX)
104106
include(AddSphinxTarget)
105-
if (SPHINX_FOUND)
107+
if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN}))
108+
# Copy rst files to build directory before generating the html
109+
# documentation. Some of the rst files are generated, so they
110+
# only exist in the build directory. Sphinx needs all files in
111+
# the same directory in order to generate the html, so we need to
112+
# copy all the non-gnerated rst files from the source to the build
113+
# directory before we run sphinx.
114+
add_custom_target(copy-clang-rst-docs
115+
COMMAND "${CMAKE_COMMAND}" -E copy_directory
116+
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}"
117+
118+
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
119+
"${CMAKE_CURRENT_SOURCE_DIR}/../CodeOwners.rst"
120+
"${CMAKE_CURRENT_BINARY_DIR}"
121+
)
122+
123+
set(docs_targets "")
124+
106125
if (${SPHINX_OUTPUT_HTML})
107126
add_sphinx_target(html clang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
108127

109-
# Copy rst files to build directory before generating the html
110-
# documentation. Some of the rst files are generated, so they
111-
# only exist in the build directory. Sphinx needs all files in
112-
# the same directory in order to generate the html, so we need to
113-
# copy all the non-gnerated rst files from the source to the build
114-
# directory before we run sphinx.
115-
add_custom_target(copy-clang-rst-docs
116-
COMMAND "${CMAKE_COMMAND}" -E copy_directory
117-
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}"
118-
119-
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
120-
"${CMAKE_CURRENT_SOURCE_DIR}/../CodeOwners.rst"
121-
"${CMAKE_CURRENT_BINARY_DIR}"
122-
)
123-
add_dependencies(docs-clang-html copy-clang-rst-docs)
124-
125128
add_custom_command(TARGET docs-clang-html POST_BUILD
126129
COMMAND "${CMAKE_COMMAND}" -E copy
127130
"${CMAKE_CURRENT_SOURCE_DIR}/LibASTMatchersReference.html"
128131
"${CMAKE_CURRENT_BINARY_DIR}/html/LibASTMatchersReference.html")
129132

130-
# Generated files
131-
gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs ../include/clang/Basic/Attr.td docs-clang-html)
132-
gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs ../include/clang/Basic/Diagnostic.td docs-clang-html)
133-
gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Driver/ClangOptionDocs.td docs-clang-html)
133+
list(APPEND docs_targets "docs-clang-html")
134134
endif()
135135
if (${SPHINX_OUTPUT_MAN})
136-
add_sphinx_target(man clang)
136+
add_sphinx_target(man clang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
137+
list(APPEND docs_targets "docs-clang-man")
137138
endif()
139+
140+
# Generated files
141+
gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs ../include/clang/Basic/Attr.td "${docs_targets}")
142+
gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs ../include/clang/Basic/Diagnostic.td "${docs_targets}")
143+
gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Driver/ClangOptionDocs.td "${docs_targets}")
144+
145+
foreach(target ${docs_targets})
146+
add_dependencies(${target} copy-clang-rst-docs)
147+
endforeach()
138148
endif()
139149
endif()

0 commit comments

Comments
 (0)