1 # Local variables (set for each module):
3 # name - short name in lower case i.e. core
4 # the_module - full name in lower case i.e. opencv_core
8 # OPENCV_MODULE_${the_module}_LOCATION
9 # OPENCV_MODULE_${the_module}_DESCRIPTION
10 # OPENCV_MODULE_${the_module}_HEADERS
11 # OPENCV_MODULE_${the_module}_SOURCES
12 # OPENCV_MODULE_${the_module}_DEPS - final flattened set of module dependencies
13 # OPENCV_MODULE_${the_module}_DEPS_EXT
14 # OPENCV_MODULE_${the_module}_REQ_DEPS
15 # OPENCV_MODULE_${the_module}_OPT_DEPS
16 # HAVE_${the_module} - for fast check of module availability
18 # To control the setup of the module you could also set:
19 # the_description - text to be used as current module description
20 # OPENCV_MODULE_TYPE - STATIC|SHARED - set to force override global settings for current module
22 # The verbose template for OpenCV module:
24 # ocv_add_module(modname <dependencies>)
25 # ocv_glob_module_sources() or glob them manually and ocv_set_module_sources(...)
26 # ocv_module_include_directories(<extra include directories>)
28 # <add extra link dependencies, compiler options, etc>
29 # ocv_add_precompiled_headers(${the_module})
30 # <add extra installation rules>
31 # ocv_add_accuracy_tests(<extra dependencies>)
32 # ocv_add_perf_tests(<extra dependencies>)
35 # If module have no "extra" then you can define it in one line:
37 # ocv_define_module(modname <dependencies>)
39 # clean flags for modules enabled on previous cmake run
40 # this is necessary to correctly handle modules removal
41 foreach(mod ${OPENCV_MODULES_BUILD})
43 unset(HAVE_${mod} CACHE)
47 # clean modules info which needs to be recalculated
48 set(OPENCV_MODULES_PUBLIC "" CACHE INTERNAL "List of OpenCV modules marked for export")
49 set(OPENCV_MODULES_BUILD "" CACHE INTERNAL "List of OpenCV modules included into the build")
50 set(OPENCV_MODULES_DISABLED_USER "" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
51 set(OPENCV_MODULES_DISABLED_AUTO "" CACHE INTERNAL "List of OpenCV modules implicitly disabled due to dependencies")
52 set(OPENCV_MODULES_DISABLED_FORCE "" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration")
54 # adds dependencies to OpenCV module
56 # add_dependencies(opencv_<name> [REQUIRED] [<list of dependencies>] [OPTIONAL <list of modules>])
58 # * <list of dependencies> - can include full names of modules or full pathes to shared/static libraries or cmake targets
59 macro(ocv_add_dependencies full_modname)
60 #we don't clean the dependencies here to allow this macro several times for every module
61 foreach(d "REQIRED" ${ARGN})
62 if(d STREQUAL "REQIRED")
63 set(__depsvar OPENCV_MODULE_${full_modname}_REQ_DEPS)
64 elseif(d STREQUAL "OPTIONAL")
65 set(__depsvar OPENCV_MODULE_${full_modname}_OPT_DEPS)
67 list(APPEND ${__depsvar} "${d}")
71 if(OPENCV_MODULE_${full_modname}_REQ_DEPS)
72 list(REMOVE_DUPLICATES OPENCV_MODULE_${full_modname}_REQ_DEPS)
74 if(OPENCV_MODULE_${full_modname}_OPT_DEPS)
75 list(REMOVE_DUPLICATES OPENCV_MODULE_${full_modname}_OPT_DEPS)
77 set(OPENCV_MODULE_${full_modname}_REQ_DEPS ${OPENCV_MODULE_${full_modname}_REQ_DEPS} CACHE INTERNAL "Required dependencies of ${full_modname} module")
78 set(OPENCV_MODULE_${full_modname}_OPT_DEPS ${OPENCV_MODULE_${full_modname}_OPT_DEPS} CACHE INTERNAL "Optional dependencies of ${full_modname} module")
83 # declare new OpenCV module in current folder
85 # ocv_add_module(<name> [INTERNAL|BINDINGS] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
87 # ocv_add_module(yaom INTERNAL opencv_core opencv_highgui NOLINK opencv_flann OPTIONAL opencv_gpu)
88 macro(ocv_add_module _name)
89 string(TOLOWER "${_name}" name)
90 string(REGEX REPLACE "^opencv_" "" ${name} "${name}")
91 set(the_module opencv_${name})
93 # the first pass - collect modules info, the second pass - create targets
94 if(OPENCV_INITIAL_PASS)
95 #remember module details
96 if(NOT DEFINED the_description)
97 set(the_description "The ${name} OpenCV module")
99 set(OPENCV_MODULE_${the_module}_DESCRIPTION "${the_description}" CACHE INTERNAL "Brief description of ${the_module} module")
100 set(OPENCV_MODULE_${the_module}_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Location of ${the_module} module sources")
102 #create option to enable/disable this module
103 option(BUILD_${the_module} "Include ${the_module} module into the OpenCV build" ON)
104 if(NOT BUILD_${the_module})
105 set(OPENCV_MODULES_DISABLED_USER ${OPENCV_MODULES_DISABLED_USER} "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
108 if("${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS")
109 set(__ocv_argn__ ${ARGN})
110 list(REMOVE_AT __ocv_argn__ 0)
111 ocv_add_dependencies(${the_module} ${__ocv_argn__})
114 ocv_add_dependencies(${the_module} ${ARGN})
115 set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export")
117 set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} "${the_module}" CACHE INTERNAL "List of OpenCV modules included into the build")
120 #TODO: add submodules if any
122 #stop processing of current file
124 else(OPENCV_INITIAL_PASS)
125 if(NOT BUILD_${the_module})
126 #extra protection from redefinition
129 project(${the_module})
130 endif(OPENCV_INITIAL_PASS)
133 # Internal macro; disables OpenCV module
134 # ocv_module_turn_off(<module name>)
135 macro(__ocv_module_turn_off the_module)
136 list(APPEND OPENCV_MODULES_DISABLED_AUTO "${the_module}")
137 list(REMOVE_ITEM OPENCV_MODULES_BUILD "${the_module}")
138 list(REMOVE_ITEM OPENCV_MODULES_PUBLIC "${the_module}")
139 set(HAVE_${the_module} OFF CACHE INTERNAL "Module ${the_module} can not be built in current configuration")
142 macro(ocv_module_disable module)
143 set(__modname ${module})
144 if(NOT __modname MATCHES "^opencv_")
145 set(__modname opencv_${module})
147 list(APPEND OPENCV_MODULES_DISABLED_FORCE "${__modname}")
148 set(HAVE_${__modname} OFF CACHE INTERNAL "Module ${__modname} can not be built in current configuration")
149 set(OPENCV_MODULES_DISABLED_FORCE "${OPENCV_MODULES_DISABLED_FORCE}" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration")
151 return()#leave the current folder
155 macro(__ocv_flatten_module_required_dependencies the_module)
156 set(__flattened_deps "")
157 set(__resolved_deps "")
158 set(__req_depends ${OPENCV_MODULE_${the_module}_REQ_DEPS})
161 list(GET __req_depends 0 __dep)
162 list(REMOVE_AT __req_depends 0)
163 if(__dep STREQUAL the_module)
164 #TODO: think how to deal with cyclic dependency
165 __ocv_module_turn_off(${the_module})
167 elseif("${OPENCV_MODULES_DISABLED_USER};${OPENCV_MODULES_DISABLED_AUTO}" MATCHES "(^|;)${__dep}(;|$)")
168 #depends on disabled module
169 __ocv_module_turn_off(${the_module})
171 elseif("${OPENCV_MODULES_BUILD}" MATCHES "(^|;)${__dep}(;|$)")
172 if(__resolved_deps MATCHES "(^|;)${__dep}(;|$)")
173 #all dependencies of this module are already resolved
174 list(APPEND __flattened_deps "${__dep}")
176 #put all required subdependencies before this dependency and mark it as resolved
177 list(APPEND __resolved_deps "${__dep}")
178 list(INSERT __req_depends 0 ${OPENCV_MODULE_${__dep}_REQ_DEPS} ${__dep})
180 elseif(__dep MATCHES "^opencv_")
181 #depends on missing module
182 __ocv_module_turn_off(${the_module})
190 list(REMOVE_DUPLICATES __flattened_deps)
191 set(OPENCV_MODULE_${the_module}_DEPS ${__flattened_deps})
193 set(OPENCV_MODULE_${the_module}_DEPS "")
196 unset(__resolved_deps)
197 unset(__flattened_deps)
202 macro(__ocv_flatten_module_optional_dependencies the_module)
203 set(__flattened_deps ${OPENCV_MODULE_${the_module}_DEPS})
204 set(__resolved_deps ${OPENCV_MODULE_${the_module}_DEPS})
205 set(__opt_depends ${OPENCV_MODULE_${the_module}_OPT_DEPS})
208 list(GET __opt_depends 0 __dep)
209 list(REMOVE_AT __opt_depends 0)
210 if(__dep STREQUAL the_module)
211 #TODO: think how to deal with cyclic dependency
212 __ocv_module_turn_off(${the_module})
214 elseif("${OPENCV_MODULES_BUILD}" MATCHES "(^|;)${__dep}(;|$)")
215 if(__resolved_deps MATCHES "(^|;)${__dep}(;|$)")
216 #all dependencies of this module are already resolved
217 list(APPEND __flattened_deps "${__dep}")
219 #put all subdependencies before this dependency and mark it as resolved
220 list(APPEND __resolved_deps "${__dep}")
221 list(INSERT __opt_depends 0 ${OPENCV_MODULE_${__dep}_REQ_DEPS} ${OPENCV_MODULE_${__dep}_OPT_DEPS} ${__dep})
224 #skip non-modules or missing modules
228 list(REMOVE_DUPLICATES __flattened_deps)
229 set(OPENCV_MODULE_${the_module}_DEPS ${__flattened_deps})
231 set(OPENCV_MODULE_${the_module}_DEPS "")
234 unset(__resolved_deps)
235 unset(__flattened_deps)
240 macro(__ocv_flatten_module_dependencies)
241 foreach(m ${OPENCV_MODULES_DISABLED_USER})
242 set(HAVE_${m} OFF CACHE INTERNAL "Module ${m} will not be built in current configuration")
244 foreach(m ${OPENCV_MODULES_BUILD})
245 set(HAVE_${m} ON CACHE INTERNAL "Module ${m} will not be built in current configuration")
246 __ocv_flatten_module_required_dependencies(${m})
249 foreach(m ${OPENCV_MODULES_BUILD})
250 __ocv_flatten_module_optional_dependencies(${m})
252 #dependencies from other modules
253 set(OPENCV_MODULE_${m}_DEPS ${OPENCV_MODULE_${m}_DEPS} CACHE INTERNAL "Flattened dependencies of ${m} module")
255 set(OPENCV_MODULE_${m}_DEPS_EXT ${OPENCV_MODULE_${m}_REQ_DEPS} ${OPENCV_MODULE_${m}_OPT_DEPS})
256 if(OPENCV_MODULE_${m}_DEPS_EXT AND OPENCV_MODULE_${m}_DEPS)
257 list(REMOVE_ITEM OPENCV_MODULE_${m}_DEPS_EXT ${OPENCV_MODULE_${m}_DEPS})
259 ocv_list_filterout(OPENCV_MODULE_${m}_DEPS_EXT "^opencv_[^ ]+$")
260 set(OPENCV_MODULE_${m}_DEPS_EXT ${OPENCV_MODULE_${m}_DEPS_EXT} CACHE INTERNAL "Extra dependencies of ${m} module")
263 set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} CACHE INTERNAL "List of OpenCV modules marked for export")
264 set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} CACHE INTERNAL "List of OpenCV modules included into the build")
265 set(OPENCV_MODULES_DISABLED_AUTO ${OPENCV_MODULES_DISABLED_AUTO} CACHE INTERNAL "List of OpenCV modules implicitly disabled due to dependencies")
268 # collect modules from specified directories
269 # NB: must be called only once!
270 macro(ocv_glob_modules)
272 set(OPENCV_INITIAL_PASS ON)
273 foreach(__path ${ARGN})
274 file(GLOB __ocvmodules RELATIVE "${__path}" "${__path}/*")
276 list(SORT __ocvmodules)
277 foreach(mod ${__ocvmodules})
278 if(EXISTS "${__path}/${mod}/CMakeLists.txt")
279 add_subdirectory("${__path}/${mod}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
286 #resolve dependencies
287 __ocv_flatten_module_dependencies()
289 #order modules by dependencies
290 set(OPENCV_MODULES_BUILD_ "")
291 foreach(m ${OPENCV_MODULES_BUILD})
292 list(APPEND OPENCV_MODULES_BUILD_ ${OPENCV_MODULE_${m}_DEPS} ${m})
294 ocv_list_unique(OPENCV_MODULES_BUILD_)
297 set(OPENCV_INITIAL_PASS OFF)
298 foreach(m ${OPENCV_MODULES_BUILD_})
299 if(m MATCHES "^opencv_")
300 string(REGEX REPLACE "^opencv_" "" __shortname "${m}")
301 add_subdirectory("${OPENCV_MODULE_${m}_LOCATION}" "${CMAKE_CURRENT_BINARY_DIR}/${__shortname}")
307 # setup include paths for the list of passed modules
308 macro(ocv_include_modules)
310 if(d MATCHES "^opencv_" AND HAVE_${d})
311 if (EXISTS "${OPENCV_MODULE_${d}_LOCATION}/include")
312 include_directories("${OPENCV_MODULE_${d}_LOCATION}/include")
314 elseif(EXISTS "${d}")
315 include_directories("${d}")
320 # setup include path for OpenCV headers for specified module
321 # ocv_module_include_directories(<extra include directories/extra include modules>)
322 macro(ocv_module_include_directories)
323 include_directories("${OPENCV_MODULE_${the_module}_LOCATION}/include"
324 "${OPENCV_MODULE_${the_module}_LOCATION}/src"
325 "${CMAKE_CURRENT_BINARY_DIR}"#for precompiled headers
327 ocv_include_modules(${OPENCV_MODULE_${the_module}_DEPS} ${ARGN})
331 # sets header and source files for the current module
332 # NB: all files specified as headers will be installed
334 # ocv_set_module_sources([HEADERS] <list of files> [SOURCES] <list of files>)
335 macro(ocv_set_module_sources)
336 set(OPENCV_MODULE_${the_module}_HEADERS "")
337 set(OPENCV_MODULE_${the_module}_SOURCES "")
339 foreach(f "HEADERS" ${ARGN})
340 if(f STREQUAL "HEADERS" OR f STREQUAL "SOURCES")
341 set(__filesvar "OPENCV_MODULE_${the_module}_${f}")
343 list(APPEND ${__filesvar} "${f}")
347 # the hacky way to embeed any files into the OpenCV without modification of its build system
348 if(COMMAND ocv_get_module_external_sources)
349 ocv_get_module_external_sources()
352 set(OPENCV_MODULE_${the_module}_HEADERS ${OPENCV_MODULE_${the_module}_HEADERS} CACHE INTERNAL "List of header files for ${the_module}")
353 set(OPENCV_MODULE_${the_module}_SOURCES ${OPENCV_MODULE_${the_module}_SOURCES} CACHE INTERNAL "List of source files for ${the_module}")
356 # finds and sets headers and sources for the standard OpenCV module
358 # ocv_glob_module_sources(<extra sources&headers in the same format as used in ocv_set_module_sources>)
359 macro(ocv_glob_module_sources)
360 file(GLOB lib_srcs "src/*.cpp")
361 file(GLOB lib_int_hdrs "src/*.hpp" "src/*.h")
362 file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
363 file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h")
365 source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
366 source_group("Include" FILES ${lib_hdrs})
367 source_group("Include\\detail" FILES ${lib_hdrs_detail})
369 ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} SOURCES ${lib_srcs} ${lib_int_hdrs})
372 # creates OpenCV module in current folder
373 # creates new target, configures standard dependencies, compilers flags, install rules
375 # ocv_create_module(<extra link dependencies>)
376 macro(ocv_create_module)
377 add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES})
378 target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
380 if(ENABLE_SOLUTION_FOLDERS)
381 set_target_properties(${the_module} PROPERTIES FOLDER "modules")
384 set_target_properties(${the_module} PROPERTIES
385 OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}"
386 DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
387 ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
388 RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
392 # For dynamic link numbering convenions
394 # Android SDK build scripts can include only .so files into final .apk
395 # As result we should not set version properties for Android
396 set_target_properties(${the_module} PROPERTIES
397 VERSION ${OPENCV_VERSION}
398 SOVERSION ${OPENCV_SOVERSION}
402 if(BUILD_SHARED_LIBS)
404 set_target_properties(${the_module} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
406 add_definitions(-DCVAPI_EXPORTS)
411 if(CMAKE_CROSSCOMPILING)
412 set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk")
414 set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG")
417 install(TARGETS ${the_module}
418 RUNTIME DESTINATION bin COMPONENT main
419 LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
420 ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
424 # only "public" headers need to be installed
425 if(OPENCV_MODULE_${the_module}_HEADERS AND OPENCV_MODULES_PUBLIC MATCHES "(^|;)${the_module}(;|$)")
426 install(FILES ${OPENCV_MODULE_${the_module}_HEADERS}
427 DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name} COMPONENT main)
431 # opencv precompiled headers macro (can add pch to modules and tests)
432 # this macro must be called after any "add_definitions" commands, otherwise precompiled headers will not work
434 # ocv_add_precompiled_headers(${the_module})
435 macro(ocv_add_precompiled_headers the_target)
436 if("${the_target}" MATCHES "^opencv_test_.*$")
437 SET(pch_path "test/test_")
438 elseif("${the_target}" MATCHES "^opencv_perf_.*$")
439 SET(pch_path "perf/perf_")
443 set(pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.hpp")
445 if(PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS AND EXISTS "${pch_header}")
446 if(CMAKE_GENERATOR MATCHES Visual)
447 set(${the_target}_pch "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.cpp")
448 add_native_precompiled_header(${the_target} ${pch_header})
449 elseif(CMAKE_GENERATOR MATCHES Xcode)
450 add_native_precompiled_header(${the_target} ${pch_header})
451 elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GENERATOR MATCHES Makefiles)
452 add_precompiled_header(${the_target} ${pch_header})
457 unset(${the_target}_pch)
460 # short command for adding simple OpenCV module
461 # see ocv_add_module for argument details
463 # ocv_define_module(module_name [INTERNAL] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
464 macro(ocv_define_module module_name)
465 ocv_add_module(${module_name} ${ARGN})
466 ocv_glob_module_sources()
467 ocv_module_include_directories()
469 ocv_add_precompiled_headers(${the_module})
471 ocv_add_accuracy_tests()
475 # ensures that all passed modules are available
476 # sets OCV_DEPENDENCIES_FOUND variable to TRUE/FALSE
477 macro(ocv_check_dependencies)
478 set(OCV_DEPENDENCIES_FOUND TRUE)
480 if(d MATCHES "^opencv_[^ ]+$" AND NOT HAVE_${d})
481 set(OCV_DEPENDENCIES_FOUND FALSE)
487 #auxiliary macro to parse arguments of ocv_add_accuracy_tests and ocv_add_perf_tests commands
488 macro(__ocv_parse_test_sources tests_type)
489 set(OPENCV_${tests_type}_${the_module}_SOURCES "")
490 set(OPENCV_${tests_type}_${the_module}_DEPS "")
491 set(__file_group_name "")
492 set(__file_group_sources "")
493 foreach(arg "DEPENDS_ON" ${ARGN} "FILES")
494 if(arg STREQUAL "FILES")
495 set(__currentvar "__file_group_sources")
496 if(__file_group_name AND __file_group_sources)
497 source_group("${__file_group_name}" FILES ${__file_group_sources})
498 list(APPEND OPENCV_${tests_type}_${the_module}_SOURCES ${__file_group_sources})
500 set(__file_group_name "")
501 set(__file_group_sources "")
502 elseif(arg STREQUAL "DEPENDS_ON")
503 set(__currentvar "OPENCV_TEST_${the_module}_DEPS")
504 elseif("${__currentvar}" STREQUAL "__file_group_sources" AND NOT __file_group_name)
505 set(__file_group_name "${arg}")
507 list(APPEND ${__currentvar} "${arg}")
510 unset(__file_group_name)
511 unset(__file_group_sources)
515 # this is a command for adding OpenCV performance tests to the module
516 # ocv_add_perf_tests(<extra_dependencies>)
517 macro(ocv_add_perf_tests)
518 set(perf_path "${CMAKE_CURRENT_SOURCE_DIR}/perf")
519 if(BUILD_PERF_TESTS AND EXISTS "${perf_path}")
520 __ocv_parse_test_sources(PERF ${ARGN})
522 # opencv_highgui is required for imread/imwrite
523 set(perf_deps ${the_module} opencv_ts opencv_highgui ${OPENCV_PERF_${the_module}_DEPS})
524 ocv_check_dependencies(${perf_deps})
526 if(OCV_DEPENDENCIES_FOUND)
527 set(the_target "opencv_perf_${name}")
528 #project(${the_target})
530 ocv_module_include_directories(${perf_deps} "${perf_path}")
532 if(NOT OPENCV_PERF_${the_module}_SOURCES)
533 file(GLOB perf_srcs "${perf_path}/*.cpp")
534 file(GLOB perf_hdrs "${perf_path}/*.hpp" "${perf_path}/*.h")
535 source_group("Src" FILES ${perf_srcs})
536 source_group("Include" FILES ${perf_hdrs})
537 set(OPENCV_PERF_${the_module}_SOURCES ${perf_srcs} ${perf_hdrs})
540 add_executable(${the_target} ${OPENCV_PERF_${the_module}_SOURCES})
541 target_link_libraries(${the_target} ${OPENCV_MODULE_${the_module}_DEPS} ${perf_deps} ${OPENCV_LINKER_LIBS})
543 # Additional target properties
544 set_target_properties(${the_target} PROPERTIES
545 DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
546 RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
549 if(ENABLE_SOLUTION_FOLDERS)
550 set_target_properties(${the_target} PROPERTIES FOLDER "tests performance")
553 ocv_add_precompiled_headers(${the_target})
555 if (PYTHON_EXECUTABLE)
556 add_dependencies(perf ${the_target})
558 else(OCV_DEPENDENCIES_FOUND)
559 #TODO: warn about unsatisfied dependencies
560 endif(OCV_DEPENDENCIES_FOUND)
564 # this is a command for adding OpenCV accuracy/regression tests to the module
565 # ocv_add_accuracy_tests([FILES <source group name> <list of sources>] [DEPENDS_ON] <list of extra dependencies>)
566 macro(ocv_add_accuracy_tests)
567 set(test_path "${CMAKE_CURRENT_SOURCE_DIR}/test")
568 ocv_check_dependencies(${test_deps})
569 if(BUILD_TESTS AND EXISTS "${test_path}")
570 __ocv_parse_test_sources(TEST ${ARGN})
572 # opencv_highgui is required for imread/imwrite
573 set(test_deps ${the_module} opencv_ts opencv_highgui ${OPENCV_TEST_${the_module}_DEPS})
574 ocv_check_dependencies(${test_deps})
576 if(OCV_DEPENDENCIES_FOUND)
577 set(the_target "opencv_test_${name}")
578 #project(${the_target})
580 ocv_module_include_directories(${test_deps} "${test_path}")
582 if(NOT OPENCV_TEST_${the_module}_SOURCES)
583 file(GLOB test_srcs "${test_path}/*.cpp")
584 file(GLOB test_hdrs "${test_path}/*.hpp" "${test_path}/*.h")
585 source_group("Src" FILES ${test_srcs})
586 source_group("Include" FILES ${test_hdrs})
587 set(OPENCV_TEST_${the_module}_SOURCES ${test_srcs} ${test_hdrs})
590 add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES})
591 target_link_libraries(${the_target} ${OPENCV_MODULE_${the_module}_DEPS} ${test_deps} ${OPENCV_LINKER_LIBS})
593 # Additional target properties
594 set_target_properties(${the_target} PROPERTIES
595 DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
596 RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
599 if(ENABLE_SOLUTION_FOLDERS)
600 set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy")
604 get_target_property(LOC ${the_target} LOCATION)
605 add_test(${the_target} "${LOC}")
607 ocv_add_precompiled_headers(${the_target})
608 else(OCV_DEPENDENCIES_FOUND)
609 #TODO: warn about unsatisfied dependencies
610 endif(OCV_DEPENDENCIES_FOUND)
614 # internal macro; finds all link dependencies of module
615 # should be used at the end of CMake processing
616 macro(__ocv_track_module_link_dependencies the_module optkind)
617 set(${the_module}_MODULE_DEPS_${optkind} "")
618 set(${the_module}_EXTRA_DEPS_${optkind} "")
620 get_target_property(__module_type ${the_module} TYPE)
621 if(__module_type STREQUAL "STATIC_LIBRARY")
622 #in case of static library we have to inherit its dependencies (in right order!!!)
623 if(NOT DEFINED ${the_module}_LIB_DEPENDS_${optkind})
624 ocv_split_libs_list(${the_module}_LIB_DEPENDS ${the_module}_LIB_DEPENDS_DBG ${the_module}_LIB_DEPENDS_OPT)
627 set(__resolved_deps "")
628 set(__mod_depends ${${the_module}_LIB_DEPENDS_${optkind}})
629 set(__has_cycle FALSE)
632 list(GET __mod_depends 0 __dep)
633 list(REMOVE_AT __mod_depends 0)
634 if(__dep STREQUAL the_module)
635 set(__has_cycle TRUE)
636 else()#if("${OPENCV_MODULES_BUILD}" MATCHES "(^|;)${__dep}(;|$)")
637 ocv_regex_escape(__rdep "${__dep}")
638 if(__resolved_deps MATCHES "(^|;)${__rdep}(;|$)")
639 #all dependencies of this module are already resolved
640 list(APPEND ${the_module}_MODULE_DEPS_${optkind} "${__dep}")
642 get_target_property(__module_type ${__dep} TYPE)
643 if(__module_type STREQUAL "STATIC_LIBRARY")
644 if(NOT DEFINED ${__dep}_LIB_DEPENDS_${optkind})
645 ocv_split_libs_list(${__dep}_LIB_DEPENDS ${__dep}_LIB_DEPENDS_DBG ${__dep}_LIB_DEPENDS_OPT)
647 list(INSERT __mod_depends 0 ${${__dep}_LIB_DEPENDS_${optkind}} ${__dep})
648 list(APPEND __resolved_deps "${__dep}")
649 elseif(NOT __module_type)
650 list(APPEND ${the_module}_EXTRA_DEPS_${optkind} "${__dep}")
654 # get_target_property(__dep_location "${__dep}" LOCATION)
658 ocv_list_unique(${the_module}_MODULE_DEPS_${optkind})
659 #ocv_list_reverse(${the_module}_MODULE_DEPS_${optkind})
660 ocv_list_unique(${the_module}_EXTRA_DEPS_${optkind})
661 #ocv_list_reverse(${the_module}_EXTRA_DEPS_${optkind})
664 #not sure if it can work
665 list(APPEND ${the_module}_MODULE_DEPS_${optkind} "${the_module}")
668 unset(__dep_location)
670 unset(__resolved_deps)
673 endif()#STATIC_LIBRARY
676 #message("${the_module}_MODULE_DEPS_${optkind}")
677 #message(" ${${the_module}_MODULE_DEPS_${optkind}}")
678 #message(" ${OPENCV_MODULE_${the_module}_DEPS}")
680 #message("${the_module}_EXTRA_DEPS_${optkind}")
681 #message(" ${${the_module}_EXTRA_DEPS_${optkind}}")
685 # creates lists of build dependencies needed for external projects
686 macro(ocv_track_build_dependencies)
687 foreach(m ${OPENCV_MODULES_BUILD})
688 __ocv_track_module_link_dependencies("${m}" OPT)
689 __ocv_track_module_link_dependencies("${m}" DBG)