CMakeLists.txt 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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.13...3.22 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. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake @ONLY)
  12. unset(CMAKE_DATA_DIR)
  13. unset(CMAKE_DATA_DIR CACHE)
  14. macro(CMake_OPTIONAL_COMPONENT)
  15. set(COMPONENT "")
  16. endmacro()
  17. endif()
  18. project(CMakeHelp NONE)
  19. option(SPHINX_INFO "Build Info manual with Sphinx" OFF)
  20. option(SPHINX_MAN "Build man pages with Sphinx" OFF)
  21. option(SPHINX_HTML "Build html help with Sphinx" OFF)
  22. option(SPHINX_SINGLEHTML "Build html single page help with Sphinx" OFF)
  23. option(SPHINX_QTHELP "Build Qt help with Sphinx" OFF)
  24. option(SPHINX_LATEXPDF "Build PDF help with Sphinx using LaTeX" OFF)
  25. option(SPHINX_TEXT "Build text help with Sphinx (not installed)" OFF)
  26. find_program(SPHINX_EXECUTABLE
  27. NAMES sphinx-build
  28. DOC "Sphinx Documentation Builder (sphinx-doc.org)"
  29. )
  30. set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
  31. separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}")
  32. mark_as_advanced(SPHINX_TEXT)
  33. mark_as_advanced(SPHINX_FLAGS)
  34. 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)
  35. return()
  36. elseif(NOT SPHINX_EXECUTABLE)
  37. message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
  38. endif()
  39. set(copyright_line_regex "^Copyright (2000-20[0-9][0-9] Kitware.*)")
  40. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  41. LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
  42. if(copyright_line MATCHES "${copyright_line_regex}")
  43. set(conf_copyright "${CMAKE_MATCH_1}")
  44. else()
  45. set(conf_copyright "Kitware, Inc.")
  46. endif()
  47. if(CMake_SPHINX_CMAKE_ORG)
  48. set(conf_baseurl "https://cmake.org/cmake/help/latest")
  49. else()
  50. set(conf_baseurl "")
  51. endif()
  52. set(conf_docs "${CMake_SOURCE_DIR}/Help")
  53. set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}")
  54. set(conf_version "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  55. set(conf_release "${CMake_VERSION}")
  56. configure_file(conf.py.in conf.py @ONLY)
  57. set(doc_formats "")
  58. if(SPHINX_HTML)
  59. list(APPEND doc_formats html)
  60. # we provide the path to the produced html output in the console
  61. # for tools that support URI protocol schemes
  62. set(html_post_commands
  63. COMMAND ${CMAKE_COMMAND} -E echo "sphinx-build html: HTML documentation generated in file://${CMAKE_CURRENT_BINARY_DIR}/html/index.html"
  64. )
  65. endif()
  66. if(SPHINX_MAN)
  67. list(APPEND doc_formats man)
  68. endif()
  69. if(SPHINX_SINGLEHTML)
  70. list(APPEND doc_formats singlehtml)
  71. endif()
  72. if(SPHINX_TEXT)
  73. list(APPEND doc_formats text)
  74. endif()
  75. if(SPHINX_INFO)
  76. find_program(MAKEINFO_EXECUTABLE
  77. NAMES makeinfo
  78. DOC "makeinfo tool"
  79. )
  80. if (NOT MAKEINFO_EXECUTABLE)
  81. message(FATAL_ERROR "MAKEINFO_EXECUTABLE (makeinfo) not found!")
  82. endif()
  83. list(APPEND doc_formats texinfo)
  84. # Sphinx texinfo builder supports .info, .txt, .html and .pdf output.
  85. # SPHINX_INFO controls the .info output.
  86. set(texinfo_post_commands
  87. COMMAND ${MAKEINFO_EXECUTABLE} --no-split -o
  88. ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
  89. ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.texi
  90. )
  91. endif()
  92. if(SPHINX_QTHELP)
  93. find_package(Python REQUIRED)
  94. find_program(QHELPGENERATOR_EXECUTABLE
  95. NAMES qhelpgenerator-qt5 qhelpgenerator
  96. DOC "qhelpgenerator tool"
  97. )
  98. if(NOT QHELPGENERATOR_EXECUTABLE)
  99. message(FATAL_ERROR "QHELPGENERATOR_EXECUTABLE (qhelpgenerator) not found!")
  100. endif()
  101. list(APPEND doc_formats qthelp)
  102. set(qthelp_post_commands
  103. # Workaround for assistant prior to
  104. # https://codereview.qt-project.org/#change,82250 in Qt 4.
  105. COMMAND ${CMAKE_COMMAND} "-DCSS_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/_static"
  106. -P "${CMAKE_CURRENT_SOURCE_DIR}/apply_qthelp_css_workaround.cmake"
  107. # Workaround sphinx configurability:
  108. # https://bitbucket.org/birkenfeld/sphinx/issue/1448/make-qthelp-more-configurable
  109. COMMAND ${CMAKE_COMMAND} "-DQTHELP_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
  110. -P "${CMAKE_CURRENT_SOURCE_DIR}/fixup_qthelp_names.cmake"
  111. # Create proper identifiers. Workaround for
  112. # https://bitbucket.org/birkenfeld/sphinx/issue/1491/qthelp-should-generate-identifiers-for
  113. COMMAND "${Python_EXECUTABLE}"
  114. "${CMAKE_CURRENT_SOURCE_DIR}/create_identifiers.py"
  115. "${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
  116. COMMAND ${QHELPGENERATOR_EXECUTABLE}
  117. ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
  118. )
  119. endif()
  120. if(SPHINX_LATEXPDF)
  121. list(APPEND doc_formats latexpdf)
  122. endif()
  123. set(doc_html_opts "")
  124. if(CMake_SPHINX_CMAKE_ORG)
  125. list(APPEND doc_html_opts
  126. -A googleanalytics=1
  127. -A opensearch=1
  128. -A versionswitch=1
  129. )
  130. if(CMake_SPHINX_CMAKE_ORG_OUTDATED)
  131. list(APPEND doc_html_opts -A outdated=1)
  132. endif()
  133. list(APPEND html_pre_commands
  134. COMMAND ${CMAKE_COMMAND} -Dversion=${CMake_VERSION} -P ${CMAKE_CURRENT_SOURCE_DIR}/tutorial_archive.cmake
  135. )
  136. list(APPEND qthelp_post_commands
  137. COMMAND ${CMAKE_COMMAND} -E copy
  138. "${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch"
  139. "${CMAKE_CURRENT_BINARY_DIR}/html/CMake.qch"
  140. )
  141. endif()
  142. set(doc_format_outputs "")
  143. set(doc_format_last "")
  144. foreach(format ${doc_formats})
  145. set(doc_format_output "doc_format_${format}")
  146. set(doc_format_log "build-${format}.log")
  147. if(CMake_SPHINX_CMAKE_ORG)
  148. set(doctrees "doctrees/${format}")
  149. else()
  150. set(doctrees "doctrees")
  151. endif()
  152. if(format STREQUAL "latexpdf")
  153. # This format does not use builder (-b) but make_mode (-M) which expects
  154. # arguments in peculiar order
  155. add_custom_command(
  156. OUTPUT ${doc_format_output}
  157. ${${format}_pre_commands}
  158. COMMAND ${SPHINX_EXECUTABLE}
  159. -M ${format}
  160. ${CMake_SOURCE_DIR}/Help
  161. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  162. -c ${CMAKE_CURRENT_BINARY_DIR}
  163. -d ${CMAKE_CURRENT_BINARY_DIR}/${doctrees}
  164. ${sphinx_flags}
  165. ${doc_${format}_opts}
  166. > ${doc_format_log} # log stdout, pass stderr
  167. ${${format}_post_commands}
  168. DEPENDS ${doc_format_last}
  169. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  170. VERBATIM
  171. )
  172. else()
  173. # other formats use standard builder (-b) mode
  174. add_custom_command(
  175. OUTPUT ${doc_format_output}
  176. ${${format}_pre_commands}
  177. COMMAND ${SPHINX_EXECUTABLE}
  178. -c ${CMAKE_CURRENT_BINARY_DIR}
  179. -d ${CMAKE_CURRENT_BINARY_DIR}/${doctrees}
  180. -b ${format}
  181. ${sphinx_flags}
  182. ${doc_${format}_opts}
  183. ${CMake_SOURCE_DIR}/Help
  184. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  185. > ${doc_format_log} # log stdout, pass stderr
  186. ${${format}_post_commands}
  187. DEPENDS ${doc_format_last}
  188. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  189. VERBATIM
  190. )
  191. endif()
  192. set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
  193. list(APPEND doc_format_outputs ${doc_format_output})
  194. if(NOT CMake_SPHINX_CMAKE_ORG)
  195. set(doc_format_last ${doc_format_output})
  196. endif()
  197. endforeach()
  198. add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
  199. if(CMake_SPHINX_DEPEND_ON_EXECUTABLES)
  200. foreach(t
  201. cmake
  202. ccmake
  203. cmake-gui
  204. cpack
  205. ctest
  206. )
  207. if(TARGET ${t})
  208. # Build documentation after main executables.
  209. add_dependencies(documentation ${t})
  210. endif()
  211. endforeach()
  212. endif()
  213. if(CMake_SPHINX_CMAKE_ORG)
  214. return()
  215. endif()
  216. if(SPHINX_INFO)
  217. CMake_OPTIONAL_COMPONENT(sphinx-info)
  218. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
  219. DESTINATION ${CMAKE_INFO_DIR}
  220. ${COMPONENT}
  221. )
  222. endif()
  223. if(SPHINX_MAN)
  224. file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
  225. ${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
  226. foreach(m ${man_rst})
  227. if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
  228. set(name "${CMAKE_MATCH_1}")
  229. set(sec "${CMAKE_MATCH_2}")
  230. set(skip FALSE)
  231. if(NOT CMakeHelp_STANDALONE)
  232. if(name STREQUAL "ccmake" AND NOT BUILD_CursesDialog)
  233. set(skip TRUE)
  234. elseif(name STREQUAL "cmake-gui" AND NOT BUILD_QtDialog)
  235. set(skip TRUE)
  236. endif()
  237. endif()
  238. if(NOT skip)
  239. CMake_OPTIONAL_COMPONENT(sphinx-man)
  240. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
  241. DESTINATION ${CMAKE_MAN_DIR}/man${sec}
  242. ${COMPONENT})
  243. endif()
  244. unset(skip)
  245. endif()
  246. endforeach()
  247. endif()
  248. if(SPHINX_HTML)
  249. CMake_OPTIONAL_COMPONENT(sphinx-html)
  250. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
  251. DESTINATION ${CMAKE_DOC_DIR}
  252. ${COMPONENT}
  253. PATTERN .buildinfo EXCLUDE
  254. )
  255. endif()
  256. if(SPHINX_SINGLEHTML)
  257. CMake_OPTIONAL_COMPONENT(sphinx-singlehtml)
  258. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
  259. DESTINATION ${CMAKE_DOC_DIR}
  260. ${COMPONENT}
  261. PATTERN .buildinfo EXCLUDE
  262. )
  263. endif()
  264. if(SPHINX_QTHELP)
  265. CMake_OPTIONAL_COMPONENT(sphinx-qthelp)
  266. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch
  267. DESTINATION ${CMAKE_DOC_DIR} ${COMPONENT}
  268. )
  269. endif()
  270. if(SPHINX_LATEXPDF)
  271. CMake_OPTIONAL_COMPONENT(sphinx-latexpdf)
  272. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/latexpdf/latex/CMake.pdf
  273. DESTINATION ${CMAKE_DOC_DIR} ${COMPONENT}
  274. )
  275. endif()