Reid Kleckner | 9f5eb63 | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 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}") |
Michal Gorny | fd9f63b | 2016-10-04 06:09:14 +0000 | [diff] [blame] | 9 | set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees-${builder}") |
Reid Kleckner | 9f5eb63 | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 10 | set(SPHINX_TARGET_NAME docs-${project}-${builder}) |
Dan Liew | c2867ba | 2014-08-14 11:57:13 +0000 | [diff] [blame] | 11 | |
| 12 | if (SPHINX_WARNINGS_AS_ERRORS) |
| 13 | set(SPHINX_WARNINGS_AS_ERRORS_FLAG "-W") |
| 14 | else() |
| 15 | set(SPHINX_WARNINGS_AS_ERRORS_FLAG "") |
| 16 | endif() |
| 17 | |
Reid Kleckner | 9f5eb63 | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 18 | add_custom_target(${SPHINX_TARGET_NAME} |
| 19 | COMMAND ${SPHINX_EXECUTABLE} |
| 20 | -b ${builder} |
| 21 | -d "${SPHINX_DOC_TREE_DIR}" |
| 22 | -q # Quiet: no output other than errors and warnings. |
Dan Liew | c2867ba | 2014-08-14 11:57:13 +0000 | [diff] [blame] | 23 | ${SPHINX_WARNINGS_AS_ERRORS_FLAG} # Treat warnings as errors if requested |
Reid Kleckner | 9f5eb63 | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 24 | "${CMAKE_CURRENT_SOURCE_DIR}" # Source |
| 25 | "${SPHINX_BUILD_DIR}" # Output |
| 26 | COMMENT |
Dan Liew | 992ca1d | 2014-08-14 11:57:16 +0000 | [diff] [blame] | 27 | "Generating ${builder} Sphinx documentation for ${project} into \"${SPHINX_BUILD_DIR}\"") |
Reid Kleckner | 9f5eb63 | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 28 | |
| 29 | # When "clean" target is run, remove the Sphinx build directory |
| 30 | set_property(DIRECTORY APPEND PROPERTY |
| 31 | ADDITIONAL_MAKE_CLEAN_FILES |
| 32 | "${SPHINX_BUILD_DIR}") |
| 33 | |
| 34 | # We need to remove ${SPHINX_DOC_TREE_DIR} when make clean is run |
| 35 | # but we should only add this path once |
| 36 | get_property(_CURRENT_MAKE_CLEAN_FILES |
| 37 | DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES) |
| 38 | list(FIND _CURRENT_MAKE_CLEAN_FILES "${SPHINX_DOC_TREE_DIR}" _INDEX) |
| 39 | if (_INDEX EQUAL -1) |
| 40 | set_property(DIRECTORY APPEND PROPERTY |
| 41 | ADDITIONAL_MAKE_CLEAN_FILES |
| 42 | "${SPHINX_DOC_TREE_DIR}") |
| 43 | endif() |
| 44 | |
| 45 | if (LLVM_BUILD_DOCS) |
| 46 | add_dependencies(sphinx ${SPHINX_TARGET_NAME}) |
| 47 | |
| 48 | # Handle installation |
Dan Liew | 923ceca | 2014-04-28 22:06:20 +0000 | [diff] [blame] | 49 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 50 | if (builder STREQUAL man) |
| 51 | # FIXME: We might not ship all the tools that these man pages describe |
| 52 | install(DIRECTORY "${SPHINX_BUILD_DIR}/" # Slash indicates contents of |
Michal Gorny | 0ed8bb4 | 2016-12-05 09:15:05 +0000 | [diff] [blame] | 53 | COMPONENT "${project}-sphinx-man" |
Dan Liew | 923ceca | 2014-04-28 22:06:20 +0000 | [diff] [blame] | 54 | DESTINATION share/man/man1) |
Reid Kleckner | 9f5eb63 | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 55 | |
Dan Liew | 923ceca | 2014-04-28 22:06:20 +0000 | [diff] [blame] | 56 | elseif (builder STREQUAL html) |
Michal Gorny | 63458c3 | 2016-09-23 11:09:33 +0000 | [diff] [blame] | 57 | string(TOUPPER "${project}" project_upper) |
| 58 | set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" |
| 59 | CACHE STRING "HTML documentation install directory for ${project}") |
| 60 | |
| 61 | # '/.' indicates: copy the contents of the directory directly into |
| 62 | # the specified destination, without recreating the last component |
| 63 | # of ${SPHINX_BUILD_DIR} implicitly. |
| 64 | install(DIRECTORY "${SPHINX_BUILD_DIR}/." |
Michal Gorny | 0ed8bb4 | 2016-12-05 09:15:05 +0000 | [diff] [blame] | 65 | COMPONENT "${project}-sphinx-html" |
Michal Gorny | 63458c3 | 2016-09-23 11:09:33 +0000 | [diff] [blame] | 66 | DESTINATION "${${project_upper}_INSTALL_SPHINX_HTML_DIR}") |
Dan Liew | 923ceca | 2014-04-28 22:06:20 +0000 | [diff] [blame] | 67 | else() |
| 68 | message(WARNING Installation of ${builder} not supported) |
| 69 | endif() |
Reid Kleckner | 9f5eb63 | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 70 | endif() |
| 71 | endif() |
| 72 | endfunction() |