CMakeLists.txt 9.1 KB

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