diff --git a/modules/matlab/CMakeLists.txt b/modules/matlab/CMakeLists.txt index fc397e4658..1dee04b7c4 100644 --- a/modules/matlab/CMakeLists.txt +++ b/modules/matlab/CMakeLists.txt @@ -276,22 +276,26 @@ endif() # ---------------------------------------------------------------------------- # NOTE: Trailing slashes on the DIRECTORY paths are important! # TODO: What needs to be done with rpath???? -file(GLOB MATLAB_FUNCTIONS "${CMAKE_CURRENT_BINARY_DIR}/src/*.${MATLAB_MEXEXT}") -file(GLOB MATLAB_CLASSES "${CMAKE_CURRENT_BINARY_DIR}/+cv/*.m") -file(GLOB MATLAB_PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/src/private/*.${MATLAB_MEXEXT}") -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/+cv/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/matlab/+cv - FILES_MATCHING PATTERN "*.${MATLAB_MEXEXT}" -) -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/+cv/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/matlab/+cv - FILES_MATCHING PATTERN "*.m" -) -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/+cv/private/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/matlab/+cv/private - FILES_MATCHING PATTERN "*.${MATLAB_MEXEXT}" -) -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/matlab - FILES_MATCHING PATTERN "cv.m" + +# install the +cv directory verbatim +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}) +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/+cv/ DESTINATION matlab/+cv) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cv.m DESTINATION matlab) + +# update the custom mex compiler to point to the install locations +string(REPLACE ";" "\\ " MEX_OPTS "${MEX_OPTS}") +string(REPLACE ";" "\\ " MEX_LIBS "${MEX_LIBS}") +string(REPLACE " " "\\ " MEX_CXXFLAGS ${MEX_CXXFLAGS}) +string(REPLACE ";" "\\ " MEX_INCLUDE_DIRS "${MEX_INCLUDE_DIRS}") +install(CODE + "execute_process( + COMMAND ${PYTHON_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/generator/cvmex.py + --opts=${MEX_OPTS} + --include_dirs=-I${CMAKE_INSTALL_PREFIX}/${OPENCV_INCLUDE_INSTALL_PATH} + --lib_dir=-L${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH} + --libs=${MEX_LIBS} + --flags=${MEX_CXXFLAGS} + --outdir ${CMAKE_INSTALL_PREFIX}/matlab + )" ) diff --git a/modules/matlab/generator/templates/template_class_base.cpp b/modules/matlab/generator/templates/template_class_base.cpp index f353f75bb9..e59b7b1d03 100644 --- a/modules/matlab/generator/templates/template_class_base.cpp +++ b/modules/matlab/generator/templates/template_class_base.cpp @@ -8,11 +8,11 @@ * See LICENCE for full modification and redistribution details. * Copyright {{time.strftime("%Y", time.localtime())}} The OpenCV Foundation */ -#include "mex.h" -#include "map.hpp" -#include "bridge.hpp" +#include #include #include +#include +#include #include using namespace cv; diff --git a/modules/matlab/generator/templates/template_function_base.cpp b/modules/matlab/generator/templates/template_function_base.cpp index 7a6ad4b07f..56f71ce386 100644 --- a/modules/matlab/generator/templates/template_function_base.cpp +++ b/modules/matlab/generator/templates/template_function_base.cpp @@ -8,12 +8,11 @@ * See LICENCE for full modification and redistribution details. * Copyright {{time.strftime("%Y", time.localtime())}} The OpenCV Foundation */ -#include "mex.h" -#include "bridge.hpp" #include #include #include #include +#include #include using namespace cv; diff --git a/modules/matlab/include/bridge.hpp b/modules/matlab/include/opencv2/matlab/bridge.hpp similarity index 100% rename from modules/matlab/include/bridge.hpp rename to modules/matlab/include/opencv2/matlab/bridge.hpp diff --git a/modules/matlab/include/map.hpp b/modules/matlab/include/opencv2/matlab/map.hpp similarity index 100% rename from modules/matlab/include/map.hpp rename to modules/matlab/include/opencv2/matlab/map.hpp diff --git a/modules/matlab/include/mxarray.hpp b/modules/matlab/include/opencv2/matlab/mxarray.hpp similarity index 98% rename from modules/matlab/include/mxarray.hpp rename to modules/matlab/include/opencv2/matlab/mxarray.hpp index 1c34255f99..26a480a7e9 100644 --- a/modules/matlab/include/mxarray.hpp +++ b/modules/matlab/include/opencv2/matlab/mxarray.hpp @@ -15,7 +15,7 @@ typedef std::unordered_set StringSet; #include typedef std::set StringSet; #endif -#include "mex.h" +#include #include "transpose.hpp" /* @@ -488,6 +488,7 @@ private: struct Variant; typedef std::string String; typedef std::vector StringVector; + typedef std::vector IndexVector; typedef std::vector MxArrayVector; typedef std::vector VariantVector; /* @class Variant @@ -506,6 +507,7 @@ private: size_t nreq; size_t nopt; StringVector keys; + IndexVector order; bool using_named; /*! @brief return true if the named-argument is in the Variant */ bool count(const String& key) { return std::find(keys.begin(), keys.end(), key) != keys.end(); } @@ -529,6 +531,14 @@ private: return s.str(); } }; + void sortArguments(Variant& v, MxArrayVector& in, MxArrayVector& out) { + // allocate the output array with ALL arguments + out.resize(v.nreq + v.nopt); + // reorder the inputs based on the variant ordering + for (size_t n = 0; n < v.order.size(); ++n) { + swap(in[n], out[v.order[n]]); + } + } MxArrayVector filled_; VariantVector variants_; String valid_; diff --git a/modules/matlab/include/transpose.hpp b/modules/matlab/include/opencv2/matlab/transpose.hpp similarity index 100% rename from modules/matlab/include/transpose.hpp rename to modules/matlab/include/opencv2/matlab/transpose.hpp