enable qt
[profile/ivi/opencv.git] / doc / CMakeLists.txt
1 #
2 #  CMake file for OpenCV docs
3 #
4
5 if(BUILD_DOCS AND HAVE_SPHINX)
6
7   project(opencv_docs)
8
9   set(DOC_LIST
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")
18   endif()
19
20   set(OPTIONAL_DOC_LIST "")
21
22
23   # build lists of modules to be documented
24   set(BASE_MODULES "")
25   set(EXTRA_MODULES "")
26
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})
31     else()
32       list(APPEND EXTRA_MODULES ${mod})
33     endif()
34   endforeach()
35
36   set(FIXED_ORDER_MODULES core imgproc highgui video calib3d features2d objdetect ml flann gpu photo stitching nonfree contrib legacy)
37
38   list(REMOVE_ITEM BASE_MODULES ${FIXED_ORDER_MODULES})
39
40   ocv_list_sort(BASE_MODULES)
41   ocv_list_sort(EXTRA_MODULES)
42
43   set(BASE_MODULES ${FIXED_ORDER_MODULES} ${BASE_MODULES})
44
45   # build lists of documentation files and generate table of contents for reference manual
46
47   set(DOC_FAKE_ROOT "${CMAKE_CURRENT_BINARY_DIR}/fake-root")
48   set(DOC_FAKE_ROOT_FILES "")
49
50   function(ocv_doc_add_file_to_fake_root source destination)
51     add_custom_command(
52       OUTPUT "${DOC_FAKE_ROOT}/${destination}"
53       COMMAND "${CMAKE_COMMAND}" -E copy "${source}" "${DOC_FAKE_ROOT}/${destination}"
54       DEPENDS "${source}"
55       COMMENT "Copying ${destination} to fake root..."
56       VERBATIM
57     )
58     list(APPEND DOC_FAKE_ROOT_FILES "${DOC_FAKE_ROOT}/${destination}")
59     set(DOC_FAKE_ROOT_FILES "${DOC_FAKE_ROOT_FILES}" PARENT_SCOPE)
60   endfunction()
61
62   function(ocv_doc_add_to_fake_root source)
63     if(ARGC GREATER 1)
64       set(destination "${ARGV1}")
65     else()
66       file(RELATIVE_PATH destination "${OpenCV_SOURCE_DIR}" "${source}")
67     endif()
68
69     if(IS_DIRECTORY "${source}")
70       file(GLOB_RECURSE files RELATIVE "${source}" "${source}/*")
71
72       foreach(file ${files})
73         ocv_doc_add_file_to_fake_root("${source}/${file}" "${destination}/${file}")
74       endforeach()
75     else()
76       ocv_doc_add_file_to_fake_root("${source}" "${destination}")
77     endif()
78
79     set(DOC_FAKE_ROOT_FILES "${DOC_FAKE_ROOT_FILES}" PARENT_SCOPE)
80   endfunction()
81
82   set(OPENCV_REFMAN_TOC "")
83
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")
88     endif()
89   endforeach()
90
91   configure_file("${OpenCV_SOURCE_DIR}/modules/refman.rst.in" "${DOC_FAKE_ROOT}/modules/refman.rst" @ONLY)
92
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")
97
98   if(PDFLATEX_COMPILER)
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"
123       )
124
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")
127
128     if(ENABLE_SOLUTION_FOLDERS)
129       set_target_properties(docs PROPERTIES FOLDER "documentation")
130     endif()
131   endif()
132
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"
139     )
140
141   if(ENABLE_SOLUTION_FOLDERS)
142     set_target_properties(html_docs PROPERTIES FOLDER "documentation")
143   endif()
144
145   foreach(f ${DOC_LIST})
146     install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" COMPONENT docs)
147   endforeach()
148
149   foreach(f ${OPTIONAL_DOC_LIST})
150     install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" OPTIONAL COMPONENT docs)
151   endforeach()
152
153 endif()