CMakeLists.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. if(NOT BUILD_DOCS)
  2. return()
  3. endif()
  4. # Dependencies scheme (* - optional):
  5. #
  6. # javadoc* -> doxygen_javadoc* -> doxygen_cpp ---------> doxygen -> opencv_docs
  7. # \ \ / /
  8. # \ -> doxygen_python* -> /
  9. # ---------------------------------------------------------->
  10. find_package(Doxygen)
  11. if(DOXYGEN_FOUND)
  12. add_custom_target(doxygen)
  13. # not documented modules list
  14. set(blacklist "${DOXYGEN_BLACKLIST}")
  15. list(APPEND blacklist "ts" "world")
  16. unset(CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT)
  17. unset(CMAKE_DOXYGEN_TUTORIAL_JS_ROOT)
  18. set(OPENCV_DOCS_EXCLUDE_CUDA ON)
  19. if(";${OPENCV_MODULES_EXTRA};" MATCHES ";cudev;")
  20. set(OPENCV_DOCS_EXCLUDE_CUDA OFF)
  21. list(APPEND CMAKE_DOXYGEN_ENABLED_SECTIONS "CUDA_MODULES")
  22. endif()
  23. # gathering headers
  24. set(paths_include)
  25. set(paths_doc)
  26. set(paths_bib)
  27. set(paths_sample)
  28. set(paths_tutorial)
  29. set(paths_hal_interface)
  30. set(refs_main)
  31. set(refs_extra)
  32. set(deps)
  33. foreach(m ${OPENCV_MODULES_MAIN} ${OPENCV_MODULES_EXTRA})
  34. set(the_module "${m}")
  35. if(NOT the_module MATCHES "^opencv_")
  36. set(the_module "opencv_${m}")
  37. endif()
  38. list(FIND blacklist ${m} _pos)
  39. if(NOT EXISTS "${OPENCV_MODULE_${the_module}_LOCATION}/include"
  40. AND NOT EXISTS "${OPENCV_MODULE_${the_module}_LOCATION}/doc"
  41. )
  42. set(_pos -2) # blacklist
  43. endif()
  44. if(${_pos} EQUAL -1)
  45. list(APPEND CMAKE_DOXYGEN_ENABLED_SECTIONS "HAVE_opencv_${m}")
  46. # include folder
  47. set(header_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/include")
  48. if(EXISTS "${header_dir}")
  49. list(APPEND paths_include "${header_dir}")
  50. list(APPEND deps ${header_dir})
  51. if(OPENCV_DOCS_EXCLUDE_CUDA)
  52. if(EXISTS "${OPENCV_MODULE_opencv_${m}_LOCATION}/include/opencv2/${m}/cuda")
  53. list(APPEND CMAKE_DOXYGEN_EXCLUDE_LIST "${OPENCV_MODULE_opencv_${m}_LOCATION}/include/opencv2/${m}/cuda")
  54. endif()
  55. file(GLOB list_cuda_files "${OPENCV_MODULE_opencv_${m}_LOCATION}/include/opencv2/${m}/*cuda*.hpp")
  56. if(list_cuda_files)
  57. list(APPEND CMAKE_DOXYGEN_EXCLUDE_LIST ${list_cuda_files})
  58. endif()
  59. endif()
  60. endif()
  61. # doc folder
  62. set(docs_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/doc")
  63. if(EXISTS "${docs_dir}")
  64. list(APPEND paths_doc "${docs_dir}")
  65. list(APPEND deps ${docs_dir})
  66. endif()
  67. # sample folder
  68. set(sample_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/samples")
  69. if(EXISTS "${sample_dir}")
  70. list(APPEND paths_sample "${sample_dir}")
  71. list(APPEND deps ${sample_dir})
  72. endif()
  73. # tutorial folder
  74. set(tutorial_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/tutorials")
  75. if(EXISTS "${tutorial_dir}")
  76. list(APPEND paths_tutorial "${tutorial_dir}")
  77. list(APPEND deps ${tutorial_dir})
  78. # tutorial reference entry
  79. file(GLOB tutorials RELATIVE "${OPENCV_MODULE_opencv_${m}_LOCATION}" "${tutorial_dir}/*.markdown")
  80. foreach (t ${tutorials})
  81. if (NOT DEFINED CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT)
  82. set(CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT "- @ref tutorial_contrib_root")
  83. set(tutorial_contrib_root "${CMAKE_CURRENT_BINARY_DIR}/contrib_tutorials.markdown")
  84. file(WRITE "${tutorial_contrib_root}"
  85. "Tutorials for contrib modules {#tutorial_contrib_root}\n"
  86. "=============================\n")
  87. endif()
  88. file(STRINGS "${OPENCV_MODULE_opencv_${m}_LOCATION}/${t}" tutorial_id LIMIT_COUNT 1 REGEX ".*{#[^}]+}")
  89. string(REGEX REPLACE ".*{#([^}]+)}" "\\1" tutorial_id "${tutorial_id}")
  90. file(APPEND "${tutorial_contrib_root}" "- ${m}. @subpage ${tutorial_id}\n")
  91. endforeach()
  92. endif()
  93. # HAL replacement file
  94. set(replacement_header "${OPENCV_MODULE_opencv_${m}_LOCATION}/src/hal_replacement.hpp")
  95. if(EXISTS "${replacement_header}")
  96. list(APPEND paths_hal_interface "${replacement_header}")
  97. endif()
  98. # BiBTeX file
  99. set(bib_file "${docs_dir}/${m}.bib")
  100. if(EXISTS "${bib_file}")
  101. set(paths_bib "${paths_bib} ${bib_file}")
  102. list(APPEND deps ${bib_file})
  103. endif()
  104. # Reference entry
  105. set(one_ref "\t- ${m}. @ref ${m}\n")
  106. list(FIND OPENCV_MODULES_EXTRA ${m} _pos)
  107. if(${_pos} EQUAL -1)
  108. set(refs_main "${refs_main}${one_ref}")
  109. else()
  110. set(refs_extra "${refs_extra}${one_ref}")
  111. endif()
  112. endif()
  113. endforeach()
  114. # fix references
  115. # set(ref_header "Module name | Folder\n----------- | ------")
  116. # if(refs_main)
  117. # set(refs_main "### Main modules\n${ref_header}\n${refs_main}")
  118. # endif()
  119. # if(refs_extra)
  120. # set(refs_extra "### Extra modules\n${ref_header}\n${refs_extra}")
  121. # endif()
  122. if(refs_main)
  123. set(refs_main "- Main modules:\n${refs_main}")
  124. endif()
  125. if(refs_extra)
  126. set(refs_extra "- Extra modules:\n${refs_extra}")
  127. endif()
  128. # additional config
  129. set(doxyfile "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
  130. set(rootfile "${CMAKE_CURRENT_BINARY_DIR}/root.markdown")
  131. set(bibfile "${CMAKE_CURRENT_SOURCE_DIR}/opencv.bib")
  132. set(faqfile "${CMAKE_CURRENT_SOURCE_DIR}/faq.markdown")
  133. set(tutorial_path "${CMAKE_CURRENT_SOURCE_DIR}/tutorials")
  134. set(tutorial_py_path "${CMAKE_CURRENT_SOURCE_DIR}/py_tutorials")
  135. set(CMAKE_DOXYGEN_TUTORIAL_JS_ROOT "- @ref tutorial_js_root")
  136. set(tutorial_js_path "${CMAKE_CURRENT_SOURCE_DIR}/js_tutorials")
  137. set(example_path "${CMAKE_SOURCE_DIR}/samples")
  138. set(doxygen_image_path
  139. ${CMAKE_CURRENT_SOURCE_DIR}/images
  140. ${paths_doc}
  141. ${tutorial_path}
  142. ${tutorial_py_path}
  143. ${tutorial_js_path}
  144. ${paths_tutorial}
  145. #${OpenCV_SOURCE_DIR}/samples/data # TODO: need to resolve ambiguous conflicts first
  146. ${OpenCV_SOURCE_DIR}
  147. ${OpenCV_SOURCE_DIR}/modules # <opencv>/modules
  148. ${OPENCV_EXTRA_MODULES_PATH} # <opencv_contrib>/modules
  149. ${OPENCV_DOCS_EXTRA_IMAGE_PATH} # custom variable for user modules
  150. )
  151. # set export variables
  152. string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_INPUT_LIST "${rootfile} ; ${faqfile} ; ${paths_include} ; ${paths_hal_interface} ; ${paths_doc} ; ${tutorial_path} ; ${tutorial_py_path} ; ${tutorial_js_path} ; ${paths_tutorial} ; ${tutorial_contrib_root}")
  153. string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_IMAGE_PATH "${doxygen_image_path}")
  154. string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_EXCLUDE_LIST "${CMAKE_DOXYGEN_EXCLUDE_LIST}")
  155. string(REPLACE ";" " " CMAKE_DOXYGEN_ENABLED_SECTIONS "${CMAKE_DOXYGEN_ENABLED_SECTIONS}")
  156. # TODO: remove paths_doc from EXAMPLE_PATH after face module tutorials/samples moved to separate folders
  157. string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_EXAMPLE_PATH "${example_path} ; ${paths_doc} ; ${paths_sample}")
  158. string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_INCLUDE_ROOTS "${paths_include}")
  159. set(CMAKE_DOXYGEN_LAYOUT "${CMAKE_CURRENT_BINARY_DIR}/DoxygenLayout.xml")
  160. set(CMAKE_DOXYGEN_OUTPUT_PATH "doxygen")
  161. set(CMAKE_DOXYGEN_MAIN_REFERENCE "${refs_main}")
  162. set(CMAKE_DOXYGEN_EXTRA_REFERENCE "${refs_extra}")
  163. set(CMAKE_EXTRA_BIB_FILES "${bibfile} ${paths_bib}")
  164. if (CMAKE_DOXYGEN_GENERATE_QHP)
  165. set(CMAKE_DOXYGEN_GENERATE_QHP "YES")
  166. else()
  167. set(CMAKE_DOXYGEN_GENERATE_QHP "NO")
  168. endif()
  169. list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/opencv.ico")
  170. list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/pattern.png")
  171. list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/acircles_pattern.png")
  172. list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/bodybg.png")
  173. # list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/mymath.sty")
  174. list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tutorial-utils.js")
  175. string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_HTML_FILES "${CMAKE_DOXYGEN_HTML_FILES}")
  176. set(OPENCV_DOCS_DOT_PATH "" CACHE PATH "Doxygen/DOT_PATH value")
  177. set(CMAKECONFIG_DOT_PATH "${OPENCV_DOCS_DOT_PATH}")
  178. set(OPENCV_DOCS_HAVE_DOT "NO" CACHE BOOL "Doxygen: build extra diagrams")
  179. set(CMAKECONFIG_HAVE_DOT "${OPENCV_DOCS_HAVE_DOT}")
  180. # 'png' is good enough for compatibility (but requires +50% storage space)
  181. set(OPENCV_DOCS_DOT_IMAGE_FORMAT "svg" CACHE STRING "Doxygen/DOT_IMAGE_FORMAT value")
  182. set(CMAKECONFIG_DOT_IMAGE_FORMAT "${OPENCV_DOCS_DOT_IMAGE_FORMAT}")
  183. # Doxygen 1.8.16 fix: https://github.com/doxygen/doxygen/pull/6870
  184. # NO is needed here: https://github.com/opencv/opencv/pull/16039
  185. set(OPENCV_DOCS_INTERACTIVE_SVG "NO" CACHE BOOL "Doxygen/INTERACTIVE_SVG value")
  186. set(CMAKECONFIG_INTERACTIVE_SVG "${OPENCV_DOCS_INTERACTIVE_SVG}")
  187. set(OPENCV_DOCS_DOXYFILE_IN "Doxyfile.in" CACHE PATH "Doxygen configuration template file (Doxyfile.in)")
  188. set(OPENCV_DOCS_DOXYGEN_LAYOUT "DoxygenLayout.xml" CACHE PATH "Doxygen layout file (.xml)")
  189. # writing file
  190. configure_file("${OPENCV_DOCS_DOXYGEN_LAYOUT}" DoxygenLayout.xml @ONLY)
  191. configure_file("${OPENCV_DOCS_DOXYFILE_IN}" ${doxyfile} @ONLY)
  192. configure_file(root.markdown.in ${rootfile} @ONLY)
  193. # js tutorial assets
  194. set(opencv_tutorial_html_dir "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html")
  195. set(js_tutorials_assets_dir "${CMAKE_CURRENT_SOURCE_DIR}/js_tutorials/js_assets")
  196. set(js_tutorials_assets_deps "")
  197. # make sure the build directory exists
  198. file(MAKE_DIRECTORY "${opencv_tutorial_html_dir}")
  199. # gather and copy specific files for js tutorials
  200. file(GLOB_RECURSE js_assets "${js_tutorials_assets_dir}/*")
  201. ocv_list_filterout(js_assets "\\\\.eslintrc.json")
  202. list(APPEND js_assets "${OpenCV_SOURCE_DIR}/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/Data/box.mp4")
  203. if(BUILD_opencv_js)
  204. set(ocv_js_dir "${CMAKE_BINARY_DIR}/bin")
  205. set(ocv_js "opencv.js")
  206. list(APPEND js_assets "${ocv_js_dir}/${ocv_js}")
  207. elseif(DEFINED OPENCV_JS_LOCATION)
  208. list(APPEND js_assets "${OPENCV_JS_LOCATION}")
  209. endif()
  210. # copy haar cascade files
  211. set(haar_cascade_files "")
  212. set(data_harrcascades_path "${OpenCV_SOURCE_DIR}/data/haarcascades/")
  213. list(APPEND js_tutorials_assets_deps "${data_harrcascades_path}/haarcascade_frontalface_default.xml" "${data_harrcascades_path}/haarcascade_eye.xml")
  214. list(APPEND js_assets "${data_harrcascades_path}/haarcascade_frontalface_default.xml" "${data_harrcascades_path}/haarcascade_eye.xml")
  215. foreach(f ${js_assets})
  216. get_filename_component(fname "${f}" NAME)
  217. add_custom_command(OUTPUT "${opencv_tutorial_html_dir}/${fname}"
  218. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${f}" "${opencv_tutorial_html_dir}/${fname}"
  219. DEPENDS "${f}"
  220. COMMENT "Copying ${fname}"
  221. )
  222. list(APPEND js_tutorials_assets_deps "${f}" "${opencv_tutorial_html_dir}/${fname}")
  223. endforeach()
  224. add_custom_target(
  225. doxygen_cpp
  226. COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
  227. DEPENDS ${doxyfile} ${rootfile} ${bibfile} ${deps} ${js_tutorials_assets_deps}
  228. COMMENT "Generate Doxygen documentation"
  229. )
  230. if(NOT DEFINED HAVE_PYTHON_BS4 AND PYTHON_DEFAULT_EXECUTABLE)
  231. # Documentation post-processing tool requires BuautifulSoup Python package
  232. execute_process(COMMAND "${PYTHON_DEFAULT_EXECUTABLE}" -c "import bs4; from bs4 import BeautifulSoup; print(bs4.__version__)"
  233. RESULT_VARIABLE _result
  234. OUTPUT_VARIABLE _bs4_version
  235. OUTPUT_STRIP_TRAILING_WHITESPACE)
  236. if(NOT _result EQUAL 0)
  237. set(HAVE_PYTHON_BS4 0 CACHE INTERNAL "")
  238. else()
  239. message(STATUS "Python BeautifulSoup (bs4) version: ${_bs4_version}")
  240. set(HAVE_PYTHON_BS4 1 CACHE INTERNAL "")
  241. endif()
  242. endif()
  243. if(PYTHON_DEFAULT_EXECUTABLE
  244. AND HAVE_PYTHON_BS4
  245. AND OPENCV_PYTHON_SIGNATURES_FILE
  246. AND TARGET gen_opencv_python_source)
  247. add_custom_target(doxygen_python
  248. COMMAND ${PYTHON_DEFAULT_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/tools/add_signatures.py" "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/" "${OPENCV_PYTHON_SIGNATURES_FILE}" "python"
  249. DEPENDS doxygen_cpp gen_opencv_python_source
  250. COMMENT "Inject Python signatures into documentation"
  251. )
  252. endif()
  253. add_dependencies(doxygen doxygen_cpp)
  254. if(TARGET doxygen_python)
  255. add_dependencies(doxygen doxygen_python)
  256. endif()
  257. if(TARGET doxygen_javadoc)
  258. add_dependencies(doxygen_cpp doxygen_javadoc)
  259. endif()
  260. add_dependencies(opencv_docs doxygen)
  261. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html
  262. DESTINATION "${OPENCV_DOC_INSTALL_PATH}"
  263. COMPONENT "docs" OPTIONAL
  264. ${compatible_MESSAGE_NEVER}
  265. )
  266. endif()