Support for compound modules, support for contrib_world

This commit is contained in:
Maksim Shabunin
2015-01-19 18:03:29 +03:00
parent 5466e321b8
commit a5a510da4b
9 changed files with 139 additions and 50 deletions

View File

@@ -19,6 +19,8 @@
# OPENCV_MODULE_${the_module}_PRIVATE_REQ_DEPS
# OPENCV_MODULE_${the_module}_PRIVATE_OPT_DEPS
# OPENCV_MODULE_${the_module}_IS_PART_OF_WORLD
# OPENCV_MODULE_${the_module}_CUDA_OBJECTS - compiled CUDA objects list
# OPENCV_MODULE_${the_module}_CHILDREN - list of submodules for compound modules
# HAVE_${the_module} - for fast check of module availability
# To control the setup of the module you could also set:
@@ -26,6 +28,7 @@
# OPENCV_MODULE_TYPE - STATIC|SHARED - set to force override global settings for current module
# OPENCV_MODULE_IS_PART_OF_WORLD - ON|OFF (default ON) - should the module be added to the opencv_world?
# BUILD_${the_module}_INIT - ON|OFF (default ON) - initial value for BUILD_${the_module}
# OPENCV_MODULE_CHILDREN - list of submodules
# The verbose template for OpenCV module:
#
@@ -158,13 +161,9 @@ macro(ocv_add_module _name)
endif()
# add self to the world dependencies
# add to world only extra modules (ON) or only main modules (OFF)
set(__expected_extra 0)
if (OPENCV_EXTRA_WORLD)
set(__expected_extra 1)
endif()
if((NOT DEFINED OPENCV_MODULE_IS_PART_OF_WORLD AND NOT OPENCV_MODULE_${the_module}_CLASS STREQUAL "BINDINGS"
AND __expected_extra EQUAL OPENCV_PROCESSING_EXTRA_MODULES)
if((NOT DEFINED OPENCV_MODULE_IS_PART_OF_WORLD
AND NOT OPENCV_MODULE_${the_module}_CLASS STREQUAL "BINDINGS"
AND NOT OPENCV_PROCESSING_EXTRA_MODULES)
OR OPENCV_MODULE_IS_PART_OF_WORLD
)
set(OPENCV_MODULE_${the_module}_IS_PART_OF_WORLD ON CACHE INTERNAL "")
@@ -179,7 +178,8 @@ macro(ocv_add_module _name)
set(OPENCV_MODULES_DISABLED_USER ${OPENCV_MODULES_DISABLED_USER} "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
endif()
# TODO: add submodules if any
# add submodules if any
set(OPENCV_MODULE_${the_module}_CHILDREN "${OPENCV_MODULE_CHILDREN}" CACHE INTERNAL "List of ${the_module} submodules")
# stop processing of current file
return()
@@ -306,27 +306,42 @@ endfunction()
# sort modules by dependencies
function(__ocv_sort_modules_by_deps __lst)
ocv_list_sort(${__lst})
set(${__lst}_ORDERED ${${__lst}} CACHE INTERNAL "")
set(__result "")
foreach (m ${${__lst}})
list(LENGTH __result __lastindex)
set(__index ${__lastindex})
foreach (__d ${__result})
set(__deps "${OPENCV_MODULE_${__d}_DEPS}")
if(";${__deps};" MATCHES ";${m};")
list(FIND __result "${__d}" __i)
if(__i LESS "${__index}")
set(__index "${__i}")
set(input ${${__lst}})
set(result "")
while(input)
list(LENGTH input length_before)
foreach (m ${input})
# check if module is in the result already
if (NOT ";${result};" MATCHES ";${m};")
# scan through module dependencies...
set(unresolved_deps_found FALSE)
foreach (d ${OPENCV_MODULE_${m}_CHILDREN} ${OPENCV_MODULE_${m}_DEPS})
# ... which are not already in the result and are enabled
if ((NOT ";${result};" MATCHES ";${d};") AND HAVE_${d})
set(unresolved_deps_found TRUE)
break()
endif()
endforeach()
# chek if all dependencies for this module has been resolved
if (NOT unresolved_deps_found)
list(APPEND result ${m})
list(REMOVE_ITEM input ${m})
endif()
endif()
endforeach()
if(__index STREQUAL __lastindex)
list(APPEND __result "${m}")
else()
list(INSERT __result ${__index} "${m}")
list(LENGTH input length_after)
# check for infinite loop or unresolved dependencies
if (NOT length_after LESS length_before)
message(WARNING "Unresolved dependencies or loop in dependency graph (${length_after})\n"
"Processed ${__lst}: ${${__lst}}\n"
"Good modules: ${result}\n"
"Bad modules: ${input}"
)
list(APPEND result ${input})
break()
endif()
endforeach()
set(${__lst} "${__result}" PARENT_SCOPE)
endwhile()
set(${__lst} "${result}" PARENT_SCOPE)
endfunction()
# resolve dependensies
@@ -645,9 +660,43 @@ macro(_ocv_create_module)
get_native_precompiled_header(${the_module} precomp.hpp)
endif()
set(sub_objs "")
set(sub_links "")
set(cuda_objs "")
if (DEFINED OPENCV_MODULE_${the_module}_CHILDREN)
status("Complex module ${the_module}")
foreach (m ${OPENCV_MODULE_${the_module}_CHILDREN})
if (BUILD_${m} AND TARGET ${m}_object) # ambigous?
get_target_property(_sub_links ${m} LINK_LIBRARIES)
list(APPEND sub_objs $<TARGET_OBJECTS:${m}_object>)
list(APPEND sub_links ${_sub_links})
status(" + ${m}")
else()
status(" - ${m}")
endif()
list(APPEND cuda_objs ${OPENCV_MODULE_${m}_CUDA_OBJECTS})
endforeach()
endif()
ocv_add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES}
"${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp"
${${the_module}_pch})
${${the_module}_pch} ${sub_objs})
if (cuda_objs)
target_link_libraries(${the_module} ${cuda_objs})
endif()
# TODO: is it needed?
if (sub_links)
ocv_list_filterout(sub_links "^opencv_")
ocv_list_unique(sub_links)
target_link_libraries(${the_module} ${sub_links})
endif()
unset(sub_objs)
unset(sub_links)
unset(cuda_objs)
if(NOT the_module STREQUAL opencv_ts)
set_target_properties(${the_module} PROPERTIES COMPILE_DEFINITIONS OPENCV_NOSTL)
endif()
@@ -686,6 +735,7 @@ macro(_ocv_create_module)
if((NOT DEFINED OPENCV_MODULE_TYPE AND BUILD_SHARED_LIBS)
OR (DEFINED OPENCV_MODULE_TYPE AND OPENCV_MODULE_TYPE STREQUAL SHARED))
set_target_properties(${the_module} PROPERTIES COMPILE_DEFINITIONS CVAPI_EXPORTS)
set_target_properties(${the_module} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
endif()
@@ -696,22 +746,35 @@ macro(_ocv_create_module)
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG")
endif()
ocv_install_target(${the_module} EXPORT OpenCVModules
ocv_install_target(${the_module} EXPORT OpenCVModules OPTIONAL
RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs
LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs
ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT dev
)
# only "public" headers need to be installed
if(OPENCV_MODULE_${the_module}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${the_module};")
foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
if(NOT hdr2 MATCHES "opencv2/${the_module}/private.*" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev)
endif()
endforeach()
endif()
foreach(m ${OPENCV_MODULE_${the_module}_CHILDREN} ${the_module})
# only "public" headers need to be installed
if(OPENCV_MODULE_${m}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${m};")
foreach(hdr ${OPENCV_MODULE_${m}_HEADERS})
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
if(NOT hdr2 MATCHES "opencv2/${m}/private.*" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
install(FILES ${hdr} OPTIONAL DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev)
endif()
endforeach()
endif()
endforeach()
_ocv_add_precompiled_headers(${the_module})
if (TARGET ${the_module}_object)
# copy COMPILE_DEFINITIONS
get_target_property(main_defs ${the_module} COMPILE_DEFINITIONS)
set_target_properties(${the_module}_object PROPERTIES COMPILE_DEFINITIONS ${main_defs})
# use same PCH
if (TARGET pch_Generate_${the_module})
add_dependencies(${the_module}_object pch_Generate_${the_module} )
endif()
endif()
endmacro()
# opencv precompiled headers macro (can add pch to modules and tests)