CMakeLists.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.18 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_TEXT "Build text help with Sphinx (not installed)" OFF)
  24. find_program(SPHINX_EXECUTABLE
  25. NAMES sphinx-build
  26. DOC "Sphinx Documentation Builder (sphinx-doc.org)"
  27. )
  28. set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
  29. separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}")
  30. mark_as_advanced(SPHINX_TEXT)
  31. mark_as_advanced(SPHINX_FLAGS)
  32. if(NOT SPHINX_INFO AND NOT SPHINX_MAN AND NOT SPHINX_HTML AND NOT SPHINX_SINGLEHTML AND NOT SPHINX_QTHELP AND NOT SPHINX_TEXT)
  33. return()
  34. elseif(NOT SPHINX_EXECUTABLE)
  35. message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
  36. endif()
  37. set(copyright_line_regex "^Copyright (2000-20[0-9][0-9] Kitware.*)")
  38. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  39. LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
  40. if(copyright_line MATCHES "${copyright_line_regex}")
  41. set(conf_copyright "${CMAKE_MATCH_1}")
  42. else()
  43. set(conf_copyright "Kitware, Inc.")
  44. endif()
  45. set(conf_docs "${CMake_SOURCE_DIR}/Help")
  46. set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}")
  47. set(conf_version "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  48. set(conf_release "${CMake_VERSION}")
  49. configure_file(conf.py.in conf.py @ONLY)
  50. set(doc_formats "")
  51. if(SPHINX_HTML)
  52. list(APPEND doc_formats html)
  53. endif()
  54. if(SPHINX_MAN)
  55. list(APPEND doc_formats man)
  56. endif()
  57. if(SPHINX_SINGLEHTML)
  58. list(APPEND doc_formats singlehtml)
  59. endif()
  60. if(SPHINX_TEXT)
  61. list(APPEND doc_formats text)
  62. endif()
  63. if(SPHINX_INFO)
  64. find_program(MAKEINFO_EXECUTABLE
  65. NAMES makeinfo
  66. DOC "makeinfo tool"
  67. )
  68. if (NOT MAKEINFO_EXECUTABLE)
  69. message(FATAL_ERROR "MAKEINFO_EXECUTABLE (makeinfo) not found!")
  70. endif()
  71. list(APPEND doc_formats texinfo)
  72. # Sphinx texinfo builder supports .info, .txt, .html and .pdf output.
  73. # SPHINX_INFO controls the .info output.
  74. set(texinfo_extra_commands
  75. COMMAND ${MAKEINFO_EXECUTABLE} --no-split -o
  76. ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
  77. ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.texi
  78. )
  79. endif()
  80. if(SPHINX_QTHELP)
  81. find_package(PythonInterp REQUIRED)
  82. find_program(QCOLLECTIONGENERATOR_EXECUTABLE
  83. NAMES qcollectiongenerator-qt5 qcollectiongenerator
  84. DOC "qcollectiongenerator tool"
  85. )
  86. if (NOT QCOLLECTIONGENERATOR_EXECUTABLE)
  87. message(FATAL_ERROR "QCOLLECTIONGENERATOR_EXECUTABLE (qcollectiongenerator) not found!")
  88. endif()
  89. list(APPEND doc_formats qthelp)
  90. set(qthelp_extra_commands
  91. # Workaround for assistant prior to
  92. # https://codereview.qt-project.org/#change,82250 in Qt 4.
  93. COMMAND ${CMAKE_COMMAND} "-DCSS_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/_static"
  94. -P "${CMAKE_CURRENT_SOURCE_DIR}/apply_qthelp_css_workaround.cmake"
  95. # Workaround sphinx configurability:
  96. # https://bitbucket.org/birkenfeld/sphinx/issue/1448/make-qthelp-more-configurable
  97. COMMAND ${CMAKE_COMMAND} "-DQTHELP_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
  98. -P "${CMAKE_CURRENT_SOURCE_DIR}/fixup_qthelp_names.cmake"
  99. # Create proper identifiers. Workaround for
  100. # https://bitbucket.org/birkenfeld/sphinx/issue/1491/qthelp-should-generate-identifiers-for
  101. COMMAND "${PYTHON_EXECUTABLE}"
  102. "${CMAKE_CURRENT_SOURCE_DIR}/create_identifiers.py"
  103. "${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
  104. COMMAND ${QCOLLECTIONGENERATOR_EXECUTABLE}
  105. ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
  106. )
  107. endif()
  108. set(doc_format_outputs "")
  109. set(doc_format_last "")
  110. foreach(format ${doc_formats})
  111. set(doc_format_output "doc_format_${format}")
  112. set(doc_format_log "build-${format}.log")
  113. add_custom_command(
  114. OUTPUT ${doc_format_output}
  115. COMMAND ${SPHINX_EXECUTABLE}
  116. -c ${CMAKE_CURRENT_BINARY_DIR}
  117. -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
  118. -b ${format}
  119. ${sphinx_flags}
  120. ${CMake_SOURCE_DIR}/Help
  121. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  122. > ${doc_format_log} # log stdout, pass stderr
  123. ${${format}_extra_commands}
  124. DEPENDS ${doc_format_last}
  125. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  126. VERBATIM
  127. )
  128. set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
  129. list(APPEND doc_format_outputs ${doc_format_output})
  130. set(doc_format_last ${doc_format_output})
  131. endforeach()
  132. add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
  133. if(CMake_SPHINX_DEPEND_ON_EXECUTABLES)
  134. foreach(t
  135. cmake
  136. ccmake
  137. cmake-gui
  138. cpack
  139. ctest
  140. )
  141. if(TARGET ${t})
  142. # Build documentation after main executables.
  143. add_dependencies(documentation ${t})
  144. endif()
  145. endforeach()
  146. endif()
  147. if(SPHINX_INFO)
  148. CMake_OPTIONAL_COMPONENT(sphinx-info)
  149. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
  150. DESTINATION ${CMAKE_INFO_DIR}
  151. ${COMPONENT}
  152. )
  153. endif()
  154. if(SPHINX_MAN)
  155. file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
  156. ${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
  157. foreach(m ${man_rst})
  158. if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
  159. set(name "${CMAKE_MATCH_1}")
  160. set(sec "${CMAKE_MATCH_2}")
  161. set(skip FALSE)
  162. if(NOT CMakeHelp_STANDALONE)
  163. if(name STREQUAL "ccmake" AND NOT BUILD_CursesDialog)
  164. set(skip TRUE)
  165. elseif(name STREQUAL "cmake-gui" AND NOT BUILD_QtDialog)
  166. set(skip TRUE)
  167. endif()
  168. endif()
  169. if(NOT skip)
  170. CMake_OPTIONAL_COMPONENT(sphinx-man)
  171. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
  172. DESTINATION ${CMAKE_MAN_DIR}/man${sec}
  173. ${COMPONENT})
  174. endif()
  175. unset(skip)
  176. endif()
  177. endforeach()
  178. endif()
  179. if(SPHINX_HTML)
  180. CMake_OPTIONAL_COMPONENT(sphinx-html)
  181. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
  182. DESTINATION ${CMAKE_DOC_DIR}
  183. ${COMPONENT}
  184. PATTERN .buildinfo EXCLUDE
  185. )
  186. endif()
  187. if(SPHINX_SINGLEHTML)
  188. CMake_OPTIONAL_COMPONENT(sphinx-singlehtml)
  189. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
  190. DESTINATION ${CMAKE_DOC_DIR}
  191. ${COMPONENT}
  192. PATTERN .buildinfo EXCLUDE
  193. )
  194. endif()
  195. if(SPHINX_QTHELP)
  196. CMake_OPTIONAL_COMPONENT(sphinx-qthelp)
  197. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch
  198. DESTINATION ${CMAKE_DOC_DIR} ${COMPONENT}
  199. )
  200. endif()