CMakeLists.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #=============================================================================
  2. # CMake - Cross Platform Makefile Generator
  3. # Copyright 2000-2013 Kitware, Inc., Insight Software Consortium
  4. #
  5. # Distributed under the OSI-approved BSD License (the "License");
  6. # see accompanying file Copyright.txt for details.
  7. #
  8. # This software is distributed WITHOUT ANY WARRANTY; without even the
  9. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. # See the License for more information.
  11. #=============================================================================
  12. if(NOT CMake_SOURCE_DIR)
  13. set(CMakeHelp_STANDALONE 1)
  14. cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
  15. get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH)
  16. get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH)
  17. include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake)
  18. include(${CMake_SOURCE_DIR}/Source/CMakeVersionCompute.cmake)
  19. include(${CMake_SOURCE_DIR}/Source/CMakeInstallDestinations.cmake)
  20. unset(CMAKE_DATA_DIR)
  21. unset(CMAKE_DATA_DIR CACHE)
  22. endif()
  23. project(CMakeHelp NONE)
  24. option(SPHINX_MAN "Build man pages with Sphinx" OFF)
  25. option(SPHINX_HTML "Build html help with Sphinx" OFF)
  26. option(SPHINX_SINGLEHTML "Build html single page help with Sphinx" OFF)
  27. option(SPHINX_QTHELP "Build Qt help with Sphinx" OFF)
  28. option(SPHINX_TEXT "Build text help with Sphinx (not installed)" OFF)
  29. find_program(SPHINX_EXECUTABLE
  30. NAMES sphinx-build
  31. DOC "Sphinx Documentation Builder (sphinx-doc.org)"
  32. )
  33. mark_as_advanced(SPHINX_TEXT)
  34. if(NOT SPHINX_MAN AND NOT SPHINX_HTML AND NOT SPHINX_SINGLEHTML AND NOT SPHINX_QTHELP AND NOT SPHINX_TEXT)
  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. endif()
  56. if(SPHINX_MAN)
  57. list(APPEND doc_formats man)
  58. endif()
  59. if(SPHINX_SINGLEHTML)
  60. list(APPEND doc_formats singlehtml)
  61. endif()
  62. if(SPHINX_TEXT)
  63. list(APPEND doc_formats text)
  64. endif()
  65. if(SPHINX_QTHELP)
  66. find_program(QCOLLECTIONGENERATOR_EXECUTABLE
  67. NAMES qcollectiongenerator
  68. DOC "qcollectiongenerator tool"
  69. )
  70. if (NOT QCOLLECTIONGENERATOR_EXECUTABLE)
  71. message(FATAL_ERROR "QCOLLECTIONGENERATOR_EXECUTABLE (qcollectiongenerator) not found!")
  72. endif()
  73. list(APPEND doc_formats qthelp)
  74. set(qthelp_extra_commands
  75. # Workaround for assistant prior to
  76. # https://codereview.qt-project.org/#change,82250 in Qt 4.
  77. COMMAND ${CMAKE_COMMAND} "-DCSS_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/_static"
  78. -P "${CMAKE_CURRENT_SOURCE_DIR}/apply_qthelp_css_workaround.cmake"
  79. # Workaround sphinx configurability:
  80. # https://bitbucket.org/birkenfeld/sphinx/issue/1448/make-qthelp-more-configurable
  81. COMMAND ${CMAKE_COMMAND} "-DQTHELP_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
  82. "-DCMake_VERSION=${CMake_VERSION_MAJOR}${CMake_VERSION_MINOR}${CMake_VERSION_PATCH}"
  83. -P "${CMAKE_CURRENT_SOURCE_DIR}/fixup_qthelp_names.cmake"
  84. COMMAND qcollectiongenerator ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
  85. )
  86. endif()
  87. set(doc_format_outputs "")
  88. set(doc_format_last "")
  89. foreach(format ${doc_formats})
  90. set(doc_format_output "doc_format_${format}")
  91. set(doc_format_log "build-${format}.log")
  92. add_custom_command(
  93. OUTPUT ${doc_format_output}
  94. COMMAND ${SPHINX_EXECUTABLE}
  95. -c ${CMAKE_CURRENT_BINARY_DIR}
  96. -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
  97. -b ${format}
  98. ${CMake_SOURCE_DIR}/Help
  99. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  100. > ${doc_format_log} # log stdout, pass stderr
  101. ${${format}_extra_commands}
  102. DEPENDS ${doc_format_last}
  103. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  104. VERBATIM
  105. )
  106. set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
  107. list(APPEND doc_format_outputs ${doc_format_output})
  108. set(doc_format_last ${doc_format_output})
  109. endforeach()
  110. add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
  111. foreach(t
  112. cmake
  113. ccmake
  114. cmake-gui
  115. cpack
  116. ctest
  117. )
  118. if(TARGET ${t})
  119. # Build documentation after main executables.
  120. add_dependencies(documentation ${t})
  121. endif()
  122. endforeach()
  123. if(SPHINX_MAN)
  124. file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
  125. ${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
  126. foreach(m ${man_rst})
  127. if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
  128. set(name "${CMAKE_MATCH_1}")
  129. set(sec "${CMAKE_MATCH_2}")
  130. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
  131. DESTINATION ${CMAKE_MAN_DIR}/man${sec})
  132. endif()
  133. endforeach()
  134. endif()
  135. if(SPHINX_HTML)
  136. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
  137. DESTINATION ${CMAKE_DOC_DIR}
  138. PATTERN .buildinfo EXCLUDE
  139. PATTERN objects.inv EXCLUDE
  140. )
  141. endif()
  142. if(SPHINX_SINGLEHTML)
  143. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
  144. DESTINATION ${CMAKE_DOC_DIR}
  145. PATTERN .buildinfo EXCLUDE
  146. PATTERN objects.inv EXCLUDE
  147. )
  148. endif()
  149. if(SPHINX_QTHELP)
  150. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake-${CMake_VERSION_MAJOR}${CMake_VERSION_MINOR}${CMake_VERSION_PATCH}.qch
  151. DESTINATION ${CMAKE_DOC_DIR}
  152. )
  153. endif()