mirror of
https://github.com/opencv/opencv.git
synced 2025-06-10 19:24:07 +08:00
Improved configure time tests. Added OpenCV specific exception handling
This commit is contained in:
parent
4d135ac4d8
commit
884f36ba65
@ -6,14 +6,14 @@
|
|||||||
#
|
#
|
||||||
# MATLAB_FOUND: true/false
|
# MATLAB_FOUND: true/false
|
||||||
# MATLAB_ROOT_DIR: Root of Matlab installation
|
# MATLAB_ROOT_DIR: Root of Matlab installation
|
||||||
# MATLAB_MEX_SCRIPT The mex script used to compile mex files
|
# MATLAB_MEX_SCRIPT: The mex script used to compile mex files
|
||||||
# MATLAB_INCLUDE_DIR Path to "mex.h"
|
# MATLAB_INCLUDE_DIR: Path to "mex.h"
|
||||||
# MATLAB_LIBRARY_DIR Path to mex and matrix libraries
|
# MATLAB_LIBRARY_DIR: Path to mex and matrix libraries
|
||||||
# MATLAB_LIBS The Matlab libs, usually mx, mex, mat
|
# MATLAB_LIBS: The Matlab libs, usually mx, mex, mat
|
||||||
# MATLAB_MEXEXT The mex library extension. It will be one of:
|
# MATLAB_MEXEXT: The mex library extension. It will be one of:
|
||||||
# mexwin32, mexwin64, mexglx, mexa64, mexmac,
|
# mexwin32, mexwin64, mexglx, mexa64, mexmac,
|
||||||
# mexmaci, mexmaci64, mexsol, mexs64
|
# mexmaci, mexmaci64, mexsol, mexs64
|
||||||
# MATLAB_ARCH The installation architecture. It is simply
|
# MATLAB_ARCH: The installation architecture. It is simply
|
||||||
# the MEXEXT with the preceding "mex" removed
|
# the MEXEXT with the preceding "mex" removed
|
||||||
#
|
#
|
||||||
# There doesn't appear to be an elegant way to detect all versions of Matlab
|
# There doesn't appear to be an elegant way to detect all versions of Matlab
|
||||||
|
@ -1,10 +1,36 @@
|
|||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# CMake file for Matlab/Octave support
|
# CMake file for Matlab/Octave support
|
||||||
|
#
|
||||||
|
# Matlab code generation and compilation is broken down into two distinct
|
||||||
|
# stages: configure time and build time. The idea is that we want to give
|
||||||
|
# the user reasonable guarantees that once they type 'make' wrapper
|
||||||
|
# generation is unlikely to fail. Therefore we run a series of tests at
|
||||||
|
# configure time to check the working status of the core components.
|
||||||
|
#
|
||||||
|
# Configure Time
|
||||||
|
# During configure time, the script attempts to ascertain whether the
|
||||||
|
# generator and mex compiler are working for a given architecture.
|
||||||
|
# Currently this involves:
|
||||||
|
# 1) Generating a simple CV_EXPORTS_W symbol and checking whether a file
|
||||||
|
# of the symbol name is generated
|
||||||
|
# 2) Compiling a simple mex gateway to check that Bridge.hpp and mex.h
|
||||||
|
# can be found, and that a file with the mexext is produced
|
||||||
|
#
|
||||||
|
# Build Time
|
||||||
|
# If the configure time tests pass, then we assume Matlab wrapper generation
|
||||||
|
# will not fail during build time. We simply glob all of the symbols in
|
||||||
|
# the OpenCV module headers, generate intermediate .cpp files, then compile
|
||||||
|
# them with mex.
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# PREPEND
|
||||||
|
# Given a list of strings IN and a TOKEN, prepend the token to each string
|
||||||
|
# and append to OUT. This is used for passing command line "-I", "-L" and "-l"
|
||||||
|
# arguments to mex. e.g.
|
||||||
|
# prepend("-I" OUT /path/to/include/dir) --> -I/path/to/include/dir
|
||||||
macro(PREPEND TOKEN OUT IN)
|
macro(PREPEND TOKEN OUT IN)
|
||||||
foreach(VAR ${IN})
|
foreach(VAR ${IN})
|
||||||
string(REGEX REPLACE "^/" "${TOKEN}/" TMP ${VAR})
|
list(APPEND ${OUT} "${TOKEN}${VAR}")
|
||||||
list(APPEND ${OUT} ${TMP})
|
|
||||||
endforeach()
|
endforeach()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
@ -32,14 +58,14 @@ prepend("-I" MEX_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|||||||
message("-- Trying to generate Matlab code")
|
message("-- Trying to generate Matlab code")
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab_caller.py
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab_caller.py
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test/rand.hpp ${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}/test/test_generator.hpp ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
ERROR_VARIABLE GEN_ERROR
|
ERROR_VARIABLE GEN_ERROR
|
||||||
OUTPUT_QUIET
|
OUTPUT_QUIET
|
||||||
)
|
)
|
||||||
|
|
||||||
if (GEN_ERROR)
|
if (GEN_ERROR)
|
||||||
message(${GEN_ERROR})
|
message(${GEN_ERROR})
|
||||||
message("-- Generating Matlab code failed. Disabling Matlab bindings...")
|
message("-- Error generating Matlab code. Disabling Matlab bindings...")
|
||||||
# restore the pythonpath
|
# restore the pythonpath
|
||||||
set(ENV{PYTHONPATH} ${PYPATH_CACHE})
|
set(ENV{PYTHONPATH} ${PYPATH_CACHE})
|
||||||
return()
|
return()
|
||||||
@ -50,7 +76,8 @@ endif()
|
|||||||
# attempt to compile the file using mex
|
# attempt to compile the file using mex
|
||||||
message("-- Trying to compile mex file")
|
message("-- Trying to compile mex file")
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}/src/rand.cpp
|
COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_INCLUDES}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
|
||||||
ERROR_VARIABLE MEX_ERROR
|
ERROR_VARIABLE MEX_ERROR
|
||||||
OUTPUT_QUIET
|
OUTPUT_QUIET
|
||||||
@ -68,17 +95,20 @@ endif()
|
|||||||
|
|
||||||
# if we make it here, mex works!
|
# if we make it here, mex works!
|
||||||
set_property(GLOBAL PROPERTY MEX_WORKS TRUE)
|
set_property(GLOBAL PROPERTY MEX_WORKS TRUE)
|
||||||
|
return()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# Build time components
|
# Build time components
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
#string(REPLACE "opencv_" "" OPENCV_MATLAB_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};
|
string(REPLACE "opencv_" "" OPENCV_MATLAB_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};
|
||||||
# ${OPENCV_MODULE_${the_module}_OPT_DEPS}")
|
${OPENCV_MODULE_${the_module}_OPT_DEPS}")
|
||||||
foreach(module ${OPENCV_MATLAB_MODULES})
|
foreach(module ${OPENCV_MATLAB_MODULES})
|
||||||
if (HAVE_opencv_${module})
|
if (HAVE_opencv_${module})
|
||||||
list(APPEND opencv_hdrs "${OPENCV_MODULE_opencv_${module}_LOCATION}/include/opencv2/${module}.hpp")
|
list(APPEND opencv_hdrs "${OPENCV_MODULE_opencv_${module}_LOCATION}/include/opencv2/${module}.hpp")
|
||||||
|
prepend("-I" MEX_INCLUDES "${OPENCV_MODULE_opencv_${module}_LOCATION}/include")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
message(${MEX_INCLUDES})
|
||||||
|
|
||||||
# synthesise the matlab sources
|
# synthesise the matlab sources
|
||||||
# TODO:These should be build-time (ie add_custom_command)
|
# TODO:These should be build-time (ie add_custom_command)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
{% block includes %}
|
{% block includes %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "mex.h"
|
#include "mex.h"
|
||||||
#include "bridge.hpp"
|
#include "bridge.hpp"
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
{% block includes %}
|
{% block includes %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -39,6 +41,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
|
|||||||
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
||||||
try {
|
try {
|
||||||
{{fun.name}}();
|
{{fun.name}}();
|
||||||
|
} catch(cv::Exception& e) {
|
||||||
|
mexErrMsgTxt(std::string("OpenCV exception caught: ").append(e.what()).c_str());
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}");
|
mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}");
|
||||||
}
|
}
|
||||||
|
32
modules/matlab/test/test_compiler.cpp
Normal file
32
modules/matlab/test/test_compiler.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* file: rand.cpp
|
||||||
|
* author: A trusty code generator
|
||||||
|
* date: Wed, 19 Jun 2013 11:15:15
|
||||||
|
*
|
||||||
|
* This file was autogenerated, do not modify.
|
||||||
|
* See LICENCE for full modification and redistribution details.
|
||||||
|
* Copyright 2013 The OpenCV Foundation
|
||||||
|
*/
|
||||||
|
#include "mex.h"
|
||||||
|
#include "bridge.hpp"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rand
|
||||||
|
* Gateway routine
|
||||||
|
* nlhs - number of return arguments
|
||||||
|
* plhs - pointers to return arguments
|
||||||
|
* nrhs - number of input arguments
|
||||||
|
* prhs - pointers to input arguments
|
||||||
|
*/
|
||||||
|
void mexFunction(int nlhs, mxArray* plhs[],
|
||||||
|
int nrhs, const mxArray* prhs[]) {
|
||||||
|
|
||||||
|
// call the opencv function
|
||||||
|
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
||||||
|
try {
|
||||||
|
rand();
|
||||||
|
} catch(...) {
|
||||||
|
mexErrMsgTxt("Uncaught exception occurred in rand");
|
||||||
|
}
|
||||||
|
}
|
@ -3,8 +3,8 @@
|
|||||||
* part of <cstdlib>, so we can be reasonably sure its
|
* part of <cstdlib>, so we can be reasonably sure its
|
||||||
* definition will be found
|
* definition will be found
|
||||||
*/
|
*/
|
||||||
#ifndef __OPENCV_MATLAB_TEST_COMPILER_HPP_
|
#ifndef __OPENCV_MATLAB_TEST_GENERATOR_HPP_
|
||||||
#define __OPENCV_MATLAB_TEST_COMPILER_HPP_
|
#define __OPENCV_MATLAB_TEST_GENERATOR_HPP_
|
||||||
|
|
||||||
namespace cv {
|
namespace cv {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user