2 # CMake file for OpenCV docs
5 if(BUILD_DOCS AND HAVE_SPHINX)
10 "${OpenCV_SOURCE_DIR}/doc/opencv-logo.png"
11 "${OpenCV_SOURCE_DIR}/doc/opencv-logo2.png"
12 "${OpenCV_SOURCE_DIR}/doc/opencv-logo-white.png"
13 "${OpenCV_SOURCE_DIR}/doc/opencv.ico"
14 "${OpenCV_SOURCE_DIR}/doc/pattern.png"
15 "${OpenCV_SOURCE_DIR}/doc/acircles_pattern.png")
16 if(NOT INSTALL_CREATE_DISTRIB)
17 list(APPEND DOC_LIST "${OpenCV_SOURCE_DIR}/doc/haartraining.htm")
20 set(OPTIONAL_DOC_LIST "")
23 # build lists of modules to be documented
27 foreach(mod ${OPENCV_MODULES_BUILD} ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MODULES_DISABLED_AUTO} ${OPENCV_MODULES_DISABLED_FORCE})
28 string(REGEX REPLACE "^opencv_" "" mod "${mod}")
29 if("${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${OpenCV_SOURCE_DIR}/modules/${mod}")
30 list(APPEND BASE_MODULES ${mod})
32 list(APPEND EXTRA_MODULES ${mod})
36 set(FIXED_ORDER_MODULES core imgproc highgui video calib3d features2d objdetect ml flann gpu photo stitching nonfree contrib legacy)
38 list(REMOVE_ITEM BASE_MODULES ${FIXED_ORDER_MODULES})
40 ocv_list_sort(BASE_MODULES)
41 ocv_list_sort(EXTRA_MODULES)
43 set(BASE_MODULES ${FIXED_ORDER_MODULES} ${BASE_MODULES})
45 # build lists of documentation files and generate table of contents for reference manual
47 set(DOC_FAKE_ROOT "${CMAKE_CURRENT_BINARY_DIR}/fake-root")
48 set(DOC_FAKE_ROOT_FILES "")
50 function(ocv_doc_add_file_to_fake_root source destination)
52 OUTPUT "${DOC_FAKE_ROOT}/${destination}"
53 COMMAND "${CMAKE_COMMAND}" -E copy "${source}" "${DOC_FAKE_ROOT}/${destination}"
55 COMMENT "Copying ${destination} to fake root..."
58 list(APPEND DOC_FAKE_ROOT_FILES "${DOC_FAKE_ROOT}/${destination}")
59 set(DOC_FAKE_ROOT_FILES "${DOC_FAKE_ROOT_FILES}" PARENT_SCOPE)
62 function(ocv_doc_add_to_fake_root source)
64 set(destination "${ARGV1}")
66 file(RELATIVE_PATH destination "${OpenCV_SOURCE_DIR}" "${source}")
69 if(IS_DIRECTORY "${source}")
70 file(GLOB_RECURSE files RELATIVE "${source}" "${source}/*")
72 foreach(file ${files})
73 ocv_doc_add_file_to_fake_root("${source}/${file}" "${destination}/${file}")
76 ocv_doc_add_file_to_fake_root("${source}" "${destination}")
79 set(DOC_FAKE_ROOT_FILES "${DOC_FAKE_ROOT_FILES}" PARENT_SCOPE)
82 set(OPENCV_REFMAN_TOC "")
84 foreach(mod ${BASE_MODULES} ${EXTRA_MODULES})
85 if(EXISTS "${OPENCV_MODULE_opencv_${mod}_LOCATION}/doc/${mod}.rst")
86 ocv_doc_add_to_fake_root("${OPENCV_MODULE_opencv_${mod}_LOCATION}/doc" modules/${mod}/doc)
87 set(OPENCV_REFMAN_TOC "${OPENCV_REFMAN_TOC} ${mod}/doc/${mod}.rst\n")
91 configure_file("${OpenCV_SOURCE_DIR}/modules/refman.rst.in" "${DOC_FAKE_ROOT}/modules/refman.rst" @ONLY)
93 ocv_doc_add_to_fake_root("${OpenCV_SOURCE_DIR}/index.rst")
94 ocv_doc_add_to_fake_root("${OpenCV_SOURCE_DIR}/doc")
95 ocv_doc_add_to_fake_root("${OpenCV_SOURCE_DIR}/platforms/android")
96 ocv_doc_add_to_fake_root("${OpenCV_SOURCE_DIR}/samples")
99 add_custom_target(docs
100 COMMAND ${SPHINX_BUILD} -b latex -c "${CMAKE_CURRENT_SOURCE_DIR}" "${DOC_FAKE_ROOT}" .
101 COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/pics ${CMAKE_CURRENT_BINARY_DIR}/doc/opencv1/pics
102 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/mymath.sty ${CMAKE_CURRENT_BINARY_DIR}
103 COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/patch_refman_latex.py" opencv2refman.tex
104 COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/patch_refman_latex.py" opencv2manager.tex
105 COMMAND ${CMAKE_COMMAND} -E echo "Generating opencv2refman.pdf"
106 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode opencv2refman.tex
107 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode opencv2refman.tex
108 COMMAND ${CMAKE_COMMAND} -E echo "Generating opencv2manager.pdf"
109 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode opencv2manager.tex
110 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode opencv2manager.tex
111 COMMAND ${CMAKE_COMMAND} -E echo "Generating opencv_user.pdf"
112 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode opencv_user.tex
113 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode opencv_user.tex
114 COMMAND ${CMAKE_COMMAND} -E echo "Generating opencv_tutorials.pdf"
115 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode opencv_tutorials.tex
116 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode opencv_tutorials.tex
117 COMMAND ${CMAKE_COMMAND} -E echo "Generating opencv_cheatsheet.pdf"
118 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode "${CMAKE_CURRENT_SOURCE_DIR}/opencv_cheatsheet.tex"
119 COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode "${CMAKE_CURRENT_SOURCE_DIR}/opencv_cheatsheet.tex"
120 DEPENDS ${DOC_FAKE_ROOT_FILES}
121 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
122 COMMENT "Generating the PDF Manuals"
125 LIST(APPEND OPTIONAL_DOC_LIST "${CMAKE_BINARY_DIR}/doc/opencv2refman.pdf" "${CMAKE_BINARY_DIR}/doc/opencv2manager.pdf"
126 "${CMAKE_BINARY_DIR}/doc/opencv_user.pdf" "${CMAKE_BINARY_DIR}/doc/opencv_tutorials.pdf" "${CMAKE_BINARY_DIR}/doc/opencv_cheatsheet.pdf")
128 if(ENABLE_SOLUTION_FOLDERS)
129 set_target_properties(docs PROPERTIES FOLDER "documentation")
133 add_custom_target(html_docs
134 COMMAND "${SPHINX_BUILD}" -b html -c "${CMAKE_CURRENT_SOURCE_DIR}" "${DOC_FAKE_ROOT}" ./_html
135 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/mymath.sty ${CMAKE_CURRENT_BINARY_DIR}
136 DEPENDS ${DOC_FAKE_ROOT_FILES}
137 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
138 COMMENT "Generating Online Documentation"
141 if(ENABLE_SOLUTION_FOLDERS)
142 set_target_properties(html_docs PROPERTIES FOLDER "documentation")
145 foreach(f ${DOC_LIST})
146 install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" COMPONENT docs)
149 foreach(f ${OPTIONAL_DOC_LIST})
150 install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" OPTIONAL COMPONENT docs)