Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 4c464de

Browse files
committed
Added Sphinx documentation generation to CMake build system.
The option LLVM_ENABLE_SPHINX option enables the "docs-llvm-html", "docs-llvm-man" targets but does not build them by default. The following CMake options have been added that control what targets are made available SPHINX_OUTPUT_HTML SPHINX_OUTPUT_MAN If LLVM_BUILD_DOCS is enabled then the enabled docs-llvm-* targets will be built by default and if ``make install`` is run then docs-llvm-html and docs-llvm-man will be installed (tested on Linux only). The add_sphinx_target function is in its own file so it can be included by other projects that use Sphinx for their documentation. Patch by Daniel Liew <[email protected]>! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206655 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 08ef020 commit 4c464de

File tree

5 files changed

+106
-1
lines changed

5 files changed

+106
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
287287

288288
option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
289289
option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
290-
option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm documentation." OFF)
290+
option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
291+
option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
291292

292293
option (LLVM_BUILD_EXTERNAL_COMPILER_RT
293294
"Build compiler-rt as an external project." OFF)

cmake/config-ix.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,13 @@ if (LLVM_ENABLE_DOXYGEN)
505505
else()
506506
message(STATUS "Doxygen disabled.")
507507
endif()
508+
509+
if (LLVM_ENABLE_SPHINX)
510+
message(STATUS "Sphinx enabled.")
511+
find_package(Sphinx REQUIRED)
512+
if (LLVM_BUILD_DOCS)
513+
add_custom_target(sphinx ALL)
514+
endif()
515+
else()
516+
message(STATUS "Sphinx disabled.")
517+
endif()

cmake/modules/AddSphinxTarget.cmake

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Handy function for creating the different Sphinx targets.
2+
#
3+
# ``builder`` should be one of the supported builders used by
4+
# the sphinx-build command.
5+
#
6+
# ``project`` should be the project name
7+
function (add_sphinx_target builder project)
8+
set(SPHINX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${builder}")
9+
set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees")
10+
set(SPHINX_TARGET_NAME docs-${project}-${builder})
11+
add_custom_target(${SPHINX_TARGET_NAME}
12+
COMMAND ${SPHINX_EXECUTABLE}
13+
-b ${builder}
14+
-d "${SPHINX_DOC_TREE_DIR}"
15+
-q # Quiet: no output other than errors and warnings.
16+
-W # Warnings are errors.
17+
"${CMAKE_CURRENT_SOURCE_DIR}" # Source
18+
"${SPHINX_BUILD_DIR}" # Output
19+
COMMENT
20+
"Generating ${builder} Sphinx documentation for ${project}")
21+
22+
# When "clean" target is run, remove the Sphinx build directory
23+
set_property(DIRECTORY APPEND PROPERTY
24+
ADDITIONAL_MAKE_CLEAN_FILES
25+
"${SPHINX_BUILD_DIR}")
26+
27+
# We need to remove ${SPHINX_DOC_TREE_DIR} when make clean is run
28+
# but we should only add this path once
29+
get_property(_CURRENT_MAKE_CLEAN_FILES
30+
DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES)
31+
list(FIND _CURRENT_MAKE_CLEAN_FILES "${SPHINX_DOC_TREE_DIR}" _INDEX)
32+
if (_INDEX EQUAL -1)
33+
set_property(DIRECTORY APPEND PROPERTY
34+
ADDITIONAL_MAKE_CLEAN_FILES
35+
"${SPHINX_DOC_TREE_DIR}")
36+
endif()
37+
38+
if (LLVM_BUILD_DOCS)
39+
add_dependencies(sphinx ${SPHINX_TARGET_NAME})
40+
41+
# Handle installation
42+
if (builder STREQUAL man)
43+
# FIXME: We might not ship all the tools that these man pages describe
44+
install(DIRECTORY "${SPHINX_BUILD_DIR}/" # Slash indicates contents of
45+
DESTINATION share/man/man1)
46+
47+
elseif (builder STREQUAL html)
48+
install(DIRECTORY "${SPHINX_BUILD_DIR}"
49+
DESTINATION "share/doc/${project}")
50+
else()
51+
message(WARNING Installation of ${builder} not supported)
52+
endif()
53+
endif()
54+
endfunction()

cmake/modules/FindSphinx.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# CMake find_package() Module for Sphinx documentation generator
2+
# http://sphinx-doc.org/
3+
#
4+
# Example usage:
5+
#
6+
# find_package(Sphinx)
7+
#
8+
# If successful the following variables will be defined
9+
# SPHINX_FOUND
10+
# SPHINX_EXECUTABLE
11+
12+
find_program(SPHINX_EXECUTABLE
13+
NAMES sphinx-build sphinx-build2
14+
DOC "Path to sphinx-build executable")
15+
16+
# Handle REQUIRED and QUIET arguments
17+
# this will also set SPHINX_FOUND to true if SPHINX_EXECUTABLE exists
18+
include(FindPackageHandleStandardArgs)
19+
find_package_handle_standard_args(Sphinx
20+
"Failed to locate sphinx-build executable"
21+
SPHINX_EXECUTABLE)
22+
23+
# Provide options for controlling different types of output
24+
option(SPHINX_OUTPUT_HTML "Output standalone HTML files" ON)
25+
option(SPHINX_OUTPUT_MAN "Output man pages" ON)

docs/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,18 @@ if (LLVM_ENABLE_DOXYGEN)
8989
endif()
9090
endif()
9191
endif()
92+
93+
if (LLVM_ENABLE_SPHINX)
94+
if (SPHINX_FOUND)
95+
include(AddSphinxTarget)
96+
if (${SPHINX_OUTPUT_HTML})
97+
add_sphinx_target(html llvm)
98+
endif()
99+
100+
101+
if (${SPHINX_OUTPUT_MAN})
102+
add_sphinx_target(man llvm)
103+
endif()
104+
105+
endif()
106+
endif()

0 commit comments

Comments
 (0)