Tom Stellard | 9c50cf0 | 2017-05-09 01:41:28 +0000 | [diff] [blame] | 1 | |
| 2 | # Create sphinx target |
Tom Stellard | af79e41 | 2017-05-15 09:34:23 +0000 | [diff] [blame] | 3 | if (LLVM_ENABLE_SPHINX) |
Tom Stellard | 9c50cf0 | 2017-05-09 01:41:28 +0000 | [diff] [blame] | 4 | message(STATUS "Sphinx enabled.") |
| 5 | find_package(Sphinx REQUIRED) |
Tom Stellard | af79e41 | 2017-05-15 09:34:23 +0000 | [diff] [blame] | 6 | if (LLVM_BUILD_DOCS AND NOT TARGET sphinx) |
Tom Stellard | 9c50cf0 | 2017-05-09 01:41:28 +0000 | [diff] [blame] | 7 | add_custom_target(sphinx ALL) |
| 8 | endif() |
| 9 | else() |
| 10 | message(STATUS "Sphinx disabled.") |
| 11 | endif() |
| 12 | |
| 13 | |
Reid Kleckner | 4c464de | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 14 | # Handy function for creating the different Sphinx targets. |
| 15 | # |
| 16 | # ``builder`` should be one of the supported builders used by |
| 17 | # the sphinx-build command. |
| 18 | # |
| 19 | # ``project`` should be the project name |
| 20 | function (add_sphinx_target builder project) |
| 21 | set(SPHINX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${builder}") |
Michal Gorny | 14540ca | 2017-11-30 19:09:22 +0000 | [diff] [blame] | 22 | set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees-${project}-${builder}") |
Reid Kleckner | 4c464de | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 23 | set(SPHINX_TARGET_NAME docs-${project}-${builder}) |
Dan Liew | 550abf8 | 2014-08-14 11:57:13 +0000 | [diff] [blame] | 24 | |
| 25 | if (SPHINX_WARNINGS_AS_ERRORS) |
| 26 | set(SPHINX_WARNINGS_AS_ERRORS_FLAG "-W") |
| 27 | else() |
| 28 | set(SPHINX_WARNINGS_AS_ERRORS_FLAG "") |
| 29 | endif() |
| 30 | |
Reid Kleckner | 4c464de | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 31 | add_custom_target(${SPHINX_TARGET_NAME} |
| 32 | COMMAND ${SPHINX_EXECUTABLE} |
| 33 | -b ${builder} |
| 34 | -d "${SPHINX_DOC_TREE_DIR}" |
| 35 | -q # Quiet: no output other than errors and warnings. |
Dan Liew | 550abf8 | 2014-08-14 11:57:13 +0000 | [diff] [blame] | 36 | ${SPHINX_WARNINGS_AS_ERRORS_FLAG} # Treat warnings as errors if requested |
Reid Kleckner | 4c464de | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 37 | "${CMAKE_CURRENT_SOURCE_DIR}" # Source |
| 38 | "${SPHINX_BUILD_DIR}" # Output |
| 39 | COMMENT |
Dan Liew | 43d6849 | 2014-08-14 11:57:16 +0000 | [diff] [blame] | 40 | "Generating ${builder} Sphinx documentation for ${project} into \"${SPHINX_BUILD_DIR}\"") |
Reid Kleckner | 4c464de | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 41 | |
| 42 | # When "clean" target is run, remove the Sphinx build directory |
| 43 | set_property(DIRECTORY APPEND PROPERTY |
| 44 | ADDITIONAL_MAKE_CLEAN_FILES |
| 45 | "${SPHINX_BUILD_DIR}") |
| 46 | |
| 47 | # We need to remove ${SPHINX_DOC_TREE_DIR} when make clean is run |
| 48 | # but we should only add this path once |
| 49 | get_property(_CURRENT_MAKE_CLEAN_FILES |
| 50 | DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES) |
| 51 | list(FIND _CURRENT_MAKE_CLEAN_FILES "${SPHINX_DOC_TREE_DIR}" _INDEX) |
| 52 | if (_INDEX EQUAL -1) |
| 53 | set_property(DIRECTORY APPEND PROPERTY |
| 54 | ADDITIONAL_MAKE_CLEAN_FILES |
| 55 | "${SPHINX_DOC_TREE_DIR}") |
| 56 | endif() |
| 57 | |
| 58 | if (LLVM_BUILD_DOCS) |
| 59 | add_dependencies(sphinx ${SPHINX_TARGET_NAME}) |
| 60 | |
| 61 | # Handle installation |
Dan Liew | 00f0627 | 2014-04-28 22:06:20 +0000 | [diff] [blame] | 62 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 63 | if (builder STREQUAL man) |
Jonathan Roelofs | 50982d3 | 2017-04-05 14:49:46 +0000 | [diff] [blame] | 64 | if (CMAKE_INSTALL_MANDIR) |
| 65 | set(INSTALL_MANDIR ${CMAKE_INSTALL_MANDIR}/) |
| 66 | else() |
| 67 | set(INSTALL_MANDIR share/man/) |
| 68 | endif() |
Dan Liew | 00f0627 | 2014-04-28 22:06:20 +0000 | [diff] [blame] | 69 | # FIXME: We might not ship all the tools that these man pages describe |
| 70 | install(DIRECTORY "${SPHINX_BUILD_DIR}/" # Slash indicates contents of |
Michal Gorny | 02114e6 | 2016-12-05 09:15:05 +0000 | [diff] [blame] | 71 | COMPONENT "${project}-sphinx-man" |
Jonathan Roelofs | 50982d3 | 2017-04-05 14:49:46 +0000 | [diff] [blame] | 72 | DESTINATION ${INSTALL_MANDIR}man1) |
Reid Kleckner | 4c464de | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 73 | |
Dan Liew | 00f0627 | 2014-04-28 22:06:20 +0000 | [diff] [blame] | 74 | elseif (builder STREQUAL html) |
Michal Gorny | 91fdd2b | 2016-09-23 11:09:33 +0000 | [diff] [blame] | 75 | string(TOUPPER "${project}" project_upper) |
| 76 | set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" |
| 77 | CACHE STRING "HTML documentation install directory for ${project}") |
| 78 | |
| 79 | # '/.' indicates: copy the contents of the directory directly into |
| 80 | # the specified destination, without recreating the last component |
| 81 | # of ${SPHINX_BUILD_DIR} implicitly. |
| 82 | install(DIRECTORY "${SPHINX_BUILD_DIR}/." |
Michal Gorny | 02114e6 | 2016-12-05 09:15:05 +0000 | [diff] [blame] | 83 | COMPONENT "${project}-sphinx-html" |
Michal Gorny | 91fdd2b | 2016-09-23 11:09:33 +0000 | [diff] [blame] | 84 | DESTINATION "${${project_upper}_INSTALL_SPHINX_HTML_DIR}") |
Dan Liew | 00f0627 | 2014-04-28 22:06:20 +0000 | [diff] [blame] | 85 | else() |
| 86 | message(WARNING Installation of ${builder} not supported) |
| 87 | endif() |
Reid Kleckner | 4c464de | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 88 | endif() |
| 89 | endif() |
| 90 | endfunction() |