1 #-----------------------
2 # CMake file for OpenCV docs
3 #-----------------------
5 if(BUILD_DOCS AND DOXYGEN_FOUND)
6 set(HAVE_DOC_GENERATOR TRUE)
8 set(HAVE_DOC_GENERATOR FALSE)
11 if(HAVE_DOC_GENERATOR)
13 # build lists of modules to be documented
17 foreach(mod ${OPENCV_MODULES_BUILD} ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MODULES_DISABLED_AUTO} ${OPENCV_MODULES_DISABLED_FORCE})
18 string(REGEX REPLACE "^opencv_" "" mod "${mod}")
19 if("${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${OpenCV_SOURCE_DIR}/modules/${mod}")
20 list(APPEND BASE_MODULES ${mod})
22 list(APPEND EXTRA_MODULES ${mod})
25 ocv_list_sort(BASE_MODULES)
26 ocv_list_sort(EXTRA_MODULES)
27 set(FIXED_ORDER_MODULES core imgproc imgcodecs videoio highgui video calib3d features2d objdetect dnn ml flann photo stitching)
28 list(REMOVE_ITEM BASE_MODULES ${FIXED_ORDER_MODULES})
29 set(BASE_MODULES ${FIXED_ORDER_MODULES} ${BASE_MODULES})
30 endif(HAVE_DOC_GENERATOR)
32 # ========= Doxygen docs =========
34 if(BUILD_DOCS AND DOXYGEN_FOUND)
35 # not documented modules list
36 list(APPEND blacklist "ts" "java" "python2" "python3" "js" "world")
37 unset(CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT)
38 unset(CMAKE_DOXYGEN_TUTORIAL_JS_ROOT)
40 set(OPENCV_MATHJAX_RELPATH "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0" CACHE STRING "URI to a MathJax installation")
48 set(paths_hal_interface)
52 foreach(m ${BASE_MODULES} ${EXTRA_MODULES})
53 list(FIND blacklist ${m} _pos)
56 set(header_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/include")
57 if(EXISTS "${header_dir}")
58 list(APPEND paths_include "${header_dir}")
59 list(APPEND deps ${header_dir})
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})
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})
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})
79 # tutorial reference entry
80 file(GLOB tutorials RELATIVE "${OPENCV_MODULE_opencv_${m}_LOCATION}" "${tutorial_dir}/*.markdown")
81 foreach (t ${tutorials})
82 if (NOT DEFINED CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT)
83 set(CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT "- @ref tutorial_contrib_root")
84 set(tutorial_contrib_root "${CMAKE_CURRENT_BINARY_DIR}/contrib_tutorials.markdown")
85 file(WRITE "${tutorial_contrib_root}"
86 "Tutorials for contrib modules {#tutorial_contrib_root}\n"
87 "=============================\n")
89 file(STRINGS "${OPENCV_MODULE_opencv_${m}_LOCATION}/${t}" tutorial_id LIMIT_COUNT 1 REGEX ".*{#[^}]+}")
90 string(REGEX REPLACE ".*{#([^}]+)}" "\\1" tutorial_id "${tutorial_id}")
91 file(APPEND "${tutorial_contrib_root}" "- ${m}. @subpage ${tutorial_id}\n")
94 # HAL replacement file
95 set(replacement_header "${OPENCV_MODULE_opencv_${m}_LOCATION}/src/hal_replacement.hpp")
96 if(EXISTS "${replacement_header}")
97 list(APPEND paths_hal_interface "${replacement_header}")
101 set(bib_file "${docs_dir}/${m}.bib")
102 if(EXISTS "${bib_file}")
103 set(paths_bib "${paths_bib} ${bib_file}")
104 list(APPEND deps ${bib_file})
107 # set(one_ref "@ref ${m} | ${m}\n")
108 set(one_ref "\t- ${m}. @ref ${m}\n")
109 list(FIND EXTRA_MODULES ${m} _pos)
111 set(refs_main "${refs_main}${one_ref}")
113 set(refs_extra "${refs_extra}${one_ref}")
119 # set(ref_header "Module name | Folder\n----------- | ------")
121 # set(refs_main "### Main modules\n${ref_header}\n${refs_main}")
124 # set(refs_extra "### Extra modules\n${ref_header}\n${refs_extra}")
127 set(refs_main "- Main modules:\n${refs_main}")
130 set(refs_extra "- Extra modules:\n${refs_extra}")
134 set(doxyfile "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
135 set(rootfile "${CMAKE_CURRENT_BINARY_DIR}/root.markdown")
136 set(bibfile "${CMAKE_CURRENT_SOURCE_DIR}/opencv.bib")
137 set(faqfile "${CMAKE_CURRENT_SOURCE_DIR}/faq.markdown")
138 set(tutorial_path "${CMAKE_CURRENT_SOURCE_DIR}/tutorials")
139 set(tutorial_py_path "${CMAKE_CURRENT_SOURCE_DIR}/py_tutorials")
140 set(CMAKE_DOXYGEN_TUTORIAL_JS_ROOT "- @ref tutorial_js_root")
141 set(tutorial_js_path "${CMAKE_CURRENT_SOURCE_DIR}/js_tutorials")
142 set(example_path "${CMAKE_SOURCE_DIR}/samples")
144 # set export variables
145 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}")
146 string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_IMAGE_PATH "${paths_doc} ; ${tutorial_path} ; ${tutorial_py_path} ; ${tutorial_js_path} ; ${paths_tutorial}")
147 # TODO: remove paths_doc from EXAMPLE_PATH after face module tutorials/samples moved to separate folders
148 string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_EXAMPLE_PATH "${example_path} ; ${paths_doc} ; ${paths_sample}")
149 set(CMAKE_DOXYGEN_LAYOUT "${CMAKE_CURRENT_SOURCE_DIR}/DoxygenLayout.xml")
150 set(CMAKE_DOXYGEN_OUTPUT_PATH "doxygen")
151 set(CMAKE_DOXYGEN_MAIN_REFERENCE "${refs_main}")
152 set(CMAKE_DOXYGEN_EXTRA_REFERENCE "${refs_extra}")
153 set(CMAKE_EXTRA_BIB_FILES "${bibfile} ${paths_bib}")
154 if (CMAKE_DOXYGEN_GENERATE_QHP)
155 set(CMAKE_DOXYGEN_GENERATE_QHP "YES")
157 set(CMAKE_DOXYGEN_GENERATE_QHP "NO")
160 list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/opencv.ico")
161 list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/pattern.png")
162 list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/acircles_pattern.png")
163 list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/bodybg.png")
164 list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/mymath.sty")
165 string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_HTML_FILES "${CMAKE_DOXYGEN_HTML_FILES}")
168 configure_file(Doxyfile.in ${doxyfile} @ONLY)
169 configure_file(root.markdown.in ${rootfile} @ONLY)
172 set(opencv_tutorial_html_dir "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html")
173 set(js_tutorials_assets_dir "${CMAKE_CURRENT_SOURCE_DIR}/js_tutorials/js_assets")
174 set(js_tutorials_assets_deps "")
176 # make sure the build directory exists
177 file(MAKE_DIRECTORY "${opencv_tutorial_html_dir}")
179 # gather and copy specific files for js tutorials
180 file(GLOB_RECURSE js_assets "${js_tutorials_assets_dir}/*")
181 ocv_list_filterout(js_assets "\\\\.eslintrc.json")
182 list(APPEND js_assets "${OpenCV_SOURCE_DIR}/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/Data/box.mp4")
185 set(ocv_js_dir "${CMAKE_BINARY_DIR}/bin")
186 set(ocv_js "opencv.js")
187 list(APPEND js_assets "${ocv_js_dir}/${ocv_js}")
188 elseif(DEFINED OPENCV_JS_LOCATION)
189 list(APPEND js_assets "${OPENCV_JS_LOCATION}")
192 # copy haar cascade files
193 set(haar_cascade_files "")
194 set(data_harrcascades_path "${OpenCV_SOURCE_DIR}/data/haarcascades/")
195 list(APPEND js_tutorials_assets_deps "${data_harrcascades_path}/haarcascade_frontalface_default.xml" "${data_harrcascades_path}/haarcascade_eye.xml")
196 list(APPEND js_assets "${data_harrcascades_path}/haarcascade_frontalface_default.xml" "${data_harrcascades_path}/haarcascade_eye.xml")
198 foreach(f ${js_assets})
199 get_filename_component(fname "${f}" NAME)
200 add_custom_command(OUTPUT "${opencv_tutorial_html_dir}/${fname}"
201 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${f}" "${opencv_tutorial_html_dir}/${fname}"
203 COMMENT "Copying ${fname}"
205 list(APPEND js_tutorials_assets_deps "${f}" "${opencv_tutorial_html_dir}/${fname}")
208 add_custom_target(doxygen
209 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
210 DEPENDS ${doxyfile} ${rootfile} ${bibfile} ${deps} ${js_tutorials_assets_deps}
212 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html
213 DESTINATION "${OPENCV_DOC_INSTALL_PATH}"
214 COMPONENT "docs" OPTIONAL
217 # Alias to build/install docs only
218 add_custom_target(install_docs
220 COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=docs -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"