2021-12-12 08:07:13 -09:00
|
|
|
include(GNUInstallDirs)
|
2017-05-08 17:41:28 -08:00
|
|
|
|
|
|
|
|
# Create sphinx target
|
2017-05-15 01:34:23 -08:00
|
|
|
if (LLVM_ENABLE_SPHINX)
|
2017-05-08 17:41:28 -08:00
|
|
|
message(STATUS "Sphinx enabled.")
|
|
|
|
|
find_package(Sphinx REQUIRED)
|
2017-05-15 01:34:23 -08:00
|
|
|
if (LLVM_BUILD_DOCS AND NOT TARGET sphinx)
|
2017-05-08 17:41:28 -08:00
|
|
|
add_custom_target(sphinx ALL)
|
2024-05-25 03:28:30 -08:00
|
|
|
set_target_properties(sphinx PROPERTIES FOLDER "LLVM/Docs")
|
2017-05-08 17:41:28 -08:00
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
message(STATUS "Sphinx disabled.")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
2014-04-18 13: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 03:24:24 -09: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-18 13:45:25 -08:00
|
|
|
function (add_sphinx_target builder project)
|
2021-01-15 03:24:24 -09:00
|
|
|
cmake_parse_arguments(ARG "" "SOURCE_DIR" "ENV_VARS" ${ARGN})
|
2014-04-18 13:45:25 -08:00
|
|
|
set(SPHINX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${builder}")
|
2017-11-30 10:09:22 -09:00
|
|
|
set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees-${project}-${builder}")
|
2014-04-18 13:45:25 -08:00
|
|
|
set(SPHINX_TARGET_NAME docs-${project}-${builder})
|
2014-08-14 03: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-05 18:57:24 -09:00
|
|
|
if (NOT ARG_SOURCE_DIR)
|
|
|
|
|
set(ARG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-02-01 22:13:01 -09:00
|
|
|
if ("${LLVM_VERSION_SUFFIX}" STREQUAL "git")
|
|
|
|
|
set(PreReleaseTag "-tPreRelease")
|
|
|
|
|
endif()
|
|
|
|
|
|
2014-04-18 13:45:25 -08:00
|
|
|
add_custom_target(${SPHINX_TARGET_NAME}
|
2021-01-15 03:24:24 -09:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env ${ARG_ENV_VARS}
|
[docs] Create utils/docs (#203962)
llvm-project is home to many sphinx documentation sites, each with
configuration quirks and bespoke extensions.
The sphinx config model makes sharing code somewhat difficult. There
are options like sphinx-multiproject, but some of our docs builds are
out of the source tree while some are done out of the binary tree, so
the multiproject configuration itself would need to be generated. It
also would impose more uniformity around extensions than required.
This change instead creates a python package at utils/docs/llvm_sphinx
and makes it available to all sphinx-build processes via PYTHONPATH.
Each conf.py does not modify its own sys.path because not all builds are
out of the source tree, so there isn't a stable relative path to use to
refer to the utils/docs/ directory.
Type checking via pyright in new package is pinned to being python 3.8
compatible.
The myst slug script from llvm/docs is promoted to be the default,
with a slight edit to targets needed in FlangDriver.md to adapt to the
change.
The ghlinks extension from clang gets lifted to be the first generic
extension, although it is still only used in clang currently. I used it
as an example of a general extension that might be useful for other
projects, but I also intend to add a new generic extension in a future
patch.
As part of the move ghlinks is refactored a bit:
* Rather than have a main function directly to run its tests, those
tests are now run via the command-line entrypoint to the new package,
e.g. `python utils/docs --test` will now replace
`python clang/docs/ghlinks.py --test`. This makes the command-line
more pithy (`python utils/docs/llvm_sphinx/ext/ghlinks --test` is a
bit long), and makes the default behavior when running be to
include utils/docs in the sys.path, so imports can be absolute and
the behavior is as close to the CMake targets as possible.
* The static files that were previously written to a tempdir during
testing are just committed directly in git. The assumption here is
that the original version was taking pains to avoid polluting the
clang/docs directory with test files that would confuse sphinx-build,
and without that limitation the workaround can be removed.
* Some typing-related changes to make it strictly python 3.8 compatible.
Change-Id: Ie16de273f74973f163dbf7fe9d22d80a466d051f
2026-06-24 11:12:48 -08:00
|
|
|
--modify "PYTHONPATH=path_list_append:${LLVM_MAIN_SRC_DIR}/../utils/docs"
|
2021-01-15 03:24:24 -09:00
|
|
|
${SPHINX_EXECUTABLE}
|
2014-04-18 13:45:25 -08:00
|
|
|
-b ${builder}
|
|
|
|
|
-d "${SPHINX_DOC_TREE_DIR}"
|
|
|
|
|
-q # Quiet: no output other than errors and warnings.
|
2020-07-04 09:23:48 -08:00
|
|
|
-t builder-${builder} # tag for builder
|
2022-02-01 22:13:01 -09:00
|
|
|
-D version=${LLVM_VERSION_MAJOR}
|
|
|
|
|
-D release=${PACKAGE_VERSION}
|
|
|
|
|
${PreReleaseTag}
|
2014-08-14 03: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-05 18:57:24 -09:00
|
|
|
"${ARG_SOURCE_DIR}" # Source
|
2014-04-18 13:45:25 -08:00
|
|
|
"${SPHINX_BUILD_DIR}" # Output
|
|
|
|
|
COMMENT
|
2014-08-14 03:57:16 -08:00
|
|
|
"Generating ${builder} Sphinx documentation for ${project} into \"${SPHINX_BUILD_DIR}\"")
|
2024-05-25 03:28:30 -08:00
|
|
|
get_subproject_title(subproject_title)
|
|
|
|
|
set_target_properties(${SPHINX_TARGET_NAME} PROPERTIES FOLDER "${subproject_title}/Docs")
|
2014-04-18 13: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)
|
2023-01-23 13:58:43 -09:00
|
|
|
if (NOT "${SPHINX_DOC_TREE_DIR}" IN_LIST _CURRENT_MAKE_CLEAN_FILES)
|
2014-04-18 13:45:25 -08:00
|
|
|
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-28 14:06:20 -08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
|
if (builder STREQUAL man)
|
|
|
|
|
# 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 00:15:05 -09:00
|
|
|
COMPONENT "${project}-sphinx-man"
|
2021-12-12 08:07:13 -09:00
|
|
|
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
|
2014-04-18 13:45:25 -08:00
|
|
|
|
2019-10-02 08: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-28 14:06:20 -08:00
|
|
|
elseif (builder STREQUAL html)
|
2016-09-23 03:09:33 -08:00
|
|
|
string(TOUPPER "${project}" project_upper)
|
2021-12-10 16:36:24 -09:00
|
|
|
set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html"
|
2016-09-23 03:09:33 -08:00
|
|
|
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 00:15:05 -09:00
|
|
|
COMPONENT "${project}-sphinx-html"
|
2016-09-23 03:09:33 -08:00
|
|
|
DESTINATION "${${project_upper}_INSTALL_SPHINX_HTML_DIR}")
|
2019-10-02 08: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-28 14:06:20 -08:00
|
|
|
else()
|
|
|
|
|
message(WARNING Installation of ${builder} not supported)
|
|
|
|
|
endif()
|
2014-04-18 13:45:25 -08:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|