@ -92,6 +92,14 @@ macro(ocv_add_module _name)
# t h e f i r s t p a s s - c o l l e c t m o d u l e s i n f o , t h e s e c o n d p a s s - c r e a t e t a r g e t s
if ( OPENCV_INITIAL_PASS )
# g u a r d a g a i n s r e d e f i n i t i o n
if ( ";${OPENCV_MODULES_BUILD};${OPENCV_MODULES_DISABLED_USER};" MATCHES ";${the_module};" )
message ( FATAL_ERROR " Redefinition of the ${ the_module } module.
a t : $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
p r e v i o u s l y d e f i n e d a t : $ { O P E N C V _ M O D U L E _ $ { t h e _ m o d u l e } _ L O C A T I O N }
" )
endif ( )
# r e m e m b e r m o d u l e d e t a i l s
if ( NOT DEFINED the_description )
set ( the_description "The ${name} OpenCV module" )
@ -103,20 +111,23 @@ macro(ocv_add_module _name)
# c r e a t e o p t i o n t o e n a b l e / d i s a b l e t h i s m o d u l e
option ( BUILD_ ${ the_module } "Include ${the_module} module into the OpenCV build" ON )
if ( NOT BUILD_ ${ the_module } )
set ( OPENCV_MODULES_DISABLED_USER ${ OPENCV_MODULES_DISABLED_USER } "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user" )
if ( "${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS" )
set ( __ocv_argn__ ${ ARGN } )
list ( REMOVE_AT __ocv_argn__ 0 )
ocv_add_dependencies ( ${ the_module } ${ __ocv_argn__ } )
unset ( __ocv_argn__ )
else ( )
# r e g i s t e r n e w m o d u l e
if ( "${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS" )
set ( __ocv_argn__ ${ ARGN } )
list ( REMOVE_AT __ocv_argn__ 0 )
ocv_add_dependencies ( ${ the_module } ${ __ocv_argn__ } )
unset ( __ocv_argn__ )
else ( )
ocv_add_dependencies ( ${ the_module } ${ ARGN } )
ocv_add_dependencies ( ${ the_module } ${ ARGN } )
if ( BUILD_ ${ the_module } )
set ( OPENCV_MODULES_PUBLIC ${ OPENCV_MODULES_PUBLIC } "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export" )
endif ( )
endif ( )
if ( BUILD_ ${ the_module } )
set ( OPENCV_MODULES_BUILD ${ OPENCV_MODULES_BUILD } "${the_module}" CACHE INTERNAL "List of OpenCV modules included into the build" )
else ( )
set ( OPENCV_MODULES_DISABLED_USER ${ OPENCV_MODULES_DISABLED_USER } "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user" )
endif ( )
# T O D O : a d d s u b m o d u l e s i f a n y
@ -148,6 +159,7 @@ macro(ocv_module_disable module)
endif ( )
list ( APPEND OPENCV_MODULES_DISABLED_FORCE "${__modname}" )
set ( HAVE_ ${ __modname } OFF CACHE INTERNAL "Module ${__modname} can not be built in current configuration" )
set ( OPENCV_MODULE_ ${ __modname } _LOCATION "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Location of ${__modname} module sources" )
set ( OPENCV_MODULES_DISABLED_FORCE "${OPENCV_MODULES_DISABLED_FORCE}" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration" )
unset ( __modname )
return ( ) # l e a v e t h e c u r r e n t f o l d e r
@ -270,25 +282,43 @@ endmacro()
# c o l l e c t m o d u l e s f r o m s p e c i f i e d d i r e c t o r i e s
# N B : m u s t b e c a l l e d o n l y o n c e !
macro ( ocv_glob_modules )
if ( DEFINED OPENCV_INITIAL_PASS )
message ( FATAL_ERROR "OpenCV has already loaded its modules. Calling ocv_glob_modules second time is not allowed." )
endif ( )
set ( __directories_observed "" )
# c o l l e c t m o d u l e s
set ( OPENCV_INITIAL_PASS ON )
foreach ( __path ${ ARGN } )
ocv_get_real_path ( __path "${__path}" )
list ( FIND __directories_observed "${__path}" __pathIdx )
if ( __pathIdx GREATER -1 )
message ( FATAL_ERROR "The directory ${__path} is observed for OpenCV modules second time." )
endif ( )
list ( APPEND __directories_observed "${__path}" )
file ( GLOB __ocvmodules RELATIVE "${__path}" "${__path}/*" )
if ( __ocvmodules )
list ( SORT __ocvmodules )
foreach ( mod ${ __ocvmodules } )
if ( CMAKE_VERSION VERSION_LESS 2.8 )
get_filename_component ( __realpath "${__path}/${mod}" ABSOLUTE )
else ( )
get_filename_component ( __realpath "${__path}/${mod}" REALPATH )
endif ( )
if ( EXISTS "${__realpath}/CMakeLists.txt" AND NOT __realpath STREQUAL CMAKE_CURRENT_SOURCE_DIR )
add_subdirectory ( "${__path}/${mod}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}" )
ocv_get_real_path ( __modpath "${__path}/${mod}" )
if ( EXISTS "${__modpath}/CMakeLists.txt" )
list ( FIND __directories_observed "${__modpath}" __pathIdx )
if ( __pathIdx GREATER -1 )
message ( FATAL_ERROR "The module from ${__modpath} is already loaded." )
endif ( )
list ( APPEND __directories_observed "${__modpath}" )
add_subdirectory ( "${__modpath}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}" )
endif ( )
endforeach ( )
endif ( )
endforeach ( )
unset ( __ocvmodules )
unset ( __directories_observed )
unset ( __path )
unset ( __modpath )
unset ( __pathIdx )
# r e s o l v e d e p e n d e n c i e s
__ocv_flatten_module_dependencies ( )
@ -301,6 +331,7 @@ macro(ocv_glob_modules)
ocv_list_unique ( OPENCV_MODULES_BUILD_ )
# c r e a t e m o d u l e s
set ( OPENCV_INITIAL_PASS OFF PARENT_SCOPE )
set ( OPENCV_INITIAL_PASS OFF )
foreach ( m ${ OPENCV_MODULES_BUILD_ } )
if ( m MATCHES "^opencv_" )