diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt --- a/clang/docs/CMakeLists.txt +++ b/clang/docs/CMakeLists.txt @@ -103,19 +103,26 @@ if (LLVM_ENABLE_SPHINX) include(AddSphinxTarget) if (SPHINX_FOUND) + + # Copy rst files to build directory before generating the + # documentation. Some of the rst files are generated, so they + # only exist in the build directory. Sphinx needs all files in + # the same directory in order to generate the files, so we need to + # copy all the non-generated rst files from the source to the build + # directory before we run Sphinx. + add_custom_target(copy-clang-rst-docs + COMMAND "${CMAKE_COMMAND}" -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}") + + # Generated files + gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs ../include/clang/Basic/Attr.td copy-clang-rst-docs) + gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs ../include/clang/Basic/Diagnostic.td copy-clang-rst-docs) + gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Driver/ClangOptionDocs.td copy-clang-rst-docs) + if (${SPHINX_OUTPUT_HTML}) add_sphinx_target(html clang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}") - # Copy rst files to build directory before generating the html - # documentation. Some of the rst files are generated, so they - # only exist in the build directory. Sphinx needs all files in - # the same directory in order to generate the html, so we need to - # copy all the non-gnerated rst files from the source to the build - # directory before we run sphinx. - add_custom_target(copy-clang-rst-docs - COMMAND "${CMAKE_COMMAND}" -E copy_directory - "${CMAKE_CURRENT_SOURCE_DIR}" - "${CMAKE_CURRENT_BINARY_DIR}") add_dependencies(docs-clang-html copy-clang-rst-docs) add_custom_command(TARGET docs-clang-html POST_BUILD @@ -123,13 +130,12 @@ "${CMAKE_CURRENT_SOURCE_DIR}/LibASTMatchersReference.html" "${CMAKE_CURRENT_BINARY_DIR}/html/LibASTMatchersReference.html") - # Generated files - gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs ../include/clang/Basic/Attr.td docs-clang-html) - gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs ../include/clang/Basic/Diagnostic.td docs-clang-html) - gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Driver/ClangOptionDocs.td docs-clang-html) endif() + if (${SPHINX_OUTPUT_MAN}) - add_sphinx_target(man clang) + add_sphinx_target(man clang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}") + add_dependencies(docs-clang-man copy-clang-rst-docs) endif() + endif() endif() diff --git a/llvm/cmake/modules/AddSphinxTarget.cmake b/llvm/cmake/modules/AddSphinxTarget.cmake --- a/llvm/cmake/modules/AddSphinxTarget.cmake +++ b/llvm/cmake/modules/AddSphinxTarget.cmake @@ -20,6 +20,9 @@ # ``project`` should be the project name # # Named arguments: +# ``SOURCE_DIR`` source directory for Sphinx files. Defaults to +# ${CMAKE_CURRENT_SOURCE_DIR}. +# # ``ENV_VARS`` should be a list of environment variables that should be set when # running Sphinx. Each environment variable should be a string with # the form KEY=VALUE.