Merge pull request #7625 from souch55:Fixapi
[platform/upstream/opencv.git] / doc / CMakeLists.txt
1 #-----------------------
2 #  CMake file for OpenCV docs
3 #-----------------------
4
5 if(BUILD_DOCS AND DOXYGEN_FOUND)
6   set(HAVE_DOC_GENERATOR TRUE)
7 else()
8   set(HAVE_DOC_GENERATOR FALSE)
9 endif()
10
11 if(HAVE_DOC_GENERATOR)
12   project(opencv_docs)
13   # build lists of modules to be documented
14   set(BASE_MODULES "")
15   set(EXTRA_MODULES "")
16
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})
21     else()
22       list(APPEND EXTRA_MODULES ${mod})
23     endif()
24   endforeach()
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 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)
31
32 # ========= Doxygen docs =========
33
34 if(BUILD_DOCS AND DOXYGEN_FOUND)
35   # not documented modules list
36   list(APPEND blacklist "ts" "java" "python2" "python3" "world" "contrib_world")
37   unset(CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT)
38
39   # gathering headers
40   set(paths_include)
41   set(paths_doc)
42   set(paths_bib)
43   set(paths_sample)
44   set(paths_tutorial)
45   set(paths_hal_interface)
46   set(refs_main)
47   set(refs_extra)
48   set(deps)
49   foreach(m ${BASE_MODULES} ${EXTRA_MODULES})
50     list(FIND blacklist ${m} _pos)
51     if(${_pos} EQUAL -1)
52       # include folder
53       set(header_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/include")
54       if(EXISTS "${header_dir}")
55         list(APPEND paths_include "${header_dir}")
56         list(APPEND deps ${header_dir})
57       endif()
58       # doc folder
59       set(docs_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/doc")
60       if(EXISTS "${docs_dir}")
61         list(APPEND paths_doc "${docs_dir}")
62         list(APPEND deps ${docs_dir})
63       endif()
64       # sample folder
65       set(sample_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/samples")
66       if(EXISTS "${sample_dir}")
67         list(APPEND paths_sample "${sample_dir}")
68         list(APPEND deps ${sample_dir})
69       endif()
70       # tutorial folder
71       set(tutorial_dir "${OPENCV_MODULE_opencv_${m}_LOCATION}/tutorials")
72       if(EXISTS "${tutorial_dir}")
73         list(APPEND paths_tutorial "${tutorial_dir}")
74         list(APPEND deps ${tutorial_dir})
75
76         # tutorial reference entry
77         file(GLOB tutorials RELATIVE "${OPENCV_MODULE_opencv_${m}_LOCATION}" "${tutorial_dir}/*.markdown")
78         foreach (t ${tutorials})
79           if (NOT DEFINED CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT)
80             set(CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT "- @ref tutorial_contrib_root")
81             set(tutorial_contrib_root "${CMAKE_CURRENT_BINARY_DIR}/contrib_tutorials.markdown")
82             file(WRITE "${tutorial_contrib_root}"
83               "Tutorials for contrib modules {#tutorial_contrib_root}\n"
84               "=============================\n")
85           endif()
86           file(STRINGS "${OPENCV_MODULE_opencv_${m}_LOCATION}/${t}" tutorial_id LIMIT_COUNT 1 REGEX ".*{#[^}]+}")
87           string(REGEX REPLACE ".*{#([^}]+)}" "\\1" tutorial_id "${tutorial_id}")
88           file(APPEND "${tutorial_contrib_root}" "- ${m}. @subpage ${tutorial_id}\n")
89         endforeach()
90       endif()
91       # HAL replacement file
92       set(replacement_header "${OPENCV_MODULE_opencv_${m}_LOCATION}/src/hal_replacement.hpp")
93       if(EXISTS "${replacement_header}")
94         list(APPEND paths_hal_interface "${replacement_header}")
95       endif()
96
97       # BiBTeX file
98       set(bib_file "${docs_dir}/${m}.bib")
99       if(EXISTS "${bib_file}")
100         set(paths_bib "${paths_bib} ${bib_file}")
101         list(APPEND deps ${bib_file})
102       endif()
103       # Reference entry
104     #   set(one_ref "@ref ${m} | ${m}\n")
105       set(one_ref "\t- ${m}. @ref ${m}\n")
106       list(FIND EXTRA_MODULES ${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
115   # fix references
116   # set(ref_header "Module name | Folder\n----------- | ------")
117   # if(refs_main)
118   #    set(refs_main "### Main modules\n${ref_header}\n${refs_main}")
119   # endif()
120   # if(refs_extra)
121   #   set(refs_extra "### Extra modules\n${ref_header}\n${refs_extra}")
122   # endif()
123   if(refs_main)
124     set(refs_main "- Main modules:\n${refs_main}")
125   endif()
126   if(refs_extra)
127     set(refs_extra "- Extra modules:\n${refs_extra}")
128   endif()
129
130   # additional config
131   set(doxyfile "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
132   set(rootfile "${CMAKE_CURRENT_BINARY_DIR}/root.markdown")
133   set(bibfile "${CMAKE_CURRENT_SOURCE_DIR}/opencv.bib")
134   set(faqfile "${CMAKE_CURRENT_SOURCE_DIR}/faq.markdown")
135   set(tutorial_path "${CMAKE_CURRENT_SOURCE_DIR}/tutorials")
136   set(tutorial_py_path "${CMAKE_CURRENT_SOURCE_DIR}/py_tutorials")
137   set(example_path "${CMAKE_SOURCE_DIR}/samples")
138
139   # set export variables
140   string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_INPUT_LIST "${rootfile} ; ${faqfile} ; ${paths_include} ; ${paths_hal_interface} ; ${paths_doc} ; ${tutorial_path} ; ${tutorial_py_path} ; ${paths_tutorial} ; ${tutorial_contrib_root}")
141   string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_IMAGE_PATH "${paths_doc} ; ${tutorial_path} ; ${tutorial_py_path} ; ${paths_tutorial}")
142   # TODO: remove paths_doc from EXAMPLE_PATH after face module tutorials/samples moved to separate folders
143   string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_EXAMPLE_PATH  "${example_path} ; ${paths_doc} ; ${paths_sample}")
144   set(CMAKE_DOXYGEN_LAYOUT "${CMAKE_CURRENT_SOURCE_DIR}/DoxygenLayout.xml")
145   set(CMAKE_DOXYGEN_OUTPUT_PATH "doxygen")
146   set(CMAKE_DOXYGEN_MAIN_REFERENCE "${refs_main}")
147   set(CMAKE_DOXYGEN_EXTRA_REFERENCE "${refs_extra}")
148   set(CMAKE_EXTRA_BIB_FILES "${bibfile} ${paths_bib}")
149   if (CMAKE_DOXYGEN_GENERATE_QHP)
150     set(CMAKE_DOXYGEN_GENERATE_QHP "YES")
151   else()
152     set(CMAKE_DOXYGEN_GENERATE_QHP "NO")
153   endif()
154
155   list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/opencv.ico")
156   list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/pattern.png")
157   list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/acircles_pattern.png")
158   list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/bodybg.png")
159   list(APPEND CMAKE_DOXYGEN_HTML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/mymath.sty")
160   string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_HTML_FILES "${CMAKE_DOXYGEN_HTML_FILES}")
161
162   # writing file
163   configure_file(Doxyfile.in ${doxyfile} @ONLY)
164   configure_file(root.markdown.in ${rootfile} @ONLY)
165
166   add_custom_target(doxygen
167     COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
168     DEPENDS ${doxyfile} ${rootfile} ${bibfile} ${deps}
169   )
170   install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html
171     DESTINATION "${OPENCV_DOC_INSTALL_PATH}"
172     COMPONENT "docs" OPTIONAL
173   )
174 endif()