CMakeLists.txt 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. if(NOT CMake_SOURCE_DIR)
  4. set(CMakeHelp_STANDALONE 1)
  5. cmake_minimum_required(VERSION 3.1...3.19 FATAL_ERROR)
  6. get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH)
  7. get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH)
  8. include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake)
  9. include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake)
  10. include(${CMake_SOURCE_DIR}/Source/CMakeInstallDestinations.cmake)
  11. unset(CMAKE_DATA_DIR)
  12. unset(CMAKE_DATA_DIR CACHE)
  13. macro(CMake_OPTIONAL_COMPONENT)
  14. set(COMPONENT "")
  15. endmacro()
  16. endif()
  17. project(CMakeHelp NONE)
  18. option(SPHINX_INFO "Build Info manual with Sphinx" OFF)
  19. option(SPHINX_MAN "Build man pages with Sphinx" OFF)
  20. option(SPHINX_HTML "Build html help with Sphinx" OFF)
  21. option(SPHINX_SINGLEHTML "Build html single page help with Sphinx" OFF)
  22. option(SPHINX_QTHELP "Build Qt help with Sphinx" OFF)
  23. option(SPHINX_LATEXPDF "Build PDF help with Sphinx using LaTeX" OFF)
  24. option(SPHINX_TEXT "Build text help with Sphinx (not installed)" OFF)
  25. find_program(SPHINX_EXECUTABLE
  26. NAMES sphinx-build
  27. DOC "Sphinx Documentation Builder (sphinx-doc.org)"
  28. )
  29. set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
  30. separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}")
  31. mark_as_advanced(SPHINX_TEXT)
  32. mark_as_advanced(SPHINX_FLAGS)
  33. if(NOT SPHINX_INFO AND NOT SPHINX_MAN AND NOT SPHINX_HTML AND NOT SPHINX_SINGLEHTML AND NOT SPHINX_QTHELP AND NOT SPHINX_TEXT AND NOT SPHINX_LATEXPDF)
  34. return()
  35. elseif(NOT SPHINX_EXECUTABLE)
  36. message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
  37. endif()
  38. set(copyright_line_regex "^Copyright (2000-20[0-9][0-9] Kitware.*)")
  39. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  40. LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
  41. if(copyright_line MATCHES "${copyright_line_regex}")
  42. set(conf_copyright "${CMAKE_MATCH_1}")
  43. else()
  44. set(conf_copyright "Kitware, Inc.")
  45. endif()
  46. set(conf_docs "${CMake_SOURCE_DIR}/Help")
  47. set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}")
  48. set(conf_version "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  49. set(conf_release "${CMake_VERSION}")
  50. configure_file(conf.py.in conf.py @ONLY)
  51. set(doc_formats "")
  52. if(SPHINX_HTML)
  53. list(APPEND doc_formats html)
  54. endif()
  55. if(SPHINX_MAN)
  56. list(APPEND doc_formats man)
  57. endif()
  58. if(SPHINX_SINGLEHTML)
  59. list(APPEND doc_formats singlehtml)
  60. endif()
  61. if(SPHINX_TEXT)
  62. list(APPEND doc_formats text)
  63. endif()
  64. if(SPHINX_INFO)
  65. find_program(MAKEINFO_EXECUTABLE
  66. NAMES makeinfo
  67. DOC "makeinfo tool"
  68. )
  69. if (NOT MAKEINFO_EXECUTABLE)
  70. message(FATAL_ERROR "MAKEINFO_EXECUTABLE (makeinfo) not found!")
  71. endif()
  72. list(APPEND doc_formats texinfo)
  73. # Sphinx texinfo builder supports .info, .txt, .html and .pdf output.
  74. # SPHINX_INFO controls the .info output.
  75. set(texinfo_extra_commands
  76. COMMAND ${MAKEINFO_EXECUTABLE} --no-split -o
  77. ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
  78. ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.texi
  79. )
  80. endif()
  81. if(SPHINX_QTHELP)
  82. find_package(PythonInterp REQUIRED)
  83. find_program(QCOLLECTIONGENERATOR_EXECUTABLE
  84. NAMES qcollectiongenerator-qt5 qcollectiongenerator
  85. DOC "qcollectiongenerator tool"
  86. )
  87. if (NOT QCOLLECTIONGENERATOR_EXECUTABLE)
  88. message(FATAL_ERROR "QCOLLECTIONGENERATOR_EXECUTABLE (qcollectiongenerator) not found!")
  89. endif()
  90. list(APPEND doc_formats qthelp)
  91. set(qthelp_extra_commands
  92. # Workaround for assistant prior to
  93. # https://codereview.qt-project.org/#change,82250 in Qt 4.
  94. COMMAND ${CMAKE_COMMAND} "-DCSS_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/_static"
  95. -P "${CMAKE_CURRENT_SOURCE_DIR}/apply_qthelp_css_workaround.cmake"
  96. # Workaround sphinx configurability:
  97. # https://bitbucket.org/birkenfeld/sphinx/issue/1448/make-qthelp-more-configurable
  98. COMMAND ${CMAKE_COMMAND} "-DQTHELP_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
  99. -P "${CMAKE_CURRENT_SOURCE_DIR}/fixup_qthelp_names.cmake"
  100. # Create proper identifiers. Workaround for
  101. # https://bitbucket.org/birkenfeld/sphinx/issue/1491/qthelp-should-generate-identifiers-for
  102. COMMAND "${PYTHON_EXECUTABLE}"
  103. "${CMAKE_CURRENT_SOURCE_DIR}/create_identifiers.py"
  104. "${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
  105. COMMAND ${QCOLLECTIONGENERATOR_EXECUTABLE}
  106. ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
  107. )
  108. endif()
  109. if(SPHINX_LATEXPDF)
  110. list(APPEND doc_formats latexpdf)
  111. endif()
  112. set(doc_format_outputs "")
  113. set(doc_format_last "")
  114. foreach(format ${doc_formats})
  115. set(doc_format_output "doc_format_${format}")
  116. set(doc_format_log "build-${format}.log")
  117. if(format STREQUAL "latexpdf")
  118. # This format does not use builder (-b) but make_mode (-M) which expects
  119. # arguments in peculiar order
  120. add_custom_command(
  121. OUTPUT ${doc_format_output}
  122. COMMAND ${SPHINX_EXECUTABLE}
  123. -M ${format}
  124. ${CMake_SOURCE_DIR}/Help
  125. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  126. -c ${CMAKE_CURRENT_BINARY_DIR}
  127. -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
  128. ${sphinx_flags}
  129. > ${doc_format_log} # log stdout, pass stderr
  130. ${${format}_extra_commands}
  131. DEPENDS ${doc_format_last}
  132. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  133. VERBATIM
  134. )
  135. else()
  136. # other formats use standard builder (-b) mode
  137. add_custom_command(
  138. OUTPUT ${doc_format_output}
  139. COMMAND ${SPHINX_EXECUTABLE}
  140. -c ${CMAKE_CURRENT_BINARY_DIR}
  141. -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
  142. -b ${format}
  143. ${sphinx_flags}
  144. ${CMake_SOURCE_DIR}/Help
  145. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  146. > ${doc_format_log} # log stdout, pass stderr
  147. ${${format}_extra_commands}
  148. DEPENDS ${doc_format_last}
  149. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  150. VERBATIM
  151. )
  152. endif()
  153. set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
  154. list(APPEND doc_format_outputs ${doc_format_output})
  155. set(doc_format_last ${doc_format_output})
  156. endforeach()
  157. add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
  158. if(CMake_SPHINX_DEPEND_ON_EXECUTABLES)
  159. foreach(t
  160. cmake
  161. ccmake
  162. cmake-gui
  163. cpack
  164. ctest
  165. )
  166. if(TARGET ${t})
  167. # Build documentation after main executables.
  168. add_dependencies(documentation ${t})
  169. endif()
  170. endforeach()
  171. endif()
  172. if(SPHINX_INFO)
  173. CMake_OPTIONAL_COMPONENT(sphinx-info)
  174. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
  175. DESTINATION ${CMAKE_INFO_DIR}
  176. ${COMPONENT}
  177. )
  178. endif()
  179. if(SPHINX_MAN)
  180. file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
  181. ${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
  182. foreach(m ${man_rst})
  183. if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
  184. set(name "${CMAKE_MATCH_1}")
  185. set(sec "${CMAKE_MATCH_2}")
  186. set(skip FALSE)
  187. if(NOT CMakeHelp_STANDALONE)
  188. if(name STREQUAL "ccmake" AND NOT BUILD_CursesDialog)
  189. set(skip TRUE)
  190. elseif(name STREQUAL "cmake-gui" AND NOT BUILD_QtDialog)
  191. set(skip TRUE)
  192. endif()
  193. endif()
  194. if(NOT skip)
  195. CMake_OPTIONAL_COMPONENT(sphinx-man)
  196. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
  197. DESTINATION ${CMAKE_MAN_DIR}/man${sec}
  198. ${COMPONENT})
  199. endif()
  200. unset(skip)
  201. endif()
  202. endforeach()
  203. endif()
  204. if(SPHINX_HTML)
  205. CMake_OPTIONAL_COMPONENT(sphinx-html)
  206. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
  207. DESTINATION ${CMAKE_DOC_DIR}
  208. ${COMPONENT}
  209. PATTERN .buildinfo EXCLUDE
  210. )
  211. endif()
  212. if(SPHINX_SINGLEHTML)
  213. CMake_OPTIONAL_COMPONENT(sphinx-singlehtml)
  214. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
  215. DESTINATION ${CMAKE_DOC_DIR}
  216. ${COMPONENT}
  217. PATTERN .buildinfo EXCLUDE
  218. )
  219. endif()
  220. if(SPHINX_QTHELP)
  221. CMake_OPTIONAL_COMPONENT(sphinx-qthelp)
  222. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch
  223. DESTINATION ${CMAKE_DOC_DIR} ${COMPONENT}
  224. )
  225. endif()
  226. if(SPHINX_LATEXPDF)
  227. CMake_OPTIONAL_COMPONENT(sphinx-latexpdf)
  228. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/latexpdf/latex/CMake.pdf
  229. DESTINATION ${CMAKE_DOC_DIR} ${COMPONENT}
  230. )
  231. endif()