CMakeLists.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_QTHELP "Build Qt help with Sphinx" OFF)
  27. option(SPHINX_TEXT "Build text help with Sphinx (not installed)" OFF)
  28. find_program(SPHINX_EXECUTABLE
  29. NAMES sphinx-build
  30. DOC "Sphinx Documentation Builder (sphinx-doc.org)"
  31. )
  32. mark_as_advanced(SPHINX_TEXT)
  33. if(NOT SPHINX_MAN AND NOT SPHINX_HTML AND NOT SPHINX_QTHELP AND NOT SPHINX_TEXT)
  34. return()
  35. elseif(NOT SPHINX_EXECUTABLE)
  36. message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
  37. endif()
  38. set(copyright_line_regex "^Copyright (2000-20[0-9][0-9] Kitware.*)")
  39. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  40. LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
  41. if(copyright_line MATCHES "${copyright_line_regex}")
  42. set(conf_copyright "${CMAKE_MATCH_1}")
  43. else()
  44. set(conf_copyright "Kitware, Inc.")
  45. endif()
  46. set(conf_docs "${CMake_SOURCE_DIR}/Help")
  47. set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}")
  48. set(conf_version "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  49. set(conf_release "${CMake_VERSION}")
  50. configure_file(conf.py.in conf.py @ONLY)
  51. set(doc_formats "")
  52. if(SPHINX_HTML)
  53. list(APPEND doc_formats html)
  54. endif()
  55. if(SPHINX_MAN)
  56. list(APPEND doc_formats man)
  57. endif()
  58. if(SPHINX_TEXT)
  59. list(APPEND doc_formats text)
  60. endif()
  61. if(SPHINX_QTHELP)
  62. find_program(QCOLLECTIONGENERATOR_EXECUTABLE
  63. NAMES qcollectiongenerator
  64. DOC "qcollectiongenerator tool"
  65. )
  66. if (NOT QCOLLECTIONGENERATOR_EXECUTABLE)
  67. message(FATAL_ERROR "QCOLLECTIONGENERATOR_EXECUTABLE (qcollectiongenerator) not found!")
  68. endif()
  69. list(APPEND doc_formats qthelp)
  70. set(qthelp_extra_commands
  71. COMMAND qcollectiongenerator ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
  72. )
  73. endif()
  74. set(doc_format_outputs "")
  75. set(doc_format_last "")
  76. foreach(format ${doc_formats})
  77. set(doc_format_output "doc_format_${format}")
  78. set(doc_format_log "build-${format}.log")
  79. add_custom_command(
  80. OUTPUT ${doc_format_output}
  81. COMMAND ${SPHINX_EXECUTABLE}
  82. -c ${CMAKE_CURRENT_BINARY_DIR}
  83. -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
  84. -b ${format}
  85. ${CMake_SOURCE_DIR}/Help
  86. ${CMAKE_CURRENT_BINARY_DIR}/${format}
  87. > ${doc_format_log} # log stdout, pass stderr
  88. ${${format}_extra_commands}
  89. DEPENDS ${doc_format_last}
  90. COMMENT "sphinx-build ${format}: see Utilities/Sphinx/${doc_format_log}"
  91. VERBATIM
  92. )
  93. set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
  94. list(APPEND doc_format_outputs ${doc_format_output})
  95. set(doc_format_last ${doc_format_output})
  96. endforeach()
  97. add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})
  98. foreach(t
  99. cmake
  100. ccmake
  101. cmake-gui
  102. cpack
  103. ctest
  104. )
  105. if(TARGET ${t})
  106. # Build documentation after main executables.
  107. add_dependencies(documentation ${t})
  108. endif()
  109. endforeach()
  110. if(SPHINX_MAN)
  111. file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
  112. ${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
  113. foreach(m ${man_rst})
  114. if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
  115. set(name "${CMAKE_MATCH_1}")
  116. set(sec "${CMAKE_MATCH_2}")
  117. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
  118. DESTINATION ${CMAKE_MAN_DIR}/man${sec})
  119. endif()
  120. endforeach()
  121. endif()
  122. if(SPHINX_HTML)
  123. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
  124. DESTINATION ${CMAKE_DOC_DIR}
  125. PATTERN .buildinfo EXCLUDE
  126. PATTERN objects.inv EXCLUDE
  127. )
  128. endif()
  129. if(SPHINX_QTHELP)
  130. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch
  131. DESTINATION ${CMAKE_DOC_DIR}
  132. )
  133. endif()