CMakeLists.txt 8.7 KB

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