2017-05-09 09:41:28 +08:00
|
|
|
|
|
|
|
# Create sphinx target
|
2017-05-15 17:34:23 +08:00
|
|
|
if (LLVM_ENABLE_SPHINX)
|
2017-05-09 09:41:28 +08:00
|
|
|
message(STATUS "Sphinx enabled.")
|
|
|
|
find_package(Sphinx REQUIRED)
|
2017-05-15 17:34:23 +08:00
|
|
|
if (LLVM_BUILD_DOCS AND NOT TARGET sphinx)
|
2017-05-09 09:41:28 +08:00
|
|
|
add_custom_target(sphinx ALL)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(STATUS "Sphinx disabled.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2014-04-19 05:45:25 +08:00
|
|
|
# Handy function for creating the different Sphinx targets.
|
|
|
|
#
|
|
|
|
# ``builder`` should be one of the supported builders used by
|
|
|
|
# the sphinx-build command.
|
|
|
|
#
|
|
|
|
# ``project`` should be the project name
|
2021-01-15 20:24:24 +08:00
|
|
|
#
|
|
|
|
# Named arguments:
|
|
|
|
# ``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.
|
2014-04-19 05:45:25 +08:00
|
|
|
function (add_sphinx_target builder project)
|
2021-01-15 20:24:24 +08:00
|
|
|
cmake_parse_arguments(ARG "" "SOURCE_DIR" "ENV_VARS" ${ARGN})
|
2014-04-19 05:45:25 +08:00
|
|
|
set(SPHINX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${builder}")
|
2017-12-01 03:09:22 +08:00
|
|
|
set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees-${project}-${builder}")
|
2014-04-19 05:45:25 +08:00
|
|
|
set(SPHINX_TARGET_NAME docs-${project}-${builder})
|
2014-08-14 19:57:13 +08:00
|
|
|
|
|
|
|
if (SPHINX_WARNINGS_AS_ERRORS)
|
|
|
|
set(SPHINX_WARNINGS_AS_ERRORS_FLAG "-W")
|
|
|
|
else()
|
|
|
|
set(SPHINX_WARNINGS_AS_ERRORS_FLAG "")
|
|
|
|
endif()
|
|
|
|
|
[clang][cmake] Include generated rst files in html built by docs-clang-html target
Summary:
This is an attempt to simply the process of building the clang
documentation, which should help avoid some of the recent issues we've
had generating the documentation for the website.
The html documentation for clang is generated by sphinx from the
reStructuredText (rst) files we have in the clang/docs directory.
There are also some rst files that need to be generated by TableGen,
before they can be passed to sphinx. Prior to this patch we were not
generating those rst files as part with the build system and they had to be
generated manually.
This patch enables the automatic generation of these rst files, but
since they are generated at build time the cannot be placed in the
clang/docs directory and must go into the cmake build directory.
Unfortunately sphinx does not currently support multiple source
directories[1], so in order to be able to generate the full
documentation, we need to work around this by copying the
rst files from the clang/docs into the build directory before
generating the html documentation.
[1] https://github.com/sphinx-doc/sphinx/issues/3132
Reviewers: rsmith, aaron.ballman, beanz, smeenai, phosek, compnerd, mgorny, delcypher
Reviewed By: mgorny, delcypher
Subscribers: delcypher, merge_guards_bot, mgorny, llvm-commits, cfe-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D72875
2020-03-06 11:57:24 +08:00
|
|
|
if (NOT ARG_SOURCE_DIR)
|
|
|
|
set(ARG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
endif()
|
|
|
|
|
2014-04-19 05:45:25 +08:00
|
|
|
add_custom_target(${SPHINX_TARGET_NAME}
|
2021-01-15 20:24:24 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env ${ARG_ENV_VARS}
|
|
|
|
${SPHINX_EXECUTABLE}
|
2014-04-19 05:45:25 +08:00
|
|
|
-b ${builder}
|
|
|
|
-d "${SPHINX_DOC_TREE_DIR}"
|
|
|
|
-q # Quiet: no output other than errors and warnings.
|
2020-07-05 01:23:48 +08:00
|
|
|
-t builder-${builder} # tag for builder
|
2014-08-14 19:57:13 +08:00
|
|
|
${SPHINX_WARNINGS_AS_ERRORS_FLAG} # Treat warnings as errors if requested
|
[clang][cmake] Include generated rst files in html built by docs-clang-html target
Summary:
This is an attempt to simply the process of building the clang
documentation, which should help avoid some of the recent issues we've
had generating the documentation for the website.
The html documentation for clang is generated by sphinx from the
reStructuredText (rst) files we have in the clang/docs directory.
There are also some rst files that need to be generated by TableGen,
before they can be passed to sphinx. Prior to this patch we were not
generating those rst files as part with the build system and they had to be
generated manually.
This patch enables the automatic generation of these rst files, but
since they are generated at build time the cannot be placed in the
clang/docs directory and must go into the cmake build directory.
Unfortunately sphinx does not currently support multiple source
directories[1], so in order to be able to generate the full
documentation, we need to work around this by copying the
rst files from the clang/docs into the build directory before
generating the html documentation.
[1] https://github.com/sphinx-doc/sphinx/issues/3132
Reviewers: rsmith, aaron.ballman, beanz, smeenai, phosek, compnerd, mgorny, delcypher
Reviewed By: mgorny, delcypher
Subscribers: delcypher, merge_guards_bot, mgorny, llvm-commits, cfe-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D72875
2020-03-06 11:57:24 +08:00
|
|
|
"${ARG_SOURCE_DIR}" # Source
|
2014-04-19 05:45:25 +08:00
|
|
|
"${SPHINX_BUILD_DIR}" # Output
|
|
|
|
COMMENT
|
2014-08-14 19:57:16 +08:00
|
|
|
"Generating ${builder} Sphinx documentation for ${project} into \"${SPHINX_BUILD_DIR}\"")
|
2014-04-19 05:45:25 +08:00
|
|
|
|
|
|
|
# When "clean" target is run, remove the Sphinx build directory
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY
|
|
|
|
ADDITIONAL_MAKE_CLEAN_FILES
|
|
|
|
"${SPHINX_BUILD_DIR}")
|
|
|
|
|
|
|
|
# We need to remove ${SPHINX_DOC_TREE_DIR} when make clean is run
|
|
|
|
# but we should only add this path once
|
|
|
|
get_property(_CURRENT_MAKE_CLEAN_FILES
|
|
|
|
DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES)
|
|
|
|
list(FIND _CURRENT_MAKE_CLEAN_FILES "${SPHINX_DOC_TREE_DIR}" _INDEX)
|
|
|
|
if (_INDEX EQUAL -1)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY
|
|
|
|
ADDITIONAL_MAKE_CLEAN_FILES
|
|
|
|
"${SPHINX_DOC_TREE_DIR}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (LLVM_BUILD_DOCS)
|
|
|
|
add_dependencies(sphinx ${SPHINX_TARGET_NAME})
|
|
|
|
|
|
|
|
# Handle installation
|
2014-04-29 06:06:20 +08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
if (builder STREQUAL man)
|
2017-04-05 22:49:46 +08:00
|
|
|
if (CMAKE_INSTALL_MANDIR)
|
|
|
|
set(INSTALL_MANDIR ${CMAKE_INSTALL_MANDIR}/)
|
|
|
|
else()
|
|
|
|
set(INSTALL_MANDIR share/man/)
|
|
|
|
endif()
|
2014-04-29 06:06:20 +08:00
|
|
|
# FIXME: We might not ship all the tools that these man pages describe
|
|
|
|
install(DIRECTORY "${SPHINX_BUILD_DIR}/" # Slash indicates contents of
|
2016-12-05 17:15:05 +08:00
|
|
|
COMPONENT "${project}-sphinx-man"
|
2017-04-05 22:49:46 +08:00
|
|
|
DESTINATION ${INSTALL_MANDIR}man1)
|
2014-04-19 05:45:25 +08:00
|
|
|
|
2019-10-03 00:06:50 +08:00
|
|
|
if(NOT LLVM_ENABLE_IDE)
|
|
|
|
add_llvm_install_targets("install-${SPHINX_TARGET_NAME}"
|
|
|
|
DEPENDS ${SPHINX_TARGET_NAME}
|
|
|
|
COMPONENT "${project}-sphinx-man")
|
|
|
|
endif()
|
2014-04-29 06:06:20 +08:00
|
|
|
elseif (builder STREQUAL html)
|
2016-09-23 19:09:33 +08:00
|
|
|
string(TOUPPER "${project}" project_upper)
|
|
|
|
set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html"
|
|
|
|
CACHE STRING "HTML documentation install directory for ${project}")
|
|
|
|
|
|
|
|
# '/.' indicates: copy the contents of the directory directly into
|
|
|
|
# the specified destination, without recreating the last component
|
|
|
|
# of ${SPHINX_BUILD_DIR} implicitly.
|
|
|
|
install(DIRECTORY "${SPHINX_BUILD_DIR}/."
|
2016-12-05 17:15:05 +08:00
|
|
|
COMPONENT "${project}-sphinx-html"
|
2016-09-23 19:09:33 +08:00
|
|
|
DESTINATION "${${project_upper}_INSTALL_SPHINX_HTML_DIR}")
|
2019-10-03 00:06:50 +08:00
|
|
|
|
|
|
|
if(NOT LLVM_ENABLE_IDE)
|
|
|
|
add_llvm_install_targets("install-${SPHINX_TARGET_NAME}"
|
|
|
|
DEPENDS ${SPHINX_TARGET_NAME}
|
|
|
|
COMPONENT "${project}-sphinx-html")
|
|
|
|
endif()
|
2014-04-29 06:06:20 +08:00
|
|
|
else()
|
|
|
|
message(WARNING Installation of ${builder} not supported)
|
|
|
|
endif()
|
2014-04-19 05:45:25 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|