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}") |
| 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() |