CMakeLists.txt 13 KB

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