mirror of
https://github.com/opencv/opencv.git
synced 2025-06-19 08:54:45 +08:00
cmake: move Matlab scripts to opencv_contrib (#12541)
* matlab: move to opencv_contrib * cmake: preserve variables scope for processing modules - use macro instead of function to avoid scope resets
This commit is contained in:
parent
3512cb2226
commit
29bee6f07e
@ -271,7 +271,6 @@ OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON
|
|||||||
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
|
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
|
||||||
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF (WIN32 AND NOT WINRT) )
|
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF (WIN32 AND NOT WINRT) )
|
||||||
OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF (WIN32 AND NOT WINRT) )
|
OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF (WIN32 AND NOT WINRT) )
|
||||||
OCV_OPTION(WITH_MATLAB "Include Matlab support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT))
|
|
||||||
OCV_OPTION(WITH_VA "Include VA support" OFF IF (UNIX AND NOT ANDROID) )
|
OCV_OPTION(WITH_VA "Include VA support" OFF IF (UNIX AND NOT ANDROID) )
|
||||||
OCV_OPTION(WITH_VA_INTEL "Include Intel VA-API/OpenCL support" OFF IF (UNIX AND NOT ANDROID) )
|
OCV_OPTION(WITH_VA_INTEL "Include Intel VA-API/OpenCL support" OFF IF (UNIX AND NOT ANDROID) )
|
||||||
OCV_OPTION(WITH_MFX "Include Intel Media SDK support" OFF IF ((UNIX AND NOT ANDROID) OR (WIN32 AND NOT WINRT AND NOT MINGW)) )
|
OCV_OPTION(WITH_MFX "Include Intel Media SDK support" OFF IF ((UNIX AND NOT ANDROID) OR (WIN32 AND NOT WINRT AND NOT MINGW)) )
|
||||||
@ -693,11 +692,6 @@ if(WITH_DIRECTX)
|
|||||||
include(cmake/OpenCVDetectDirectX.cmake)
|
include(cmake/OpenCVDetectDirectX.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# --- Matlab/Octave ---
|
|
||||||
if(WITH_MATLAB)
|
|
||||||
include(cmake/OpenCVFindMatlab.cmake)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(WITH_VTK)
|
if(WITH_VTK)
|
||||||
include(cmake/OpenCVDetectVTK.cmake)
|
include(cmake/OpenCVDetectVTK.cmake)
|
||||||
endif()
|
endif()
|
||||||
@ -1516,15 +1510,7 @@ if(BUILD_JAVA OR BUILD_opencv_java)
|
|||||||
status(" Java tests:" BUILD_TESTS AND opencv_test_java_BINARY_DIR THEN YES ELSE NO)
|
status(" Java tests:" BUILD_TESTS AND opencv_test_java_BINARY_DIR THEN YES ELSE NO)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ========================= matlab =========================
|
ocv_cmake_hook(STATUS_DUMP_EXTRA)
|
||||||
if(WITH_MATLAB OR MATLAB_FOUND)
|
|
||||||
status("")
|
|
||||||
status(" Matlab:" MATLAB_FOUND THEN "YES" ELSE "NO")
|
|
||||||
if(MATLAB_FOUND)
|
|
||||||
status(" mex:" MATLAB_MEX_SCRIPT THEN "${MATLAB_MEX_SCRIPT}" ELSE NO)
|
|
||||||
status(" Compiler/generator:" MEX_WORKS THEN "Working" ELSE "Not working (bindings will not be generated)")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ========================== auxiliary ==========================
|
# ========================== auxiliary ==========================
|
||||||
status("")
|
status("")
|
||||||
|
@ -1,199 +0,0 @@
|
|||||||
# ----- Find Matlab/Octave -----
|
|
||||||
#
|
|
||||||
# OpenCVFindMatlab.cmake attempts to locate the install path of Matlab in order
|
|
||||||
# to extract the mex headers, libraries and shell scripts. If found
|
|
||||||
# successfully, the following variables will be defined
|
|
||||||
#
|
|
||||||
# MATLAB_FOUND: true/false
|
|
||||||
# MATLAB_ROOT_DIR: Root of Matlab installation
|
|
||||||
# MATLAB_BIN: The main Matlab "executable" (shell script)
|
|
||||||
# MATLAB_MEX_SCRIPT: The mex script used to compile mex files
|
|
||||||
# MATLAB_INCLUDE_DIRS:Path to "mex.h"
|
|
||||||
# MATLAB_LIBRARY_DIRS:Path to mex and matrix libraries
|
|
||||||
# MATLAB_LIBRARIES: The Matlab libs, usually mx, mex, mat
|
|
||||||
# MATLAB_MEXEXT: The mex library extension. It will be one of:
|
|
||||||
# mexwin32, mexwin64, mexglx, mexa64, mexmac,
|
|
||||||
# mexmaci, mexmaci64, mexsol, mexs64
|
|
||||||
# MATLAB_ARCH: The installation architecture. It is **usually**
|
|
||||||
# the MEXEXT with the preceding "mex" removed,
|
|
||||||
# though it's different for linux distros.
|
|
||||||
#
|
|
||||||
# There doesn't appear to be an elegant way to detect all versions of Matlab
|
|
||||||
# across different platforms. If you know the matlab path and want to avoid
|
|
||||||
# the search, you can define the path to the Matlab root when invoking cmake:
|
|
||||||
#
|
|
||||||
# cmake -DMATLAB_ROOT_DIR='/PATH/TO/ROOT_DIR' ..
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----- set_library_presuffix -----
|
|
||||||
#
|
|
||||||
# Matlab tends to use some non-standard prefixes and suffixes on its libraries.
|
|
||||||
# For example, libmx.dll on Windows (Windows does not add prefixes) and
|
|
||||||
# mkl.dylib on OS X (OS X uses "lib" prefixes).
|
|
||||||
# On some versions of Windows the .dll suffix also appears to not be checked.
|
|
||||||
#
|
|
||||||
# This function modifies the library prefixes and suffixes used by
|
|
||||||
# find_library when finding Matlab libraries. It does not affect scopes
|
|
||||||
# outside of this file.
|
|
||||||
function(set_libarch_prefix_suffix)
|
|
||||||
if (UNIX AND NOT APPLE)
|
|
||||||
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" PARENT_SCOPE)
|
|
||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a" PARENT_SCOPE)
|
|
||||||
elseif (APPLE)
|
|
||||||
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" PARENT_SCOPE)
|
|
||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".a" PARENT_SCOPE)
|
|
||||||
elseif (WIN32)
|
|
||||||
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" PARENT_SCOPE)
|
|
||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll" PARENT_SCOPE)
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----- locate_matlab_root -----
|
|
||||||
#
|
|
||||||
# Attempt to find the path to the Matlab installation. If successful, sets
|
|
||||||
# the absolute path in the variable MATLAB_ROOT_DIR
|
|
||||||
function(locate_matlab_root)
|
|
||||||
|
|
||||||
# --- UNIX/APPLE ---
|
|
||||||
if (UNIX)
|
|
||||||
# possible root locations, in order of likelihood
|
|
||||||
set(SEARCH_DIRS_ /Applications /usr/local /opt/local /usr /opt)
|
|
||||||
foreach (DIR_ ${SEARCH_DIRS_})
|
|
||||||
file(GLOB MATLAB_ROOT_DIR_ ${DIR_}/MATLAB/R* ${DIR_}/MATLAB_R*)
|
|
||||||
if (MATLAB_ROOT_DIR_)
|
|
||||||
# sort in order from highest to lowest
|
|
||||||
# normally it's in the format MATLAB_R[20XX][A/B]
|
|
||||||
# TODO: numerical rather than lexicographic sort. However,
|
|
||||||
# CMake does not support floating-point MATH(EXPR ...) at this time.
|
|
||||||
list(SORT MATLAB_ROOT_DIR_)
|
|
||||||
list(REVERSE MATLAB_ROOT_DIR_)
|
|
||||||
list(GET MATLAB_ROOT_DIR_ 0 MATLAB_ROOT_DIR_)
|
|
||||||
set(MATLAB_ROOT_DIR ${MATLAB_ROOT_DIR_} PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# --- WINDOWS ---
|
|
||||||
elseif (WIN32)
|
|
||||||
# 1. search the path environment variable
|
|
||||||
find_program(MATLAB_ROOT_DIR_ matlab PATHS ENV PATH)
|
|
||||||
if (MATLAB_ROOT_DIR_)
|
|
||||||
# get the root directory from the full path
|
|
||||||
# /path/to/matlab/rootdir/bin/matlab.exe
|
|
||||||
get_filename_component(MATLAB_ROOT_DIR_ ${MATLAB_ROOT_DIR_} PATH)
|
|
||||||
get_filename_component(MATLAB_ROOT_DIR_ ${MATLAB_ROOT_DIR_} PATH)
|
|
||||||
set(MATLAB_ROOT_DIR ${MATLAB_ROOT_DIR_} PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# 2. search the registry
|
|
||||||
# determine the available Matlab versions
|
|
||||||
set(REG_EXTENSION_ "SOFTWARE\\Mathworks\\MATLAB")
|
|
||||||
set(REG_ROOTS_ "HKEY_LOCAL_MACHINE" "HKEY_CURRENT_USER")
|
|
||||||
foreach(REG_ROOT_ ${REG_ROOTS_})
|
|
||||||
execute_process(COMMAND reg query "${REG_ROOT_}\\${REG_EXTENSION_}" OUTPUT_VARIABLE QUERY_RESPONSE_ ERROR_VARIABLE UNUSED_)
|
|
||||||
if (QUERY_RESPONSE_)
|
|
||||||
string(REGEX MATCHALL "[0-9]\\.[0-9]" VERSION_STRINGS_ ${QUERY_RESPONSE_})
|
|
||||||
list(APPEND VERSIONS_ ${VERSION_STRINGS_})
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# select the highest version
|
|
||||||
list(APPEND VERSIONS_ "0.0")
|
|
||||||
list(SORT VERSIONS_)
|
|
||||||
list(REVERSE VERSIONS_)
|
|
||||||
list(GET VERSIONS_ 0 VERSION_)
|
|
||||||
|
|
||||||
# request the MATLABROOT from the registry
|
|
||||||
foreach(REG_ROOT_ ${REG_ROOTS_})
|
|
||||||
get_filename_component(QUERY_RESPONSE_ [${REG_ROOT_}\\${REG_EXTENSION_}\\${VERSION_};MATLABROOT] ABSOLUTE)
|
|
||||||
if (NOT ${QUERY_RESPONSE_} MATCHES "registry$")
|
|
||||||
set(MATLAB_ROOT_DIR ${QUERY_RESPONSE_} PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----- locate_matlab_components -----
|
|
||||||
#
|
|
||||||
# Given a directory MATLAB_ROOT_DIR, attempt to find the Matlab components
|
|
||||||
# (include directory and libraries) under the root. If everything is found,
|
|
||||||
# sets the variable MATLAB_FOUND to TRUE
|
|
||||||
function(locate_matlab_components MATLAB_ROOT_DIR)
|
|
||||||
# get the mex extension
|
|
||||||
find_file(MATLAB_MEXEXT_SCRIPT_ NAMES mexext mexext.bat PATHS ${MATLAB_ROOT_DIR}/bin NO_DEFAULT_PATH)
|
|
||||||
execute_process(COMMAND ${MATLAB_MEXEXT_SCRIPT_}
|
|
||||||
OUTPUT_VARIABLE MATLAB_MEXEXT_
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
if (NOT MATLAB_MEXEXT_)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# map the mexext to an architecture extension
|
|
||||||
set(ARCHITECTURES_ "maci64" "maci" "glnxa64" "glnx64" "sol64" "sola64" "win32" "win64" )
|
|
||||||
foreach(ARCHITECTURE_ ${ARCHITECTURES_})
|
|
||||||
if(EXISTS ${MATLAB_ROOT_DIR}/bin/${ARCHITECTURE_})
|
|
||||||
set(MATLAB_ARCH_ ${ARCHITECTURE_})
|
|
||||||
break()
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# get the path to the libraries
|
|
||||||
set(MATLAB_LIBRARY_DIRS_ ${MATLAB_ROOT_DIR}/bin/${MATLAB_ARCH_})
|
|
||||||
|
|
||||||
# get the libraries
|
|
||||||
set_libarch_prefix_suffix()
|
|
||||||
find_library(MATLAB_LIB_MX_ mx PATHS ${MATLAB_LIBRARY_DIRS_} NO_DEFAULT_PATH)
|
|
||||||
find_library(MATLAB_LIB_MEX_ mex PATHS ${MATLAB_LIBRARY_DIRS_} NO_DEFAULT_PATH)
|
|
||||||
find_library(MATLAB_LIB_MAT_ mat PATHS ${MATLAB_LIBRARY_DIRS_} NO_DEFAULT_PATH)
|
|
||||||
set(MATLAB_LIBRARIES_ ${MATLAB_LIB_MX_} ${MATLAB_LIB_MEX_} ${MATLAB_LIB_MAT_})
|
|
||||||
|
|
||||||
# get the include path
|
|
||||||
find_path(MATLAB_INCLUDE_DIRS_ mex.h ${MATLAB_ROOT_DIR}/extern/include)
|
|
||||||
|
|
||||||
# get the mex shell script
|
|
||||||
find_program(MATLAB_MEX_SCRIPT_ NAMES mex mex.bat PATHS ${MATLAB_ROOT_DIR}/bin NO_DEFAULT_PATH)
|
|
||||||
|
|
||||||
# get the Matlab executable
|
|
||||||
find_program(MATLAB_BIN_ NAMES matlab PATHS ${MATLAB_ROOT_DIR}/bin NO_DEFAULT_PATH)
|
|
||||||
|
|
||||||
# export into parent scope
|
|
||||||
if (MATLAB_MEX_SCRIPT_ AND MATLAB_LIBRARIES_ AND MATLAB_INCLUDE_DIRS_)
|
|
||||||
set(MATLAB_BIN ${MATLAB_BIN_} PARENT_SCOPE)
|
|
||||||
set(MATLAB_MEX_SCRIPT ${MATLAB_MEX_SCRIPT_} PARENT_SCOPE)
|
|
||||||
set(MATLAB_INCLUDE_DIRS ${MATLAB_INCLUDE_DIRS_} PARENT_SCOPE)
|
|
||||||
set(MATLAB_LIBRARIES ${MATLAB_LIBRARIES_} PARENT_SCOPE)
|
|
||||||
set(MATLAB_LIBRARY_DIRS ${MATLAB_LIBRARY_DIRS_} PARENT_SCOPE)
|
|
||||||
set(MATLAB_MEXEXT ${MATLAB_MEXEXT_} PARENT_SCOPE)
|
|
||||||
set(MATLAB_ARCH ${MATLAB_ARCH_} PARENT_SCOPE)
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
# FIND MATLAB COMPONENTS
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
if (NOT MATLAB_FOUND)
|
|
||||||
|
|
||||||
# attempt to find the Matlab root folder
|
|
||||||
if (NOT MATLAB_ROOT_DIR)
|
|
||||||
locate_matlab_root()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# given the matlab root folder, find the library locations
|
|
||||||
if (MATLAB_ROOT_DIR)
|
|
||||||
locate_matlab_components(${MATLAB_ROOT_DIR})
|
|
||||||
endif()
|
|
||||||
find_package_handle_standard_args(Matlab DEFAULT_MSG
|
|
||||||
MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS
|
|
||||||
MATLAB_ROOT_DIR MATLAB_LIBRARIES
|
|
||||||
MATLAB_LIBRARY_DIRS MATLAB_MEXEXT
|
|
||||||
MATLAB_ARCH MATLAB_BIN)
|
|
||||||
endif()
|
|
@ -296,28 +296,29 @@ endfunction()
|
|||||||
# Calls 'add_subdirectory' for each location.
|
# Calls 'add_subdirectory' for each location.
|
||||||
# Note: both input lists should have same length.
|
# Note: both input lists should have same length.
|
||||||
# Usage: _add_modules_1(<list with paths> <list with names>)
|
# Usage: _add_modules_1(<list with paths> <list with names>)
|
||||||
function(_add_modules_1 paths names)
|
macro(_add_modules_1 paths names)
|
||||||
list(LENGTH ${paths} len)
|
ocv_debug_message("_add_modules_1(paths=${paths}, names=${names}, ... " ${ARGN} ")")
|
||||||
if(len EQUAL 0)
|
list(LENGTH ${paths} __len)
|
||||||
return()
|
if(NOT __len EQUAL 0)
|
||||||
|
list(LENGTH ${names} __len_verify)
|
||||||
|
if(NOT __len EQUAL __len_verify)
|
||||||
|
message(FATAL_ERROR "Bad configuration! ${__len} != ${__len_verify}")
|
||||||
endif()
|
endif()
|
||||||
list(LENGTH ${names} len_verify)
|
math(EXPR __len "${__len} - 1")
|
||||||
if(NOT len EQUAL len_verify)
|
foreach(i RANGE ${__len})
|
||||||
message(FATAL_ERROR "Bad configuration! ${len} != ${len_verify}")
|
list(GET ${paths} ${i} __path)
|
||||||
endif()
|
list(GET ${names} ${i} __name)
|
||||||
math(EXPR len "${len} - 1")
|
#message(STATUS "First pass: ${__name} => ${__path}")
|
||||||
foreach(i RANGE ${len})
|
include("${__path}/cmake/init.cmake" OPTIONAL)
|
||||||
list(GET ${paths} ${i} path)
|
add_subdirectory("${__path}" "${CMAKE_CURRENT_BINARY_DIR}/.firstpass/${__name}")
|
||||||
list(GET ${names} ${i} name)
|
|
||||||
#message(STATUS "First pass: ${name} => ${path}")
|
|
||||||
include("${path}/cmake/init.cmake" OPTIONAL)
|
|
||||||
add_subdirectory("${path}" "${CMAKE_CURRENT_BINARY_DIR}/.firstpass/${name}")
|
|
||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
# Calls 'add_subdirectory' for each module name.
|
# Calls 'add_subdirectory' for each module name.
|
||||||
# Usage: _add_modules_2([<module> ...])
|
# Usage: _add_modules_2([<module> ...])
|
||||||
function(_add_modules_2)
|
macro(_add_modules_2)
|
||||||
|
ocv_debug_message("_add_modules_2(" ${ARGN} ")")
|
||||||
foreach(m ${ARGN})
|
foreach(m ${ARGN})
|
||||||
set(the_module "${m}")
|
set(the_module "${m}")
|
||||||
ocv_cmake_hook(PRE_MODULES_CREATE_${the_module})
|
ocv_cmake_hook(PRE_MODULES_CREATE_${the_module})
|
||||||
@ -333,7 +334,8 @@ function(_add_modules_2)
|
|||||||
endif()
|
endif()
|
||||||
ocv_cmake_hook(POST_MODULES_CREATE_${the_module})
|
ocv_cmake_hook(POST_MODULES_CREATE_${the_module})
|
||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
unset(the_module)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
# Check if list of input items is unique.
|
# Check if list of input items is unique.
|
||||||
# Usage: _assert_uniqueness(<failure message> <element> [<element> ...])
|
# Usage: _assert_uniqueness(<failure message> <element> [<element> ...])
|
||||||
|
@ -121,8 +121,10 @@ macro(ocv_assert)
|
|||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
macro(ocv_debug_message)
|
macro(ocv_debug_message)
|
||||||
# string(REPLACE ";" " " __msg "${ARGN}")
|
if(OPENCV_CMAKE_DEBUG_MESSAGES)
|
||||||
# message(STATUS "${__msg}")
|
string(REPLACE ";" " " __msg "${ARGN}")
|
||||||
|
message(STATUS "${__msg}")
|
||||||
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
macro(ocv_check_environment_variables)
|
macro(ocv_check_environment_variables)
|
||||||
|
@ -10,7 +10,7 @@ set(the_description "Deep neural network module. It allows to load models from d
|
|||||||
|
|
||||||
ocv_add_dispatched_file_force_all("layers/layers_common" AVX AVX2 AVX512_SKX)
|
ocv_add_dispatched_file_force_all("layers/layers_common" AVX AVX2 AVX512_SKX)
|
||||||
|
|
||||||
ocv_add_module(dnn opencv_core opencv_imgproc WRAP python matlab java js)
|
ocv_add_module(dnn opencv_core opencv_imgproc WRAP python java js)
|
||||||
|
|
||||||
ocv_option(OPENCV_DNN_OPENCL "Build with OpenCL support" HAVE_OPENCL AND NOT APPLE)
|
ocv_option(OPENCV_DNN_OPENCL "Build with OpenCL support" HAVE_OPENCL AND NOT APPLE)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user