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