Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
232f11e2
Commit
232f11e2
authored
Sep 13, 2013
by
hbristow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated OpenCVFindMatlab with changes suggested by SpecLad
parent
530ad447
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
66 deletions
+45
-66
OpenCVFindMatlab.cmake
cmake/OpenCVFindMatlab.cmake
+45
-66
No files found.
cmake/OpenCVFindMatlab.cmake
View file @
232f11e2
...
...
@@ -8,15 +8,15 @@
# 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_BIN: The actual Matlab executable
# MATLAB_INCLUDE_DIR: Path to "mex.h"
# MATLAB_LIBRARY_DIR: Path to mex and matrix libraries
# MATLAB_LIBS: The Matlab libs, usually mx, mex, mat
# 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 simply
# the MEXEXT with the preceding "mex" removed
# 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
...
...
@@ -57,23 +57,8 @@ endfunction()
# the absolute path in the variable MATLAB_ROOT_DIR
function
(
locate_matlab_root
)
# --- LINUX ---
if
(
UNIX AND NOT APPLE
)
# possible root locations, in order of likelihood
set
(
SEARCH_DIRS_ /usr/local /opt/local /usr /opt
)
foreach
(
DIR_
${
SEARCH_DIRS_
}
)
file
(
GLOB MATLAB_ROOT_DIR_
${
DIR_
}
/*matlab*
)
if
(
MATLAB_ROOT_DIR_
)
# sort in order from highest to lowest
list
(
SORT MATLAB_ROOT_DIR_
)
list
(
REVERSE MATLAB_ROOT_DIR_
)
list
(
GET MATLAB_ROOT_DIR_ 0 MATLAB_ROOT_DIR_
)
break
()
endif
()
endforeach
()
# --- APPLE ---
elseif
(
APPLE
)
# --- 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_
}
)
...
...
@@ -84,21 +69,25 @@ function(locate_matlab_root)
list
(
SORT MATLAB_ROOT_DIR_
)
list
(
REVERSE MATLAB_ROOT_DIR_
)
list
(
GET MATLAB_ROOT_DIR_ 0 MATLAB_ROOT_DIR_
)
break
()
set
(
MATLAB_ROOT_DIR
${
MATLAB_ROOT_DIR_
}
PARENT_SCOPE
)
return
()
endif
()
endforeach
()
# --- WINDOWS ---
elseif
(
WIN32
)
# search the path to see if Matlab exists there
# Contrary to EVERY OTHER REGEX IMPLEMENTATION ON EARTH, cmake returns
# the entire input string if no matches for the capture group are found.
string
(
REGEX REPLACE
".*[;=](.*[Mm][Aa][Tt][Ll][Aa][Bb][^;]*)
\\\\
bin.*"
"
\\
1"
MATLAB_ROOT_DIR_
"$ENV{PATH}"
)
if
(
"
${
MATLAB_ROOT_DIR_
}
"
STREQUAL
"$ENV{PATH}"
)
set
(
MATLAB_ROOT_DIR_
)
# 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
()
#
registry-hacking
#
2. search the registry
# determine the available Matlab versions
set
(
REG_EXTENSION_
"SOFTWARE
\\
Mathworks
\\
MATLAB"
)
set
(
REG_ROOTS_
"HKEY_LOCAL_MACHINE"
"HKEY_CURRENT_USER"
)
...
...
@@ -119,16 +108,12 @@ function(locate_matlab_root)
# request the MATLABROOT from the registry
foreach
(
REG_ROOT_
${
REG_ROOTS_
}
)
get_filename_component
(
QUERY_RESPONSE_ [
${
REG_ROOT_
}
\\
${
REG_EXTENSION_
}
\\
${
VERSION_
}
;MATLABROOT] ABSOLUTE
)
if
(
"
${
MATLAB_ROOT_DIR_
}
"
STREQUAL
""
AND NOT
${
QUERY_RESPONSE_
}
MATCHES
"registry$"
)
set
(
MATLAB_ROOT_DIR_
${
QUERY_RESPONSE_
}
)
if
(
NOT
${
QUERY_RESPONSE_
}
MATCHES
"registry$"
)
set
(
MATLAB_ROOT_DIR
${
QUERY_RESPONSE_
}
PARENT_SCOPE
)
return
()
endif
()
endforeach
()
endif
()
# export the root into the parent scope
if
(
MATLAB_ROOT_DIR_
)
set
(
MATLAB_ROOT_DIR
${
MATLAB_ROOT_DIR_
}
PARENT_SCOPE
)
endif
()
endfunction
()
...
...
@@ -140,11 +125,7 @@ endfunction()
# sets the variable MATLAB_FOUND to TRUE
function
(
locate_matlab_components MATLAB_ROOT_DIR
)
# get the mex extension
if
(
UNIX
)
execute_process
(
COMMAND
${
MATLAB_ROOT_DIR
}
/bin/mexext OUTPUT_VARIABLE MATLAB_MEXEXT_
)
elseif
(
WIN32
)
execute_process
(
COMMAND
${
MATLAB_ROOT_DIR
}
/bin/mexext.bat OUTPUT_VARIABLE MATLAB_MEXEXT_
)
endif
()
execute_process
(
COMMAND
${
MATLAB_ROOT_DIR
}
/bin/mexext OUTPUT_VARIABLE MATLAB_MEXEXT_
)
if
(
NOT MATLAB_MEXEXT_
)
return
()
endif
()
...
...
@@ -160,35 +141,34 @@ function(locate_matlab_components MATLAB_ROOT_DIR)
endforeach
()
# get the path to the libraries
set
(
MATLAB_LIBRARY_DIR_
${
MATLAB_ROOT_DIR
}
/bin/
${
MATLAB_ARCH_
}
)
set
(
MATLAB_LIBRARY_DIR
S
_
${
MATLAB_ROOT_DIR
}
/bin/
${
MATLAB_ARCH_
}
)
# get the libraries
set_libarch_prefix_suffix
()
find_library
(
MATLAB_LIB_MX_ mx PATHS
${
MATLAB_LIBRARY_DIR_
}
NO_DEFAULT_PATH
)
find_library
(
MATLAB_LIB_MEX_ mex PATHS
${
MATLAB_LIBRARY_DIR_
}
NO_DEFAULT_PATH
)
find_library
(
MATLAB_LIB_MAT_ mat PATHS
${
MATLAB_LIBRARY_DIR_
}
NO_DEFAULT_PATH
)
set
(
MATLAB_LIBS_
${
MATLAB_LIB_MX_
}
${
MATLAB_LIB_MEX_
}
${
MATLAB_LIB_MAT_
}
)
find_library
(
MATLAB_LIB_MX_ mx PATHS
${
MATLAB_LIBRARY_DIR
S
_
}
NO_DEFAULT_PATH
)
find_library
(
MATLAB_LIB_MEX_ mex PATHS
${
MATLAB_LIBRARY_DIR
S
_
}
NO_DEFAULT_PATH
)
find_library
(
MATLAB_LIB_MAT_ mat PATHS
${
MATLAB_LIBRARY_DIR
S
_
}
NO_DEFAULT_PATH
)
set
(
MATLAB_LIB
RARIE
S_
${
MATLAB_LIB_MX_
}
${
MATLAB_LIB_MEX_
}
${
MATLAB_LIB_MAT_
}
)
# get the include path
find_path
(
MATLAB_INCLUDE_DIR_ mex.h
${
MATLAB_ROOT_DIR
}
/extern/include
)
find_path
(
MATLAB_INCLUDE_DIR
S
_ mex.h
${
MATLAB_ROOT_DIR
}
/extern/include
)
# get the mex shell script
find_
file
(
MATLAB_MEX_SCRIPT_ NAMES mex mex.bat
PATHS
${
MATLAB_ROOT_DIR
}
/bin NO_DEFAULT_PATH
)
find_
program
(
MATLAB_MEX_SCRIPT_ NAMES mex
PATHS
${
MATLAB_ROOT_DIR
}
/bin NO_DEFAULT_PATH
)
# get the Matlab executable
find_
file
(
MATLAB_BIN_ NAMES matlab matlab.exe
PATHS
${
MATLAB_ROOT_DIR
}
/bin NO_DEFAULT_PATH
)
find_
program
(
MATLAB_BIN_ NAMES matlab
PATHS
${
MATLAB_ROOT_DIR
}
/bin NO_DEFAULT_PATH
)
# export into parent scope
if
(
MATLAB_MEX_SCRIPT_ AND MATLAB_LIB
S_ AND MATLAB_INCLUDE_DIR
_
)
set
(
MATLAB_BIN
${
MATLAB_BIN_
}
PARENT_SCOPE
)
set
(
MATLAB_MEX_SCRIPT
${
MATLAB_MEX_SCRIPT_
}
PARENT_SCOPE
)
set
(
MATLAB_INCLUDE_DIR
${
MATLAB_INCLUDE_DIR
_
}
PARENT_SCOPE
)
set
(
MATLAB_LIB
S
${
MATLAB_LIBS_
}
PARENT_SCOPE
)
set
(
MATLAB_LIBRARY_DIR
${
MATLAB_LIBRARY_DIR
_
}
PARENT_SCOPE
)
set
(
MATLAB_MEXEXT
${
MATLAB_MEXEXT_
}
PARENT_SCOPE
)
set
(
MATLAB_ARCH
${
MATLAB_ARCH_
}
PARENT_SCOPE
)
if
(
MATLAB_MEX_SCRIPT_ AND MATLAB_LIB
RARIES_ AND MATLAB_INCLUDE_DIRS
_
)
set
(
MATLAB_BIN
${
MATLAB_BIN_
}
PARENT_SCOPE
)
set
(
MATLAB_MEX_SCRIPT
${
MATLAB_MEX_SCRIPT_
}
PARENT_SCOPE
)
set
(
MATLAB_INCLUDE_DIR
S
${
MATLAB_INCLUDE_DIRS
_
}
PARENT_SCOPE
)
set
(
MATLAB_LIB
RARIES
${
MATLAB_LIBRARIES_
}
PARENT_SCOPE
)
set
(
MATLAB_LIBRARY_DIR
S
${
MATLAB_LIBRARY_DIRS
_
}
PARENT_SCOPE
)
set
(
MATLAB_MEXEXT
${
MATLAB_MEXEXT_
}
PARENT_SCOPE
)
set
(
MATLAB_ARCH
${
MATLAB_ARCH_
}
PARENT_SCOPE
)
endif
()
return
()
endfunction
()
...
...
@@ -198,9 +178,6 @@ endfunction()
# ----------------------------------------------------------------------------
if
(
NOT MATLAB_FOUND
)
# guilty until proven innocent
set
(
MATLAB_FOUND FALSE
)
# attempt to find the Matlab root folder
if
(
NOT MATLAB_ROOT_DIR
)
locate_matlab_root
()
...
...
@@ -210,7 +187,9 @@ if (NOT MATLAB_FOUND)
if
(
MATLAB_ROOT_DIR
)
locate_matlab_components
(
${
MATLAB_ROOT_DIR
}
)
endif
()
find_package_handle_standard_args
(
Matlab DEFAULT_MSG MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIR
MATLAB_ROOT_DIR MATLAB_LIBS MATLAB_LIBRARY_DIR
MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN
)
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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment