cmake/Utilities/Sphinx/CMakeLists.txt

339 lines
11 KiB
CMake
Raw Normal View History

2016-10-30 18:24:19 +01:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2014-08-03 19:52:23 +02:00
if(NOT CMake_SOURCE_DIR)
set(CMakeHelp_STANDALONE 1)
2023-07-02 19:51:09 +02:00
cmake_minimum_required(VERSION 3.13...3.25 FATAL_ERROR)
2014-08-03 19:52:23 +02:00
get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH)
get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH)
include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake)
2020-02-01 23:06:01 +01:00
include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake)
2014-08-03 19:52:23 +02:00
include(${CMake_SOURCE_DIR}/Source/CMakeInstallDestinations.cmake)
2022-03-29 21:10:50 +02:00
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake @ONLY)
2014-08-03 19:52:23 +02:00
unset(CMAKE_DATA_DIR)
unset(CMAKE_DATA_DIR CACHE)
2015-11-17 17:22:37 +01:00
macro(CMake_OPTIONAL_COMPONENT)
set(COMPONENT "")
endmacro()
2014-08-03 19:52:23 +02:00
endif()
project(CMakeHelp NONE)
2018-08-09 18:06:22 +02:00
option(SPHINX_INFO "Build Info manual with Sphinx" OFF)
2014-08-03 19:52:23 +02:00
option(SPHINX_MAN "Build man pages with Sphinx" OFF)
option(SPHINX_HTML "Build html help with Sphinx" OFF)
option(SPHINX_SINGLEHTML "Build html single page help with Sphinx" OFF)
2023-05-23 16:38:00 +02:00
option(SPHINX_LINKCHECK "Check external links mentioned in documentation" OFF)
2015-04-27 22:25:09 +02:00
option(SPHINX_QTHELP "Build Qt help with Sphinx" OFF)
2021-09-14 00:13:48 +02:00
option(SPHINX_LATEXPDF "Build PDF help with Sphinx using LaTeX" OFF)
2014-08-03 19:52:23 +02:00
option(SPHINX_TEXT "Build text help with Sphinx (not installed)" OFF)
find_program(SPHINX_EXECUTABLE
NAMES sphinx-build
DOC "Sphinx Documentation Builder (sphinx-doc.org)"
)
2015-08-17 11:37:30 +02:00
set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}")
2014-08-03 19:52:23 +02:00
mark_as_advanced(SPHINX_TEXT)
2015-08-17 11:37:30 +02:00
mark_as_advanced(SPHINX_FLAGS)
2014-08-03 19:52:23 +02:00
2023-05-23 16:38:00 +02:00
if(NOT (SPHINX_INFO
OR SPHINX_MAN
OR SPHINX_HTML
OR SPHINX_SINGLEHTML
OR SPHINX_LINKCHECK
OR SPHINX_QTHELP
OR SPHINX_TEXT
OR SPHINX_LATEXPDF
))
2014-08-03 19:52:23 +02:00
return()
elseif(NOT SPHINX_EXECUTABLE)
message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
endif()
set(copyright_line_regex "^Copyright (2000-20[0-9][0-9] Kitware.*)")
file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
if(copyright_line MATCHES "${copyright_line_regex}")
set(conf_copyright "${CMAKE_MATCH_1}")
else()
set(conf_copyright "Kitware, Inc.")
endif()
2022-04-13 00:32:21 +02:00
if(CMake_SPHINX_CMAKE_ORG)
set(conf_baseurl "https://cmake.org/cmake/help/latest")
else()
set(conf_baseurl "")
endif()
2014-08-03 19:52:23 +02:00
set(conf_docs "${CMake_SOURCE_DIR}/Help")
set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}")
set(conf_version "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
set(conf_release "${CMake_VERSION}")
configure_file(conf.py.in conf.py @ONLY)
set(doc_formats "")
if(SPHINX_HTML)
list(APPEND doc_formats html)
2021-11-20 13:41:27 +01:00
# we provide the path to the produced html output in the console
# for tools that support URI protocol schemes
2022-05-25 20:56:39 +02:00
set(html_post_commands
2021-11-20 13:41:27 +01:00
COMMAND ${CMAKE_COMMAND} -E echo "sphinx-build html: HTML documentation generated in file://${CMAKE_CURRENT_BINARY_DIR}/html/index.html"
)
2014-08-03 19:52:23 +02:00
endif()
if(SPHINX_MAN)
list(APPEND doc_formats man)
endif()
if(SPHINX_SINGLEHTML)
list(APPEND doc_formats singlehtml)
endif()
2023-05-23 16:38:00 +02:00
if(SPHINX_LINKCHECK)
list(APPEND doc_formats linkcheck)
#
set(linkcheck_post_commands
COMMAND ${CMAKE_COMMAND} -E echo "sphinx-build linkcheck: see checking status in file://${CMAKE_CURRENT_BINARY_DIR}/linkcheck/output.txt"
)
endif()
2014-08-03 19:52:23 +02:00
if(SPHINX_TEXT)
list(APPEND doc_formats text)
endif()
2018-08-09 18:06:22 +02:00
if(SPHINX_INFO)
find_program(MAKEINFO_EXECUTABLE
NAMES makeinfo
DOC "makeinfo tool"
)
if (NOT MAKEINFO_EXECUTABLE)
message(FATAL_ERROR "MAKEINFO_EXECUTABLE (makeinfo) not found!")
endif()
list(APPEND doc_formats texinfo)
# Sphinx texinfo builder supports .info, .txt, .html and .pdf output.
# SPHINX_INFO controls the .info output.
2022-05-25 20:56:39 +02:00
set(texinfo_post_commands
2018-08-09 18:06:22 +02:00
COMMAND ${MAKEINFO_EXECUTABLE} --no-split -o
${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.texi
)
endif()
2015-04-27 22:25:09 +02:00
if(SPHINX_QTHELP)
2022-08-04 22:12:04 +02:00
find_package(Python REQUIRED)
2015-04-27 22:25:09 +02:00
2022-04-13 00:32:21 +02:00
find_program(QHELPGENERATOR_EXECUTABLE
NAMES qhelpgenerator-qt5 qhelpgenerator
DOC "qhelpgenerator tool"
2015-04-27 22:25:09 +02:00
)
2022-04-13 00:32:21 +02:00
if(NOT QHELPGENERATOR_EXECUTABLE)
message(FATAL_ERROR "QHELPGENERATOR_EXECUTABLE (qhelpgenerator) not found!")
2015-04-27 22:25:09 +02:00
endif()
list(APPEND doc_formats qthelp)
2022-05-25 20:56:39 +02:00
set(qthelp_post_commands
2015-04-27 22:25:09 +02:00
# Workaround for assistant prior to
# https://codereview.qt-project.org/#change,82250 in Qt 4.
COMMAND ${CMAKE_COMMAND} "-DCSS_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/_static"
-P "${CMAKE_CURRENT_SOURCE_DIR}/apply_qthelp_css_workaround.cmake"
# Workaround sphinx configurability:
2022-11-16 20:14:03 +01:00
# https://github.com/sphinx-doc/sphinx/issues/1448
2015-04-27 22:25:09 +02:00
COMMAND ${CMAKE_COMMAND} "-DQTHELP_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
-P "${CMAKE_CURRENT_SOURCE_DIR}/fixup_qthelp_names.cmake"
# Create proper identifiers. Workaround for
2022-11-16 20:14:03 +01:00
# https://github.com/sphinx-doc/sphinx/issues/1491
2022-08-04 22:12:04 +02:00
COMMAND "${Python_EXECUTABLE}"
2015-04-27 22:25:09 +02:00
"${CMAKE_CURRENT_SOURCE_DIR}/create_identifiers.py"
"${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
2022-04-13 00:32:21 +02:00
COMMAND ${QHELPGENERATOR_EXECUTABLE}
2015-04-27 22:25:09 +02:00
${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
)
endif()
2021-09-14 00:13:48 +02:00
if(SPHINX_LATEXPDF)
list(APPEND doc_formats latexpdf)
endif()
2014-08-03 19:52:23 +02:00
2022-04-13 00:32:21 +02:00
set(doc_html_opts "")
if(CMake_SPHINX_CMAKE_ORG)
list(APPEND doc_html_opts
-A googleanalytics=1
-A opensearch=1
-A versionswitch=1
)
if(CMake_SPHINX_CMAKE_ORG_OUTDATED)
list(APPEND doc_html_opts -A outdated=1)
endif()
2022-05-25 20:56:39 +02:00
list(APPEND html_pre_commands
COMMAND ${CMAKE_COMMAND} -Dversion=${CMake_VERSION} -P ${CMAKE_CURRENT_SOURCE_DIR}/tutorial_archive.cmake
)
list(APPEND qthelp_post_commands
2022-04-13 00:32:21 +02:00
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch"
"${CMAKE_CURRENT_BINARY_DIR}/html/CMake.qch"
)
endif()
2023-05-23 16:38:00 +02:00
# Redirect `sphinx-build` output to `build-<format>.log` file?
set(sphinx_use_build_log TRUE)
set(sphinx_verbose_levels "DEBUG;TRACE")
set(sphinx_no_redirect_levels "VERBOSE;${sphinx_verbose_levels}")
# NOTE There is no generic verbosity level for all supported generators,
# so lets use CMake verbosity level to control if `sphinx-build` should
# redirect it's output to a file or a user wants to see it at build time.
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.25)
cmake_language(GET_MESSAGE_LOG_LEVEL verbose_level)
else()
# If building under CMake < 3.25, fallback to `CMAKE_MESSAGE_LOG_LEVEL`
# variable. It was added in 3.17 but it's OK to set it even for older
# versions (w/o any effect on `message()` command of course).
set(verbose_level ${CMAKE_MESSAGE_LOG_LEVEL})
endif()
if(DEFINED ENV{VERBOSE} OR CMAKE_VERBOSE_MAKEFILE OR verbose_level IN_LIST sphinx_no_redirect_levels)
set(sphinx_use_build_log FALSE)
if(verbose_level IN_LIST sphinx_verbose_levels)
# NOTE Sphinx accept multiple `-v` options for more verbosity
# but the output mostly for Sphinx developers...
list(APPEND sphinx_flags "-v")
endif()
endif()
2014-08-03 19:52:23 +02:00
set(doc_format_outputs "")
set(doc_format_last "")
2022-11-16 20:14:03 +01:00
foreach(format IN LISTS doc_formats)
2014-08-03 19:52:23 +02:00
set(doc_format_output "doc_format_${format}")
2023-05-23 16:38:00 +02:00
set(doc_format_log "")
set(build_comment_tail " ...")
if(sphinx_use_build_log)
set(doc_format_log "build-${format}.log")
set(build_comment_tail ": see Utilities/Sphinx/${doc_format_log}")
list(PREPEND doc_format_log ">")
endif()
2022-04-13 00:32:21 +02:00
if(CMake_SPHINX_CMAKE_ORG)
set(doctrees "doctrees/${format}")
else()
set(doctrees "doctrees")
endif()
2021-09-14 00:13:48 +02:00
if(format STREQUAL "latexpdf")
# This format does not use builder (-b) but make_mode (-M) which expects
# arguments in peculiar order
2023-05-23 16:38:00 +02:00
set(_args
-M ${format}
${CMake_SOURCE_DIR}/Help
${CMAKE_CURRENT_BINARY_DIR}/${format}
-c ${CMAKE_CURRENT_BINARY_DIR}
-d ${CMAKE_CURRENT_BINARY_DIR}/${doctrees}
${sphinx_flags}
${doc_${format}_opts}
2021-09-14 00:13:48 +02:00
)
else()
# other formats use standard builder (-b) mode
2023-05-23 16:38:00 +02:00
set(_args
-c ${CMAKE_CURRENT_BINARY_DIR}
-d ${CMAKE_CURRENT_BINARY_DIR}/${doctrees}
-b ${format}
${sphinx_flags}
${doc_${format}_opts}
${CMake_SOURCE_DIR}/Help
${CMAKE_CURRENT_BINARY_DIR}/${format}
2021-09-14 00:13:48 +02:00
)
endif()
2023-05-23 16:38:00 +02:00
add_custom_command(
OUTPUT ${doc_format_output}
${${format}_pre_commands}
COMMAND ${SPHINX_EXECUTABLE} ${_args} ${doc_format_log}
${${format}_post_commands}
DEPENDS ${doc_format_last}
COMMENT "sphinx-build ${format}${build_comment_tail}"
VERBATIM
)
2014-08-03 19:52:23 +02:00
set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
list(APPEND doc_format_outputs ${doc_format_output})
2022-04-13 00:32:21 +02:00
if(NOT CMake_SPHINX_CMAKE_ORG)
set(doc_format_last ${doc_format_output})
endif()
2014-08-03 19:52:23 +02:00
endforeach()
add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
2017-07-20 19:35:53 +02:00
if(CMake_SPHINX_DEPEND_ON_EXECUTABLES)
2022-11-16 20:14:03 +01:00
foreach(t IN ITEMS cmake ccmake cmake-gui cpack ctest)
2017-07-20 19:35:53 +02:00
if(TARGET ${t})
# Build documentation after main executables.
add_dependencies(documentation ${t})
endif()
endforeach()
endif()
2014-08-03 19:52:23 +02:00
2022-04-13 00:32:21 +02:00
if(CMake_SPHINX_CMAKE_ORG)
return()
endif()
2018-08-09 18:06:22 +02:00
if(SPHINX_INFO)
CMake_OPTIONAL_COMPONENT(sphinx-info)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
DESTINATION ${CMAKE_INFO_DIR}
${COMPONENT}
)
endif()
2014-08-03 19:52:23 +02:00
if(SPHINX_MAN)
file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
2022-11-16 20:14:03 +01:00
foreach(m IN LISTS man_rst)
2014-08-03 19:52:23 +02:00
if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
set(name "${CMAKE_MATCH_1}")
set(sec "${CMAKE_MATCH_2}")
2016-10-30 18:24:19 +01:00
set(skip FALSE)
2016-03-13 13:35:51 +01:00
if(NOT CMakeHelp_STANDALONE)
if(name STREQUAL "ccmake" AND NOT BUILD_CursesDialog)
2016-10-30 18:24:19 +01:00
set(skip TRUE)
elseif(name STREQUAL "cmake-gui" AND NOT BUILD_QtDialog)
set(skip TRUE)
2016-03-13 13:35:51 +01:00
endif()
endif()
2016-10-30 18:24:19 +01:00
if(NOT skip)
CMake_OPTIONAL_COMPONENT(sphinx-man)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
DESTINATION ${CMAKE_MAN_DIR}/man${sec}
${COMPONENT})
endif()
unset(skip)
2014-08-03 19:52:23 +02:00
endif()
endforeach()
endif()
if(SPHINX_HTML)
2015-11-17 17:22:37 +01:00
CMake_OPTIONAL_COMPONENT(sphinx-html)
2014-08-03 19:52:23 +02:00
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION ${CMAKE_DOC_DIR}
2015-11-17 17:22:37 +01:00
${COMPONENT}
2014-08-03 19:52:23 +02:00
PATTERN .buildinfo EXCLUDE
)
endif()
if(SPHINX_SINGLEHTML)
2015-11-17 17:22:37 +01:00
CMake_OPTIONAL_COMPONENT(sphinx-singlehtml)
2014-08-03 19:52:23 +02:00
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
DESTINATION ${CMAKE_DOC_DIR}
2015-11-17 17:22:37 +01:00
${COMPONENT}
2014-08-03 19:52:23 +02:00
PATTERN .buildinfo EXCLUDE
)
endif()
2015-04-27 22:25:09 +02:00
if(SPHINX_QTHELP)
2015-11-17 17:22:37 +01:00
CMake_OPTIONAL_COMPONENT(sphinx-qthelp)
2020-02-01 23:06:01 +01:00
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch
2015-11-17 17:22:37 +01:00
DESTINATION ${CMAKE_DOC_DIR} ${COMPONENT}
2015-04-27 22:25:09 +02:00
)
endif()
2021-09-14 00:13:48 +02:00
if(SPHINX_LATEXPDF)
CMake_OPTIONAL_COMPONENT(sphinx-latexpdf)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/latexpdf/latex/CMake.pdf
DESTINATION ${CMAKE_DOC_DIR} ${COMPONENT}
)
endif()