Merge pull request #2098 from pxli168:patch-1
[profile/ivi/opencv.git] / cmake / OpenCVModule.cmake
1 # Local variables (set for each module):
2 #
3 # name       - short name in lower case i.e. core
4 # the_module - full name in lower case i.e. opencv_core
5
6 # Global variables:
7 #
8 # OPENCV_MODULE_${the_module}_LOCATION
9 # OPENCV_MODULE_${the_module}_DESCRIPTION
10 # OPENCV_MODULE_${the_module}_CLASS - PUBLIC|INTERNAL|BINDINGS
11 # OPENCV_MODULE_${the_module}_HEADERS
12 # OPENCV_MODULE_${the_module}_SOURCES
13 # OPENCV_MODULE_${the_module}_DEPS - final flattened set of module dependencies
14 # OPENCV_MODULE_${the_module}_DEPS_EXT - non-module dependencies
15 # OPENCV_MODULE_${the_module}_REQ_DEPS
16 # OPENCV_MODULE_${the_module}_OPT_DEPS
17 # OPENCV_MODULE_${the_module}_PRIVATE_REQ_DEPS
18 # OPENCV_MODULE_${the_module}_PRIVATE_OPT_DEPS
19 # HAVE_${the_module} - for fast check of module availability
20
21 # To control the setup of the module you could also set:
22 # the_description - text to be used as current module description
23 # OPENCV_MODULE_TYPE - STATIC|SHARED - set to force override global settings for current module
24 # OPENCV_MODULE_IS_PART_OF_WORLD - ON|OFF (default ON) - should the module be added to the opencv_world?
25 # BUILD_${the_module}_INIT - ON|OFF (default ON) - initial value for BUILD_${the_module}
26
27 # The verbose template for OpenCV module:
28 #
29 #   ocv_add_module(modname <dependencies>)
30 #   ocv_glob_module_sources() or glob them manually and ocv_set_module_sources(...)
31 #   ocv_module_include_directories(<extra include directories>)
32 #   ocv_create_module()
33 #   <add extra link dependencies, compiler options, etc>
34 #   ocv_add_precompiled_headers(${the_module})
35 #   <add extra installation rules>
36 #   ocv_add_accuracy_tests(<extra dependencies>)
37 #   ocv_add_perf_tests(<extra dependencies>)
38 #   ocv_add_samples(<extra dependencies>)
39 #
40 #
41 # If module have no "extra" then you can define it in one line:
42 #
43 #   ocv_define_module(modname <dependencies>)
44
45 # clean flags for modules enabled on previous cmake run
46 # this is necessary to correctly handle modules removal
47 foreach(mod ${OPENCV_MODULES_BUILD} ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MODULES_DISABLED_AUTO} ${OPENCV_MODULES_DISABLED_FORCE})
48   if(HAVE_${mod})
49     unset(HAVE_${mod} CACHE)
50   endif()
51   unset(OPENCV_MODULE_${mod}_REQ_DEPS CACHE)
52   unset(OPENCV_MODULE_${mod}_OPT_DEPS CACHE)
53   unset(OPENCV_MODULE_${mod}_PRIVATE_REQ_DEPS CACHE)
54   unset(OPENCV_MODULE_${mod}_PRIVATE_OPT_DEPS CACHE)
55 endforeach()
56
57 # clean modules info which needs to be recalculated
58 set(OPENCV_MODULES_PUBLIC         "" CACHE INTERNAL "List of OpenCV modules marked for export")
59 set(OPENCV_MODULES_BUILD          "" CACHE INTERNAL "List of OpenCV modules included into the build")
60 set(OPENCV_MODULES_DISABLED_USER  "" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
61 set(OPENCV_MODULES_DISABLED_AUTO  "" CACHE INTERNAL "List of OpenCV modules implicitly disabled due to dependencies")
62 set(OPENCV_MODULES_DISABLED_FORCE "" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration")
63
64 # adds dependencies to OpenCV module
65 # Usage:
66 #   add_dependencies(opencv_<name> [REQUIRED] [<list of dependencies>] [OPTIONAL <list of modules>])
67 # Notes:
68 # * <list of dependencies> - can include full names of modules or full pathes to shared/static libraries or cmake targets
69 macro(ocv_add_dependencies full_modname)
70   #we don't clean the dependencies here to allow this macro several times for every module
71   foreach(d "REQUIRED" ${ARGN})
72     if(d STREQUAL "REQUIRED")
73       set(__depsvar OPENCV_MODULE_${full_modname}_REQ_DEPS)
74     elseif(d STREQUAL "OPTIONAL")
75       set(__depsvar OPENCV_MODULE_${full_modname}_OPT_DEPS)
76     elseif(d STREQUAL "PRIVATE_REQUIRED")
77       set(__depsvar OPENCV_MODULE_${full_modname}_PRIVATE_REQ_DEPS)
78     elseif(d STREQUAL "PRIVATE_OPTIONAL")
79       set(__depsvar OPENCV_MODULE_${full_modname}_PRIVATE_OPT_DEPS)
80     else()
81       list(APPEND ${__depsvar} "${d}")
82     endif()
83   endforeach()
84   unset(__depsvar)
85
86   ocv_list_unique(OPENCV_MODULE_${full_modname}_REQ_DEPS)
87   ocv_list_unique(OPENCV_MODULE_${full_modname}_OPT_DEPS)
88   ocv_list_unique(OPENCV_MODULE_${full_modname}_PRIVATE_REQ_DEPS)
89   ocv_list_unique(OPENCV_MODULE_${full_modname}_PRIVATE_OPT_DEPS)
90
91   set(OPENCV_MODULE_${full_modname}_REQ_DEPS ${OPENCV_MODULE_${full_modname}_REQ_DEPS}
92     CACHE INTERNAL "Required dependencies of ${full_modname} module")
93   set(OPENCV_MODULE_${full_modname}_OPT_DEPS ${OPENCV_MODULE_${full_modname}_OPT_DEPS}
94     CACHE INTERNAL "Optional dependencies of ${full_modname} module")
95   set(OPENCV_MODULE_${full_modname}_PRIVATE_REQ_DEPS ${OPENCV_MODULE_${full_modname}_PRIVATE_REQ_DEPS}
96     CACHE INTERNAL "Required private dependencies of ${full_modname} module")
97   set(OPENCV_MODULE_${full_modname}_PRIVATE_OPT_DEPS ${OPENCV_MODULE_${full_modname}_PRIVATE_OPT_DEPS}
98     CACHE INTERNAL "Optional private dependencies of ${full_modname} module")
99 endmacro()
100
101 # declare new OpenCV module in current folder
102 # Usage:
103 #   ocv_add_module(<name> [INTERNAL|BINDINGS] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
104 # Example:
105 #   ocv_add_module(yaom INTERNAL opencv_core opencv_highgui opencv_flann OPTIONAL opencv_cuda)
106 macro(ocv_add_module _name)
107   string(TOLOWER "${_name}" name)
108   string(REGEX REPLACE "^opencv_" "" ${name} "${name}")
109   set(the_module opencv_${name})
110
111   # the first pass - collect modules info, the second pass - create targets
112   if(OPENCV_INITIAL_PASS)
113     #guard agains redefinition
114     if(";${OPENCV_MODULES_BUILD};${OPENCV_MODULES_DISABLED_USER};" MATCHES ";${the_module};")
115       message(FATAL_ERROR "Redefinition of the ${the_module} module.
116   at:                    ${CMAKE_CURRENT_SOURCE_DIR}
117   previously defined at: ${OPENCV_MODULE_${the_module}_LOCATION}
118 ")
119     endif()
120
121     if(NOT DEFINED the_description)
122       set(the_description "The ${name} OpenCV module")
123     endif()
124
125     if(NOT DEFINED BUILD_${the_module}_INIT)
126       set(BUILD_${the_module}_INIT ON)
127     endif()
128
129     # create option to enable/disable this module
130     option(BUILD_${the_module} "Include ${the_module} module into the OpenCV build" ${BUILD_${the_module}_INIT})
131
132     # remember the module details
133     set(OPENCV_MODULE_${the_module}_DESCRIPTION "${the_description}" CACHE INTERNAL "Brief description of ${the_module} module")
134     set(OPENCV_MODULE_${the_module}_LOCATION    "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Location of ${the_module} module sources")
135
136     # parse list of dependencies
137     if("${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS")
138       set(OPENCV_MODULE_${the_module}_CLASS "${ARGV1}" CACHE INTERNAL "The category of the module")
139       set(__ocv_argn__ ${ARGN})
140       list(REMOVE_AT __ocv_argn__ 0)
141       ocv_add_dependencies(${the_module} ${__ocv_argn__})
142       unset(__ocv_argn__)
143     else()
144       set(OPENCV_MODULE_${the_module}_CLASS "PUBLIC" CACHE INTERNAL "The category of the module")
145       ocv_add_dependencies(${the_module} ${ARGN})
146       if(BUILD_${the_module})
147         set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export")
148       endif()
149     endif()
150
151     # add self to the world dependencies
152     if(NOT DEFINED OPENCV_MODULE_IS_PART_OF_WORLD AND NOT OPENCV_MODULE_${the_module}_CLASS STREQUAL "BINDINGS" OR OPENCV_MODULE_IS_PART_OF_WORLD)
153       ocv_add_dependencies(opencv_world OPTIONAL ${the_module})
154     endif()
155
156     if(BUILD_${the_module})
157       set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} "${the_module}" CACHE INTERNAL "List of OpenCV modules included into the build")
158     else()
159       set(OPENCV_MODULES_DISABLED_USER ${OPENCV_MODULES_DISABLED_USER} "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
160     endif()
161
162     # TODO: add submodules if any
163
164     # stop processing of current file
165     return()
166   else(OPENCV_INITIAL_PASS)
167     if(NOT BUILD_${the_module})
168       return() # extra protection from redefinition
169     endif()
170     project(${the_module})
171   endif(OPENCV_INITIAL_PASS)
172 endmacro()
173
174 # excludes module from current configuration
175 macro(ocv_module_disable module)
176   set(__modname ${module})
177   if(NOT __modname MATCHES "^opencv_")
178     set(__modname opencv_${module})
179   endif()
180   list(APPEND OPENCV_MODULES_DISABLED_FORCE "${__modname}")
181   set(HAVE_${__modname} OFF CACHE INTERNAL "Module ${__modname} can not be built in current configuration")
182   set(OPENCV_MODULE_${__modname}_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Location of ${__modname} module sources")
183   set(OPENCV_MODULES_DISABLED_FORCE "${OPENCV_MODULES_DISABLED_FORCE}" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration")
184   if(BUILD_${__modname})
185     # touch variable controlling build of the module to suppress "unused variable" CMake warning
186   endif()
187   unset(__modname)
188   return() # leave the current folder
189 endmacro()
190
191
192 # collect modules from specified directories
193 # NB: must be called only once!
194 macro(ocv_glob_modules)
195   if(DEFINED OPENCV_INITIAL_PASS)
196     message(FATAL_ERROR "OpenCV has already loaded its modules. Calling ocv_glob_modules second time is not allowed.")
197   endif()
198   set(__directories_observed "")
199
200   # collect modules
201   set(OPENCV_INITIAL_PASS ON)
202   foreach(__path ${ARGN})
203     get_filename_component(__path "${__path}" ABSOLUTE)
204
205     list(FIND __directories_observed "${__path}" __pathIdx)
206     if(__pathIdx GREATER -1)
207       message(FATAL_ERROR "The directory ${__path} is observed for OpenCV modules second time.")
208     endif()
209     list(APPEND __directories_observed "${__path}")
210
211     file(GLOB __ocvmodules RELATIVE "${__path}" "${__path}/*")
212     if(__ocvmodules)
213       list(SORT __ocvmodules)
214       foreach(mod ${__ocvmodules})
215         get_filename_component(__modpath "${__path}/${mod}" ABSOLUTE)
216         if(EXISTS "${__modpath}/CMakeLists.txt")
217
218           list(FIND __directories_observed "${__modpath}" __pathIdx)
219           if(__pathIdx GREATER -1)
220             message(FATAL_ERROR "The module from ${__modpath} is already loaded.")
221           endif()
222           list(APPEND __directories_observed "${__modpath}")
223
224           if(OCV_MODULE_RELOCATE_ON_INITIAL_PASS)
225             file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
226             file(COPY "${__modpath}/CMakeLists.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
227             add_subdirectory("${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
228             if("${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
229               set(OPENCV_MODULE_opencv_${mod}_LOCATION "${__modpath}" CACHE PATH "" FORCE)
230             endif()
231           else()
232             add_subdirectory("${__modpath}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
233           endif()
234         endif()
235       endforeach()
236     endif()
237   endforeach()
238   ocv_clear_vars(__ocvmodules __directories_observed __path __modpath __pathIdx)
239
240   # resolve dependencies
241   __ocv_resolve_dependencies()
242
243   # create modules
244   set(OPENCV_INITIAL_PASS OFF PARENT_SCOPE)
245   set(OPENCV_INITIAL_PASS OFF)
246   foreach(m ${OPENCV_MODULES_BUILD})
247     if(m MATCHES "^opencv_")
248       string(REGEX REPLACE "^opencv_" "" __shortname "${m}")
249       add_subdirectory("${OPENCV_MODULE_${m}_LOCATION}" "${CMAKE_CURRENT_BINARY_DIR}/${__shortname}")
250     else()
251       message(WARNING "Check module name: ${m}")
252       add_subdirectory("${OPENCV_MODULE_${m}_LOCATION}" "${CMAKE_CURRENT_BINARY_DIR}/${m}")
253     endif()
254   endforeach()
255   unset(__shortname)
256 endmacro()
257
258
259 # disables OpenCV module with missing dependencies
260 function(__ocv_module_turn_off the_module)
261   list(REMOVE_ITEM OPENCV_MODULES_DISABLED_AUTO "${the_module}")
262   list(APPEND OPENCV_MODULES_DISABLED_AUTO "${the_module}")
263   list(REMOVE_ITEM OPENCV_MODULES_BUILD "${the_module}")
264   list(REMOVE_ITEM OPENCV_MODULES_PUBLIC "${the_module}")
265   set(HAVE_${the_module} OFF CACHE INTERNAL "Module ${the_module} can not be built in current configuration")
266
267   set(OPENCV_MODULES_DISABLED_AUTO "${OPENCV_MODULES_DISABLED_AUTO}" CACHE INTERNAL "")
268   set(OPENCV_MODULES_BUILD "${OPENCV_MODULES_BUILD}" CACHE INTERNAL "")
269   set(OPENCV_MODULES_PUBLIC "${OPENCV_MODULES_PUBLIC}" CACHE INTERNAL "")
270 endfunction()
271
272 # sort modules by dependencies
273 function(__ocv_sort_modules_by_deps __lst)
274   ocv_list_sort(${__lst})
275   set(${__lst}_ORDERED ${${__lst}} CACHE INTERNAL "")
276   set(__result "")
277   foreach (m ${${__lst}})
278     list(LENGTH __result __lastindex)
279     set(__index ${__lastindex})
280     foreach (__d ${__result})
281       set(__deps "${OPENCV_MODULE_${__d}_DEPS}")
282       if(";${__deps};" MATCHES ";${m};")
283         list(FIND __result "${__d}" __i)
284         if(__i LESS "${__index}")
285           set(__index "${__i}")
286         endif()
287       endif()
288     endforeach()
289     if(__index STREQUAL __lastindex)
290       list(APPEND __result "${m}")
291     else()
292       list(INSERT __result ${__index} "${m}")
293     endif()
294   endforeach()
295   set(${__lst} "${__result}" PARENT_SCOPE)
296 endfunction()
297
298 # resolve dependensies
299 function(__ocv_resolve_dependencies)
300   foreach(m ${OPENCV_MODULES_DISABLED_USER})
301     set(HAVE_${m} OFF CACHE INTERNAL "Module ${m} will not be built in current configuration")
302   endforeach()
303   foreach(m ${OPENCV_MODULES_BUILD})
304     set(HAVE_${m} ON CACHE INTERNAL "Module ${m} will be built in current configuration")
305   endforeach()
306
307   # disable MODULES with unresolved dependencies
308   set(has_changes ON)
309   while(has_changes)
310     set(has_changes OFF)
311     foreach(m ${OPENCV_MODULES_BUILD})
312       set(__deps ${OPENCV_MODULE_${m}_REQ_DEPS} ${OPENCV_MODULE_${m}_PRIVATE_REQ_DEPS})
313       while(__deps)
314         ocv_list_pop_front(__deps d)
315         string(TOLOWER "${d}" upper_d)
316         if(NOT (HAVE_${d} OR HAVE_${upper_d} OR TARGET ${d} OR EXISTS ${d}))
317           if(d MATCHES "^opencv_") # TODO Remove this condition in the future and use HAVE_ variables only
318             message(STATUS "Module ${m} disabled because ${d} dependency can't be resolved!")
319             __ocv_module_turn_off(${m})
320             set(has_changes ON)
321             break()
322           else()
323             message(STATUS "Assume that non-module dependency is available: ${d} (for module ${m})")
324           endif()
325         endif()
326       endwhile()
327     endforeach()
328   endwhile()
329
330 #  message(STATUS "List of active modules: ${OPENCV_MODULES_BUILD}")
331
332   foreach(m ${OPENCV_MODULES_BUILD})
333     set(deps_${m} ${OPENCV_MODULE_${m}_REQ_DEPS})
334     foreach(d ${OPENCV_MODULE_${m}_OPT_DEPS})
335       if(NOT (";${deps_${m}};" MATCHES ";${d};"))
336         if(HAVE_${d} OR TARGET ${d})
337           list(APPEND deps_${m} ${d})
338         endif()
339       endif()
340     endforeach()
341 #    message(STATUS "Initial deps of ${m} (w/o private deps): ${deps_${m}}")
342   endforeach()
343
344   # propagate dependencies
345   set(has_changes ON)
346   while(has_changes)
347     set(has_changes OFF)
348     foreach(m2 ${OPENCV_MODULES_BUILD}) # transfer deps of m2 to m
349       foreach(m ${OPENCV_MODULES_BUILD})
350         if((NOT m STREQUAL m2) AND ";${deps_${m}};" MATCHES ";${m2};")
351           foreach(d ${deps_${m2}})
352             if(NOT (";${deps_${m}};" MATCHES ";${d};"))
353 #              message(STATUS "  Transfer dependency ${d} from ${m2} to ${m}")
354               list(APPEND deps_${m} ${d})
355               set(has_changes ON)
356             endif()
357           endforeach()
358         endif()
359       endforeach()
360     endforeach()
361   endwhile()
362
363   # process private deps
364   foreach(m ${OPENCV_MODULES_BUILD})
365     foreach(d ${OPENCV_MODULE_${m}_PRIVATE_REQ_DEPS})
366       if(NOT (";${deps_${m}};" MATCHES ";${d};"))
367         list(APPEND deps_${m} ${d})
368       endif()
369     endforeach()
370     foreach(d ${OPENCV_MODULE_${m}_PRIVATE_OPT_DEPS})
371       if(NOT (";${deps_${m}};" MATCHES ";${d};"))
372         if(HAVE_${d} OR TARGET ${d})
373           list(APPEND deps_${m} ${d})
374         endif()
375       endif()
376     endforeach()
377   endforeach()
378
379   ocv_list_sort(OPENCV_MODULES_BUILD)
380
381   foreach(m ${OPENCV_MODULES_BUILD})
382 #    message(STATUS "FULL deps of ${m}: ${deps_${m}}")
383     set(OPENCV_MODULE_${m}_DEPS ${deps_${m}})
384     set(OPENCV_MODULE_${m}_DEPS_EXT ${deps_${m}})
385     ocv_list_filterout(OPENCV_MODULE_${m}_DEPS_EXT "^opencv_[^ ]+$")
386     if(OPENCV_MODULE_${m}_DEPS_EXT AND OPENCV_MODULE_${m}_DEPS)
387       list(REMOVE_ITEM OPENCV_MODULE_${m}_DEPS ${OPENCV_MODULE_${m}_DEPS_EXT})
388     endif()
389   endforeach()
390
391   # reorder dependencies
392   foreach(m ${OPENCV_MODULES_BUILD})
393     __ocv_sort_modules_by_deps(OPENCV_MODULE_${m}_DEPS)
394     ocv_list_sort(OPENCV_MODULE_${m}_DEPS_EXT)
395
396     set(OPENCV_MODULE_${m}_DEPS ${OPENCV_MODULE_${m}_DEPS} CACHE INTERNAL "Flattened dependencies of ${m} module")
397     set(OPENCV_MODULE_${m}_DEPS_EXT ${OPENCV_MODULE_${m}_DEPS_EXT} CACHE INTERNAL "Extra dependencies of ${m} module")
398
399 #    message(STATUS "  module deps: ${OPENCV_MODULE_${m}_DEPS}")
400 #    message(STATUS "  extra deps: ${OPENCV_MODULE_${m}_DEPS_EXT}")
401   endforeach()
402
403   __ocv_sort_modules_by_deps(OPENCV_MODULES_BUILD)
404
405   set(OPENCV_MODULES_PUBLIC        ${OPENCV_MODULES_PUBLIC}        CACHE INTERNAL "List of OpenCV modules marked for export")
406   set(OPENCV_MODULES_BUILD         ${OPENCV_MODULES_BUILD}         CACHE INTERNAL "List of OpenCV modules included into the build")
407   set(OPENCV_MODULES_DISABLED_AUTO ${OPENCV_MODULES_DISABLED_AUTO} CACHE INTERNAL "List of OpenCV modules implicitly disabled due to dependencies")
408 endfunction()
409
410
411 # setup include paths for the list of passed modules
412 macro(ocv_include_modules)
413   foreach(d ${ARGN})
414     if(d MATCHES "^opencv_" AND HAVE_${d})
415       if (EXISTS "${OPENCV_MODULE_${d}_LOCATION}/include")
416         ocv_include_directories("${OPENCV_MODULE_${d}_LOCATION}/include")
417       endif()
418     elseif(EXISTS "${d}")
419       ocv_include_directories("${d}")
420     endif()
421   endforeach()
422 endmacro()
423
424 # setup include paths for the list of passed modules and recursively add dependent modules
425 macro(ocv_include_modules_recurse)
426   foreach(d ${ARGN})
427     if(d MATCHES "^opencv_" AND HAVE_${d})
428       if (EXISTS "${OPENCV_MODULE_${d}_LOCATION}/include")
429         ocv_include_directories("${OPENCV_MODULE_${d}_LOCATION}/include")
430       endif()
431       if(OPENCV_MODULE_${d}_DEPS)
432         ocv_include_modules(${OPENCV_MODULE_${d}_DEPS})
433       endif()
434     elseif(EXISTS "${d}")
435       ocv_include_directories("${d}")
436     endif()
437   endforeach()
438 endmacro()
439
440 # setup include path for OpenCV headers for specified module
441 # ocv_module_include_directories(<extra include directories/extra include modules>)
442 macro(ocv_module_include_directories)
443   ocv_include_directories("${OPENCV_MODULE_${the_module}_LOCATION}/include"
444                           "${OPENCV_MODULE_${the_module}_LOCATION}/src"
445                           "${CMAKE_CURRENT_BINARY_DIR}" # for precompiled headers
446                           )
447   ocv_include_modules(${OPENCV_MODULE_${the_module}_DEPS} ${ARGN})
448 endmacro()
449
450
451 # sets header and source files for the current module
452 # NB: all files specified as headers will be installed
453 # Usage:
454 # ocv_set_module_sources([HEADERS] <list of files> [SOURCES] <list of files>)
455 macro(ocv_set_module_sources)
456   set(OPENCV_MODULE_${the_module}_HEADERS "")
457   set(OPENCV_MODULE_${the_module}_SOURCES "")
458
459   foreach(f "HEADERS" ${ARGN})
460     if(f STREQUAL "HEADERS" OR f STREQUAL "SOURCES")
461       set(__filesvar "OPENCV_MODULE_${the_module}_${f}")
462     else()
463       list(APPEND ${__filesvar} "${f}")
464     endif()
465   endforeach()
466
467   # the hacky way to embeed any files into the OpenCV without modification of its build system
468   if(COMMAND ocv_get_module_external_sources)
469     ocv_get_module_external_sources()
470   endif()
471
472   # use full paths for module to be independent from the module location
473   ocv_convert_to_full_paths(OPENCV_MODULE_${the_module}_HEADERS)
474
475   set(OPENCV_MODULE_${the_module}_HEADERS ${OPENCV_MODULE_${the_module}_HEADERS} CACHE INTERNAL "List of header files for ${the_module}")
476   set(OPENCV_MODULE_${the_module}_SOURCES ${OPENCV_MODULE_${the_module}_SOURCES} CACHE INTERNAL "List of source files for ${the_module}")
477 endmacro()
478
479 # finds and sets headers and sources for the standard OpenCV module
480 # Usage:
481 # ocv_glob_module_sources(<extra sources&headers in the same format as used in ocv_set_module_sources>)
482 macro(ocv_glob_module_sources)
483   file(GLOB_RECURSE lib_srcs     "src/*.cpp")
484   file(GLOB_RECURSE lib_int_hdrs "src/*.hpp" "src/*.h")
485   file(GLOB lib_hdrs     "include/opencv2/*.hpp" "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
486   file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h")
487
488   ocv_source_group("Src" DIRBASE "${CMAKE_CURRENT_SOURCE_DIR}/src" FILES ${lib_srcs} ${lib_int_hdrs})
489   ocv_source_group("Include" DIRBASE "${CMAKE_CURRENT_SOURCE_DIR}/include" FILES ${lib_hdrs} ${lib_hdrs_detail})
490
491   file(GLOB lib_cuda_srcs "src/cuda/*.cu")
492   set(cuda_objs "")
493   set(lib_cuda_hdrs "")
494   if(HAVE_CUDA AND lib_cuda_srcs)
495     ocv_include_directories(${CUDA_INCLUDE_DIRS})
496     file(GLOB lib_cuda_hdrs "src/cuda/*.hpp")
497
498     ocv_cuda_compile(cuda_objs ${lib_cuda_srcs} ${lib_cuda_hdrs})
499     source_group("Src\\Cuda" FILES ${lib_cuda_srcs} ${lib_cuda_hdrs})
500   endif()
501
502   file(GLOB cl_kernels "src/opencl/*.cl")
503   if(cl_kernels)
504     ocv_include_directories(${OPENCL_INCLUDE_DIRS})
505     string(REGEX REPLACE "opencv_" "" the_module_barename "${the_module}")
506     add_custom_command(
507       OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp"
508       COMMAND ${CMAKE_COMMAND} -DMODULE_NAME="${the_module_barename}" -DCL_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src/opencl" -DOUTPUT="${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" -P "${OpenCV_SOURCE_DIR}/cmake/cl2cpp.cmake"
509       DEPENDS ${cl_kernels} "${OpenCV_SOURCE_DIR}/cmake/cl2cpp.cmake")
510     ocv_source_group("Src\\opencl\\kernels" FILES ${cl_kernels})
511     ocv_source_group("Src\\opencl\\kernels\\autogenerated" FILES "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp")
512     list(APPEND lib_srcs ${cl_kernels} "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp")
513   endif()
514
515   ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail}
516                                  SOURCES ${lib_srcs} ${lib_int_hdrs} ${cuda_objs} ${lib_cuda_srcs} ${lib_cuda_hdrs})
517 endmacro()
518
519 # creates OpenCV module in current folder
520 # creates new target, configures standard dependencies, compilers flags, install rules
521 # Usage:
522 #   ocv_create_module(<extra link dependencies>)
523 #   ocv_create_module(SKIP_LINK)
524 macro(ocv_create_module)
525   # The condition we ought to be testing here is whether ocv_add_precompiled_headers will
526   # be called at some point in the future. We can't look into the future, though,
527   # so this will have to do.
528   if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp")
529     get_native_precompiled_header(${the_module} precomp.hpp)
530   endif()
531
532   add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES}
533     "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp"
534     ${${the_module}_pch})
535   if(NOT the_module STREQUAL opencv_ts)
536     set_target_properties(${the_module} PROPERTIES COMPILE_DEFINITIONS OPENCV_NOSTL)
537   endif()
538
539   if(NOT "${ARGN}" STREQUAL "SKIP_LINK")
540     target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS})
541     target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${OPENCV_MODULE_${the_module}_DEPS})
542     target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
543     if (HAVE_CUDA)
544       target_link_libraries(${the_module} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
545     endif()
546   endif()
547
548   add_dependencies(opencv_modules ${the_module})
549
550   if(ENABLE_SOLUTION_FOLDERS)
551     set_target_properties(${the_module} PROPERTIES FOLDER "modules")
552   endif()
553
554   set_target_properties(${the_module} PROPERTIES
555     OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}"
556     DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
557     ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
558     LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
559     RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
560     INSTALL_NAME_DIR lib
561   )
562
563   # For dynamic link numbering convenions
564   if(NOT ANDROID)
565     # Android SDK build scripts can include only .so files into final .apk
566     # As result we should not set version properties for Android
567     set_target_properties(${the_module} PROPERTIES
568       VERSION ${OPENCV_LIBVERSION}
569       SOVERSION ${OPENCV_SOVERSION}
570     )
571   endif()
572
573   if((NOT DEFINED OPENCV_MODULE_TYPE AND BUILD_SHARED_LIBS)
574       OR (DEFINED OPENCV_MODULE_TYPE AND OPENCV_MODULE_TYPE STREQUAL SHARED))
575     set_target_properties(${the_module} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
576   endif()
577
578   if(MSVC)
579     if(CMAKE_CROSSCOMPILING)
580       set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk")
581     endif()
582     set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG")
583   endif()
584
585   ocv_install_target(${the_module} EXPORT OpenCVModules
586     RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs
587     LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs
588     ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT dev
589     )
590
591   # only "public" headers need to be installed
592   if(OPENCV_MODULE_${the_module}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${the_module};")
593     foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
594       string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
595       if(NOT hdr2 MATCHES "opencv2/${the_module}/private.*" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
596         install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev)
597       endif()
598     endforeach()
599   endif()
600 endmacro()
601
602 # opencv precompiled headers macro (can add pch to modules and tests)
603 # this macro must be called after any "add_definitions" commands, otherwise precompiled headers will not work
604 # Usage:
605 # ocv_add_precompiled_headers(${the_module})
606 macro(ocv_add_precompiled_headers the_target)
607   if("${the_target}" MATCHES "^opencv_test_.*$")
608     SET(pch_path "test/test_")
609   elseif("${the_target}" MATCHES "^opencv_perf_.*$")
610     SET(pch_path "perf/perf_")
611   else()
612     SET(pch_path "src/")
613   endif()
614   ocv_add_precompiled_header_to_target(${the_target} "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.hpp")
615   unset(pch_path)
616 endmacro()
617
618 # short command for adding simple OpenCV module
619 # see ocv_add_module for argument details
620 # Usage:
621 # ocv_define_module(module_name  [INTERNAL] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
622 macro(ocv_define_module module_name)
623   ocv_add_module(${module_name} ${ARGN})
624   ocv_module_include_directories()
625   ocv_glob_module_sources()
626   ocv_create_module()
627   ocv_add_precompiled_headers(${the_module})
628
629   ocv_add_accuracy_tests()
630   ocv_add_perf_tests()
631   ocv_add_samples()
632 endmacro()
633
634 # ensures that all passed modules are available
635 # sets OCV_DEPENDENCIES_FOUND variable to TRUE/FALSE
636 macro(ocv_check_dependencies)
637   set(OCV_DEPENDENCIES_FOUND TRUE)
638   foreach(d ${ARGN})
639     if(d MATCHES "^opencv_[^ ]+$" AND NOT HAVE_${d})
640       set(OCV_DEPENDENCIES_FOUND FALSE)
641       break()
642     endif()
643   endforeach()
644 endmacro()
645
646 # auxiliary macro to parse arguments of ocv_add_accuracy_tests and ocv_add_perf_tests commands
647 macro(__ocv_parse_test_sources tests_type)
648   set(OPENCV_${tests_type}_${the_module}_SOURCES "")
649   set(OPENCV_${tests_type}_${the_module}_DEPS "")
650   set(__file_group_name "")
651   set(__file_group_sources "")
652   foreach(arg "DEPENDS_ON" ${ARGN} "FILES")
653     if(arg STREQUAL "FILES")
654       set(__currentvar "__file_group_sources")
655       if(__file_group_name AND __file_group_sources)
656         source_group("${__file_group_name}" FILES ${__file_group_sources})
657         list(APPEND OPENCV_${tests_type}_${the_module}_SOURCES ${__file_group_sources})
658       endif()
659       set(__file_group_name "")
660       set(__file_group_sources "")
661     elseif(arg STREQUAL "DEPENDS_ON")
662       set(__currentvar "OPENCV_TEST_${the_module}_DEPS")
663     elseif("${__currentvar}" STREQUAL "__file_group_sources" AND NOT __file_group_name)
664       set(__file_group_name "${arg}")
665     else()
666       list(APPEND ${__currentvar} "${arg}")
667     endif()
668   endforeach()
669   unset(__file_group_name)
670   unset(__file_group_sources)
671   unset(__currentvar)
672 endmacro()
673
674 # this is a command for adding OpenCV performance tests to the module
675 # ocv_add_perf_tests(<extra_dependencies>)
676 function(ocv_add_perf_tests)
677   set(perf_path "${CMAKE_CURRENT_SOURCE_DIR}/perf")
678   if(BUILD_PERF_TESTS AND EXISTS "${perf_path}")
679     __ocv_parse_test_sources(PERF ${ARGN})
680
681     # opencv_highgui is required for imread/imwrite
682     set(perf_deps ${the_module} opencv_ts opencv_highgui ${OPENCV_PERF_${the_module}_DEPS} ${OPENCV_MODULE_opencv_ts_DEPS})
683     ocv_check_dependencies(${perf_deps})
684
685     if(OCV_DEPENDENCIES_FOUND)
686       set(the_target "opencv_perf_${name}")
687       # project(${the_target})
688
689       ocv_module_include_directories(${perf_deps} "${perf_path}")
690
691       if(NOT OPENCV_PERF_${the_module}_SOURCES)
692         file(GLOB_RECURSE perf_srcs "${perf_path}/*.cpp")
693         file(GLOB_RECURSE perf_hdrs "${perf_path}/*.hpp" "${perf_path}/*.h")
694         ocv_source_group("Src" DIRBASE "${perf_path}" FILES ${perf_srcs})
695         ocv_source_group("Include" DIRBASE "${perf_path}" FILES ${perf_hdrs})
696         set(OPENCV_PERF_${the_module}_SOURCES ${perf_srcs} ${perf_hdrs})
697       endif()
698
699       get_native_precompiled_header(${the_target} perf_precomp.hpp)
700
701       add_executable(${the_target} ${OPENCV_PERF_${the_module}_SOURCES} ${${the_target}_pch})
702       target_link_libraries(${the_target} ${OPENCV_MODULE_${the_module}_DEPS} ${perf_deps} ${OPENCV_LINKER_LIBS})
703       add_dependencies(opencv_perf_tests ${the_target})
704
705       # Additional target properties
706       set_target_properties(${the_target} PROPERTIES
707         DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
708         RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
709       )
710
711       if(ENABLE_SOLUTION_FOLDERS)
712         set_target_properties(${the_target} PROPERTIES FOLDER "tests performance")
713       endif()
714
715       ocv_add_precompiled_headers(${the_target})
716
717     else(OCV_DEPENDENCIES_FOUND)
718       # TODO: warn about unsatisfied dependencies
719     endif(OCV_DEPENDENCIES_FOUND)
720     if(INSTALL_TESTS)
721       install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests)
722     endif()
723   endif()
724 endfunction()
725
726 # this is a command for adding OpenCV accuracy/regression tests to the module
727 # ocv_add_accuracy_tests([FILES <source group name> <list of sources>] [DEPENDS_ON] <list of extra dependencies>)
728 function(ocv_add_accuracy_tests)
729   set(test_path "${CMAKE_CURRENT_SOURCE_DIR}/test")
730   ocv_check_dependencies(${test_deps})
731   if(BUILD_TESTS AND EXISTS "${test_path}")
732     __ocv_parse_test_sources(TEST ${ARGN})
733
734     # opencv_highgui is required for imread/imwrite
735     set(test_deps ${the_module} opencv_ts opencv_highgui ${OPENCV_TEST_${the_module}_DEPS} ${OPENCV_MODULE_opencv_ts_DEPS})
736     ocv_check_dependencies(${test_deps})
737
738     if(OCV_DEPENDENCIES_FOUND)
739       set(the_target "opencv_test_${name}")
740       # project(${the_target})
741
742       ocv_module_include_directories(${test_deps} "${test_path}")
743
744       if(NOT OPENCV_TEST_${the_module}_SOURCES)
745         file(GLOB_RECURSE test_srcs "${test_path}/*.cpp")
746         file(GLOB_RECURSE test_hdrs "${test_path}/*.hpp" "${test_path}/*.h")
747         ocv_source_group("Src" DIRBASE "${test_path}" FILES ${test_srcs})
748         ocv_source_group("Include" DIRBASE "${test_path}" FILES ${test_hdrs})
749         set(OPENCV_TEST_${the_module}_SOURCES ${test_srcs} ${test_hdrs})
750       endif()
751
752       get_native_precompiled_header(${the_target} test_precomp.hpp)
753
754       add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} ${${the_target}_pch})
755       target_link_libraries(${the_target} ${OPENCV_MODULE_${the_module}_DEPS} ${test_deps} ${OPENCV_LINKER_LIBS})
756       add_dependencies(opencv_tests ${the_target})
757
758       # Additional target properties
759       set_target_properties(${the_target} PROPERTIES
760         DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
761         RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
762       )
763
764       if(ENABLE_SOLUTION_FOLDERS)
765         set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy")
766       endif()
767
768       enable_testing()
769       get_target_property(LOC ${the_target} LOCATION)
770       add_test(${the_target} "${LOC}")
771
772       ocv_add_precompiled_headers(${the_target})
773     else(OCV_DEPENDENCIES_FOUND)
774       # TODO: warn about unsatisfied dependencies
775     endif(OCV_DEPENDENCIES_FOUND)
776
777     if(INSTALL_TESTS)
778       install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests)
779     endif()
780   endif()
781 endfunction()
782
783 function(ocv_add_samples)
784   set(samples_path "${CMAKE_CURRENT_SOURCE_DIR}/samples")
785   string(REGEX REPLACE "^opencv_" "" module_id ${the_module})
786
787   if(BUILD_EXAMPLES AND EXISTS "${samples_path}")
788     set(samples_deps ${the_module} ${OPENCV_MODULE_${the_module}_DEPS} opencv_highgui ${ARGN})
789     ocv_check_dependencies(${samples_deps})
790
791     if(OCV_DEPENDENCIES_FOUND)
792       file(GLOB sample_sources "${samples_path}/*.cpp")
793       ocv_include_modules(${OPENCV_MODULE_${the_module}_DEPS})
794
795       foreach(source ${sample_sources})
796         get_filename_component(name "${source}" NAME_WE)
797         set(the_target "example_${module_id}_${name}")
798
799         add_executable(${the_target} "${source}")
800         target_link_libraries(${the_target} ${samples_deps})
801
802         set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}")
803
804         if(ENABLE_SOLUTION_FOLDERS)
805           set_target_properties(${the_target} PROPERTIES
806             OUTPUT_NAME "${module_id}-example-${name}"
807             FOLDER "samples/${module_id}")
808         endif()
809
810         if(WIN32)
811           install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT samples)
812         endif()
813       endforeach()
814     endif()
815   endif()
816
817   if(INSTALL_C_EXAMPLES AND NOT WIN32 AND EXISTS "${samples_path}")
818     file(GLOB sample_files "${samples_path}/*")
819     install(FILES ${sample_files}
820             DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id}
821             PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
822   endif()
823 endfunction()
824
825 # internal macro; finds all link dependencies of the module
826 # should be used at the end of CMake processing
827 macro(__ocv_track_module_link_dependencies the_module optkind)
828   set(${the_module}_MODULE_DEPS_${optkind}   "")
829   set(${the_module}_EXTRA_DEPS_${optkind}    "")
830
831   get_target_property(__module_type ${the_module} TYPE)
832   if(__module_type STREQUAL "STATIC_LIBRARY")
833     #in case of static library we have to inherit its dependencies (in right order!!!)
834     if(NOT DEFINED ${the_module}_LIB_DEPENDS_${optkind})
835       ocv_split_libs_list(${the_module}_LIB_DEPENDS ${the_module}_LIB_DEPENDS_DBG ${the_module}_LIB_DEPENDS_OPT)
836     endif()
837
838     set(__resolved_deps "")
839     set(__mod_depends ${${the_module}_LIB_DEPENDS_${optkind}})
840     set(__has_cycle FALSE)
841
842     while(__mod_depends)
843       list(GET __mod_depends 0 __dep)
844       list(REMOVE_AT __mod_depends 0)
845       if(__dep STREQUAL the_module)
846         set(__has_cycle TRUE)
847       else()#if("${OPENCV_MODULES_BUILD}" MATCHES "(^|;)${__dep}(;|$)")
848         ocv_regex_escape(__rdep "${__dep}")
849         if(__resolved_deps MATCHES "(^|;)${__rdep}(;|$)")
850           #all dependencies of this module are already resolved
851           list(APPEND ${the_module}_MODULE_DEPS_${optkind} "${__dep}")
852         else()
853           get_target_property(__module_type ${__dep} TYPE)
854           if(__module_type STREQUAL "STATIC_LIBRARY")
855             if(NOT DEFINED ${__dep}_LIB_DEPENDS_${optkind})
856               ocv_split_libs_list(${__dep}_LIB_DEPENDS ${__dep}_LIB_DEPENDS_DBG ${__dep}_LIB_DEPENDS_OPT)
857             endif()
858             list(INSERT __mod_depends 0 ${${__dep}_LIB_DEPENDS_${optkind}} ${__dep})
859             list(APPEND __resolved_deps "${__dep}")
860           elseif(NOT __module_type)
861             list(APPEND  ${the_module}_EXTRA_DEPS_${optkind} "${__dep}")
862           endif()
863         endif()
864       #else()
865        # get_target_property(__dep_location "${__dep}" LOCATION)
866       endif()
867     endwhile()
868
869     ocv_list_unique(${the_module}_MODULE_DEPS_${optkind})
870     #ocv_list_reverse(${the_module}_MODULE_DEPS_${optkind})
871     ocv_list_unique(${the_module}_EXTRA_DEPS_${optkind})
872     #ocv_list_reverse(${the_module}_EXTRA_DEPS_${optkind})
873
874     if(__has_cycle)
875       # not sure if it can work
876       list(APPEND ${the_module}_MODULE_DEPS_${optkind} "${the_module}")
877     endif()
878
879     unset(__dep_location)
880     unset(__mod_depends)
881     unset(__resolved_deps)
882     unset(__has_cycle)
883     unset(__rdep)
884   endif()#STATIC_LIBRARY
885   unset(__module_type)
886
887   #message("${the_module}_MODULE_DEPS_${optkind}")
888   #message("       ${${the_module}_MODULE_DEPS_${optkind}}")
889   #message("       ${OPENCV_MODULE_${the_module}_DEPS}")
890   #message("")
891   #message("${the_module}_EXTRA_DEPS_${optkind}")
892   #message("       ${${the_module}_EXTRA_DEPS_${optkind}}")
893   #message("")
894 endmacro()
895
896 # creates lists of build dependencies needed for external projects
897 macro(ocv_track_build_dependencies)
898   foreach(m ${OPENCV_MODULES_BUILD})
899     __ocv_track_module_link_dependencies("${m}" OPT)
900     __ocv_track_module_link_dependencies("${m}" DBG)
901   endforeach()
902 endmacro()