1
0

CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. # Create proper identifiers. Workaround for
  85. # https://bitbucket.org/birkenfeld/sphinx/issue/1491/qthelp-should-generate-identifiers-for
  86. COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/create_identifiers.py" "${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
  87. COMMAND qcollectiongenerator ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
  88. )
  89. endif()
  90. set(doc_format_outputs "")
  91. set(doc_format_last "")
  92. foreach(format ${doc_formats})
  93. set(doc_format_output "doc_format_${format}")
  94. set(doc_format_log "build-${format}.log")
  95. add_custom_command(
  96. OUTPUT ${doc_format_output}
  97. COMMAND ${SPHINX_EXECUTABLE}
  98. -c ${CMAKE_CURRENT_BINARY_DIR}
  99. -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
  100. -b ${format}
  101. ${CMake_SOURCE_DIR}/Help
  102. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  103. > ${doc_format_log} # log stdout, pass stderr
  104. ${${format}_extra_commands}
  105. DEPENDS ${doc_format_last}
  106. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  107. VERBATIM
  108. )
  109. set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
  110. list(APPEND doc_format_outputs ${doc_format_output})
  111. set(doc_format_last ${doc_format_output})
  112. endforeach()
  113. add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
  114. foreach(t
  115. cmake
  116. ccmake
  117. cmake-gui
  118. cpack
  119. ctest
  120. )
  121. if(TARGET ${t})
  122. # Build documentation after main executables.
  123. add_dependencies(documentation ${t})
  124. endif()
  125. endforeach()
  126. if(SPHINX_MAN)
  127. file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
  128. ${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
  129. foreach(m ${man_rst})
  130. if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
  131. set(name "${CMAKE_MATCH_1}")
  132. set(sec "${CMAKE_MATCH_2}")
  133. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
  134. DESTINATION ${CMAKE_MAN_DIR}/man${sec})
  135. endif()
  136. endforeach()
  137. endif()
  138. if(SPHINX_HTML)
  139. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
  140. DESTINATION ${CMAKE_DOC_DIR}
  141. PATTERN .buildinfo EXCLUDE
  142. PATTERN objects.inv EXCLUDE
  143. )
  144. endif()
  145. if(SPHINX_SINGLEHTML)
  146. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
  147. DESTINATION ${CMAKE_DOC_DIR}
  148. PATTERN .buildinfo EXCLUDE
  149. PATTERN objects.inv EXCLUDE
  150. )
  151. endif()
  152. if(SPHINX_QTHELP)
  153. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake-${CMake_VERSION_MAJOR}${CMake_VERSION_MINOR}${CMake_VERSION_PATCH}.qch
  154. DESTINATION ${CMAKE_DOC_DIR}
  155. )
  156. endif()