CMakeLists.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 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/CMakeVersionCompute.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
  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. "-DCMake_VERSION=${CMake_VERSION_MAJOR}${CMake_VERSION_MINOR}${CMake_VERSION_PATCH}"
  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. set(doc_format_outputs "")
  110. set(doc_format_last "")
  111. foreach(format ${doc_formats})
  112. set(doc_format_output "doc_format_${format}")
  113. set(doc_format_log "build-${format}.log")
  114. add_custom_command(
  115. OUTPUT ${doc_format_output}
  116. COMMAND ${SPHINX_EXECUTABLE}
  117. -c ${CMAKE_CURRENT_BINARY_DIR}
  118. -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
  119. -b ${format}
  120. ${sphinx_flags}
  121. ${CMake_SOURCE_DIR}/Help
  122. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  123. > ${doc_format_log} # log stdout, pass stderr
  124. ${${format}_extra_commands}
  125. DEPENDS ${doc_format_last}
  126. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  127. VERBATIM
  128. )
  129. set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
  130. list(APPEND doc_format_outputs ${doc_format_output})
  131. set(doc_format_last ${doc_format_output})
  132. endforeach()
  133. add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
  134. if(CMake_SPHINX_DEPEND_ON_EXECUTABLES)
  135. foreach(t
  136. cmake
  137. ccmake
  138. cmake-gui
  139. cpack
  140. ctest
  141. )
  142. if(TARGET ${t})
  143. # Build documentation after main executables.
  144. add_dependencies(documentation ${t})
  145. endif()
  146. endforeach()
  147. endif()
  148. if(SPHINX_INFO)
  149. CMake_OPTIONAL_COMPONENT(sphinx-info)
  150. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
  151. DESTINATION ${CMAKE_INFO_DIR}
  152. ${COMPONENT}
  153. )
  154. endif()
  155. if(SPHINX_MAN)
  156. file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
  157. ${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
  158. foreach(m ${man_rst})
  159. if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
  160. set(name "${CMAKE_MATCH_1}")
  161. set(sec "${CMAKE_MATCH_2}")
  162. set(skip FALSE)
  163. if(NOT CMakeHelp_STANDALONE)
  164. if(name STREQUAL "ccmake" AND NOT BUILD_CursesDialog)
  165. set(skip TRUE)
  166. elseif(name STREQUAL "cmake-gui" AND NOT BUILD_QtDialog)
  167. set(skip TRUE)
  168. endif()
  169. endif()
  170. if(NOT skip)
  171. CMake_OPTIONAL_COMPONENT(sphinx-man)
  172. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
  173. DESTINATION ${CMAKE_MAN_DIR}/man${sec}
  174. ${COMPONENT})
  175. endif()
  176. unset(skip)
  177. endif()
  178. endforeach()
  179. endif()
  180. if(SPHINX_HTML)
  181. CMake_OPTIONAL_COMPONENT(sphinx-html)
  182. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
  183. DESTINATION ${CMAKE_DOC_DIR}
  184. ${COMPONENT}
  185. PATTERN .buildinfo EXCLUDE
  186. )
  187. endif()
  188. if(SPHINX_SINGLEHTML)
  189. CMake_OPTIONAL_COMPONENT(sphinx-singlehtml)
  190. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
  191. DESTINATION ${CMAKE_DOC_DIR}
  192. ${COMPONENT}
  193. PATTERN .buildinfo EXCLUDE
  194. )
  195. endif()
  196. if(SPHINX_QTHELP)
  197. CMake_OPTIONAL_COMPONENT(sphinx-qthelp)
  198. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake-${CMake_VERSION_MAJOR}${CMake_VERSION_MINOR}${CMake_VERSION_PATCH}.qch
  199. DESTINATION ${CMAKE_DOC_DIR} ${COMPONENT}
  200. )
  201. endif()