blob: 3456b536e80acc80523a2b733dc86ea9babe1d7b [file] [log] [blame]
Reid Kleckner9f5eb632014-04-18 21:45:25 +00001# 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
7function (add_sphinx_target builder project)
8 set(SPHINX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${builder}")
Michal Gornyfd9f63b2016-10-04 06:09:14 +00009 set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees-${builder}")
Reid Kleckner9f5eb632014-04-18 21:45:25 +000010 set(SPHINX_TARGET_NAME docs-${project}-${builder})
Dan Liewc2867ba2014-08-14 11:57:13 +000011
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 Kleckner9f5eb632014-04-18 21:45:25 +000018 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 Liewc2867ba2014-08-14 11:57:13 +000023 ${SPHINX_WARNINGS_AS_ERRORS_FLAG} # Treat warnings as errors if requested
Reid Kleckner9f5eb632014-04-18 21:45:25 +000024 "${CMAKE_CURRENT_SOURCE_DIR}" # Source
25 "${SPHINX_BUILD_DIR}" # Output
26 COMMENT
Dan Liew992ca1d2014-08-14 11:57:16 +000027 "Generating ${builder} Sphinx documentation for ${project} into \"${SPHINX_BUILD_DIR}\"")
Reid Kleckner9f5eb632014-04-18 21:45:25 +000028
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 Liew923ceca2014-04-28 22:06:20 +000049 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 Gorny0ed8bb42016-12-05 09:15:05 +000053 COMPONENT "${project}-sphinx-man"
Dan Liew923ceca2014-04-28 22:06:20 +000054 DESTINATION share/man/man1)
Reid Kleckner9f5eb632014-04-18 21:45:25 +000055
Dan Liew923ceca2014-04-28 22:06:20 +000056 elseif (builder STREQUAL html)
Michal Gorny63458c32016-09-23 11:09:33 +000057 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 Gorny0ed8bb42016-12-05 09:15:05 +000065 COMPONENT "${project}-sphinx-html"
Michal Gorny63458c32016-09-23 11:09:33 +000066 DESTINATION "${${project_upper}_INSTALL_SPHINX_HTML_DIR}")
Dan Liew923ceca2014-04-28 22:06:20 +000067 else()
68 message(WARNING Installation of ${builder} not supported)
69 endif()
Reid Kleckner9f5eb632014-04-18 21:45:25 +000070 endif()
71 endif()
72endfunction()