Home | History | Annotate | Download | only in modules
      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 (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
     43       if (builder STREQUAL man)
     44         # FIXME: We might not ship all the tools that these man pages describe
     45         install(DIRECTORY "${SPHINX_BUILD_DIR}/" # Slash indicates contents of
     46                 DESTINATION share/man/man1)
     47 
     48       elseif (builder STREQUAL html)
     49         install(DIRECTORY "${SPHINX_BUILD_DIR}"
     50                 DESTINATION "share/doc/${project}")
     51       else()
     52         message(WARNING Installation of ${builder} not supported)
     53       endif()
     54     endif()
     55   endif()
     56 endfunction()
     57