Improved finding Matlab on Windows machines. Needs testing on computers that have multiple version installed
This commit is contained in:
parent
627b9df85f
commit
58ca8ed97f
@ -24,7 +24,18 @@
|
|||||||
#
|
#
|
||||||
# cmake -DMATLAB_ROOT_DIR='/PATH/TO/ROOT_DIR' ..
|
# cmake -DMATLAB_ROOT_DIR='/PATH/TO/ROOT_DIR' ..
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----- set_library_presuffix -----
|
# ----- 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)
|
function(set_libarch_prefix_suffix)
|
||||||
if (UNIX AND NOT APPLE)
|
if (UNIX AND NOT APPLE)
|
||||||
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" PARENT_SCOPE)
|
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" PARENT_SCOPE)
|
||||||
@ -38,6 +49,8 @@ function(set_libarch_prefix_suffix)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----- locate_matlab_root -----
|
# ----- locate_matlab_root -----
|
||||||
#
|
#
|
||||||
# Attempt to find the path to the Matlab installation. If successful, sets
|
# Attempt to find the path to the Matlab installation. If successful, sets
|
||||||
@ -79,55 +92,39 @@ function(locate_matlab_root)
|
|||||||
elseif (WIN32)
|
elseif (WIN32)
|
||||||
# search the path to see if Matlab exists there
|
# search the path to see if Matlab exists there
|
||||||
# fingers crossed it is, otherwise we have to start hunting through the registry :/
|
# fingers crossed it is, otherwise we have to start hunting through the registry :/
|
||||||
string(REGEX REPLACE ".*[;=](.*MATLAB[^;]*)\\\\bin.*" "\\1" MATLAB_ROOT_DIR_ "$ENV{PATH}")
|
string(REGEX REPLACE ".*[;=](.*[Mm][Aa][Tt][Ll][Aa][Bb][^;]*)\\\\bin.*" "\\1" MATLAB_ROOT_DIR_ "$ENV{PATH}")
|
||||||
if (MATLAB_ROOT_DIR_)
|
|
||||||
set(MATLAB_ROOT_DIR ${MATLAB_ROOT_DIR_} PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
# registry-hacking
|
||||||
# determine the Matlab version
|
# determine the available Matlab versions
|
||||||
set(REG_EXTENSION_ "SOFTWARE\\Mathworks\\MATLAB")
|
set(REG_EXTENSION_ "SOFTWARE\\Mathworks\\MATLAB")
|
||||||
set(REG_ROOTS_ "HKEY_LOCAL_MACHINE" "HKEY_CURRENT_USER")
|
set(REG_ROOTS_ "HKEY_LOCAL_MACHINE" "HKEY_CURRENT_USER")
|
||||||
foreach(REG_ROOT_ ${REG_ROOTS_})
|
foreach(REG_ROOT_ ${REG_ROOTS_})
|
||||||
execute_process(COMMAND reg query "${REG_ROOT_}\\${REG_EXTENSION_}"
|
execute_process(COMMAND reg query "${REG_ROOT_}\\${REG_EXTENSION_}" OUTPUT_VARIABLE QUERY_RESPONSE_)
|
||||||
OUTPUT_VARIABLE QUERY_RESPONSE_
|
if (QUERY_RESPONSE_)
|
||||||
)
|
string(REGEX MATCHALL "[0-9]\\.[0-9]" VERSION_STRINGS_ ${QUERY_RESPONSE_})
|
||||||
if (QUERY_RESPONSE)
|
list(APPEND VERSIONS_ ${VERSION_STRINGS_})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
set(QUERY_PATH_ ${REG_ROOT_}\\SOFTWARE)
|
|
||||||
set(QUERY_PATH_REGEX_ "${REG_ROOT_}\\\\SOFTWARE\\\\Mathworks\\\\MATLAB\\\\([\\.0-9]+)")
|
# select the highest version
|
||||||
message(${QUERY_PATH_})
|
list(APPEND VERSIONS_ "0.0")
|
||||||
execute_process(COMMAND reg query ${QUERY_PATH_} OUTPUT_VARIABLE QUERY_RESPONSE_
|
|
||||||
ERROR_VARIABLE ERROR_VAR_)
|
|
||||||
message("Error: ${ERROR_VAR_}")
|
|
||||||
message("Response: ${QUERY_RESPONSE_}")
|
|
||||||
if (QUERY_RESPONSE_)
|
|
||||||
string(REGEX MATCHALL ${QUERY_PATH_REGEX_} QUERY_MATCHES_ ${QUERY_RESPONSE_})
|
|
||||||
foreach(QUERY_MATCH_ ${QUERY_MATCHES_})
|
|
||||||
string(REGEX REPLACE ${QUERY_PATH_REGEX_} "\\1" QUERY_MATCH_ ${QUERY_MATCH_})
|
|
||||||
list(APPEND VERSIONS_ ${QUERY_MATCH_})
|
|
||||||
endforeach()
|
|
||||||
message(${VERSIONS_})
|
|
||||||
# sort in order from highest to lowest
|
|
||||||
list(SORT VERSIONS_)
|
list(SORT VERSIONS_)
|
||||||
list(REVERSE VERSIONS_)
|
list(REVERSE VERSIONS_)
|
||||||
list(GET VERSIONS_ 0 VERSION_)
|
list(GET VERSIONS_ 0 VERSION_)
|
||||||
get_filename_component(MATLAB_ROOT_DIR_ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Mathworks\\MATLAB] ABSOLUTE CACHE)
|
|
||||||
message(${MATLAB_ROOT_DIR_})
|
# request the MATLABROOT from the registry
|
||||||
if (MATLAB_ROOT_DIR_)
|
foreach(REG_ROOT_ ${REG_ROOTS_})
|
||||||
#break()
|
get_filename_component(QUERY_RESPONSE_ [${REG_ROOT_}\\${REG_EXTENSION_}\\${VERSION_};MATLABROOT] ABSOLUTE)
|
||||||
endif()
|
if (NOT ${MATLAB_ROOT_DIR_} AND NOT ${QUERY_RESPONSE_} MATCHES "registry$")
|
||||||
|
set(MATLAB_ROOT_DIR_ ${QUERY_RESPONSE_})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# export output into parent scope
|
# export the root into the parent scope
|
||||||
if (MATLAB_ROOT_DIR_)
|
if (MATLAB_ROOT_DIR_)
|
||||||
set(MATLAB_ROOT_DIR ${MATLAB_ROOT_DIR_} PARENT_SCOPE)
|
set(MATLAB_ROOT_DIR ${MATLAB_ROOT_DIR_} PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
return()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
@ -191,6 +188,7 @@ function(locate_matlab_components MATLAB_ROOT_DIR)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# FIND MATLAB COMPONENTS
|
# FIND MATLAB COMPONENTS
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
@ -211,9 +209,4 @@ if (NOT MATLAB_FOUND)
|
|||||||
find_package_handle_standard_args(Matlab DEFAULT_MSG MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIR
|
find_package_handle_standard_args(Matlab DEFAULT_MSG MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIR
|
||||||
MATLAB_ROOT_DIR MATLAB_LIBS MATLAB_LIBRARY_DIR
|
MATLAB_ROOT_DIR MATLAB_LIBS MATLAB_LIBRARY_DIR
|
||||||
MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
|
MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
|
||||||
|
|
||||||
# if Matlab was not found, unset the local variables
|
|
||||||
if (NOT MATLAB_FOUND)
|
|
||||||
unset (MATLAB_ROOT_DIR)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
@ -99,7 +99,6 @@ if (NOT MEX_WORKS)
|
|||||||
# attempt to generate a gateway for a function
|
# attempt to generate a gateway for a function
|
||||||
message(STATUS "Trying to generate Matlab code")
|
message(STATUS "Trying to generate Matlab code")
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/test/trigger.cpp
|
|
||||||
COMMAND ${PYTHON_EXECUTABLE}
|
COMMAND ${PYTHON_EXECUTABLE}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab.py ${HDR_PARSER_PATH}
|
${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab.py ${HDR_PARSER_PATH}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test/test_generator.hpp ${CMAKE_BINARY_DIR}/junk
|
${CMAKE_CURRENT_SOURCE_DIR}/test/test_generator.hpp ${CMAKE_BINARY_DIR}/junk
|
||||||
|
@ -9,8 +9,13 @@ class MatlabWrapperGenerator(object):
|
|||||||
ns = {}
|
ns = {}
|
||||||
for file in input_files:
|
for file in input_files:
|
||||||
# get the file name
|
# get the file name
|
||||||
|
# TODO: Is there a cleaner way to do this?
|
||||||
|
try:
|
||||||
name = re.findall('include/opencv2/([^./]+)', file)[0]
|
name = re.findall('include/opencv2/([^./]+)', file)[0]
|
||||||
#name = os.path.splitext(os.path.basename(file))[0]
|
except:
|
||||||
|
name = os.path.splitext(os.path.basename(file))[0]
|
||||||
|
|
||||||
|
# add the file to the namespace
|
||||||
try:
|
try:
|
||||||
ns[name] = ns[name] + parser.parse(file)
|
ns[name] = ns[name] + parser.parse(file)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user