2013-03-10 17:17:05 +01:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# CMake file for Matlab/Octave support
|
2013-06-19 03:54:14 +02:00
|
|
|
#
|
|
|
|
# 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
|
2013-06-19 05:59:22 +02:00
|
|
|
# the user reasonable guarantees that once they type 'make', wrapper
|
2013-06-19 03:54:14 +02:00
|
|
|
# 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.
|
2013-03-10 17:17:05 +01:00
|
|
|
# ----------------------------------------------------------------------------
|
2013-06-19 03:54:14 +02:00
|
|
|
|
|
|
|
# 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
|
2013-06-18 15:00:48 +02:00
|
|
|
macro(PREPEND TOKEN OUT IN)
|
|
|
|
foreach(VAR ${IN})
|
2013-06-19 03:54:14 +02:00
|
|
|
list(APPEND ${OUT} "${TOKEN}${VAR}")
|
2013-06-18 15:00:48 +02:00
|
|
|
endforeach()
|
|
|
|
endmacro()
|
2013-03-10 17:17:05 +01:00
|
|
|
|
2013-03-14 08:26:18 +01:00
|
|
|
# make sure we're on a supported architecture with Matlab and python installed
|
|
|
|
if (IOS OR ANDROID OR NOT MATLAB_FOUND OR NOT PYTHONLIBS_FOUND)
|
2013-03-10 17:17:05 +01:00
|
|
|
ocv_module_disable(matlab)
|
2013-06-19 05:59:22 +02:00
|
|
|
return()
|
2013-03-10 17:17:05 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(the_description "The Matlab/Octave bindings")
|
|
|
|
ocv_add_module(matlab BINDINGS opencv_core opencv_imgproc
|
|
|
|
OPTIONAL opencv_objdetect opencv_features2d opencv_video
|
|
|
|
opencv_highgui opencv_ml opencv_calib3d opencv_photo
|
|
|
|
opencv_nonfree opencv_calib)
|
|
|
|
|
2013-06-19 07:04:52 +02:00
|
|
|
if (BUILD_TESTS)
|
|
|
|
add_subdirectory(test)
|
|
|
|
endif()
|
2013-06-18 15:00:48 +02:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Configure time components
|
|
|
|
# ----------------------------------------------------------------------------
|
2013-06-19 07:04:52 +02:00
|
|
|
set(HDR_PARSER_PATH ${OPENCV_MODULE_opencv_python_LOCATION}/src2)
|
|
|
|
prepend("-I" MEX_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
|
|
|
2013-06-18 15:00:48 +02:00
|
|
|
message("-- Trying to generate Matlab code")
|
|
|
|
execute_process(
|
2013-06-19 05:59:22 +02:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab_caller.py ${HDR_PARSER_PATH}
|
2013-06-19 03:54:14 +02:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/test_generator.hpp ${CMAKE_CURRENT_BINARY_DIR}
|
2013-06-18 15:00:48 +02:00
|
|
|
ERROR_VARIABLE GEN_ERROR
|
|
|
|
OUTPUT_QUIET
|
|
|
|
)
|
|
|
|
|
|
|
|
if (GEN_ERROR)
|
|
|
|
message(${GEN_ERROR})
|
2013-06-19 03:54:14 +02:00
|
|
|
message("-- Error generating Matlab code. Disabling Matlab bindings...")
|
2013-06-18 15:00:48 +02:00
|
|
|
return()
|
|
|
|
else()
|
|
|
|
message("-- Trying to generate Matlab code - OK")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# attempt to compile the file using mex
|
|
|
|
message("-- Trying to compile mex file")
|
|
|
|
execute_process(
|
2013-06-19 03:54:14 +02:00
|
|
|
COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_INCLUDES}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp
|
2013-06-18 15:00:48 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
|
|
|
|
ERROR_VARIABLE MEX_ERROR
|
|
|
|
OUTPUT_QUIET
|
|
|
|
)
|
|
|
|
|
|
|
|
if (MEX_ERROR)
|
|
|
|
message(${MEX_ERROR})
|
|
|
|
message("-- Error compiling mex file. Disabling Matlab bindings...")
|
|
|
|
return()
|
|
|
|
else()
|
|
|
|
message("-- Trying to compile mex file - OK")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# if we make it here, mex works!
|
|
|
|
set_property(GLOBAL PROPERTY MEX_WORKS TRUE)
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Build time components
|
|
|
|
# ----------------------------------------------------------------------------
|
2013-06-19 03:54:14 +02:00
|
|
|
string(REPLACE "opencv_" "" OPENCV_MATLAB_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};
|
|
|
|
${OPENCV_MODULE_${the_module}_OPT_DEPS}")
|
2013-03-18 05:48:10 +01:00
|
|
|
foreach(module ${OPENCV_MATLAB_MODULES})
|
|
|
|
if (HAVE_opencv_${module})
|
2013-06-18 09:27:09 +02:00
|
|
|
list(APPEND opencv_hdrs "${OPENCV_MODULE_opencv_${module}_LOCATION}/include/opencv2/${module}.hpp")
|
2013-06-19 03:54:14 +02:00
|
|
|
prepend("-I" MEX_INCLUDES "${OPENCV_MODULE_opencv_${module}_LOCATION}/include")
|
2013-03-14 08:26:18 +01:00
|
|
|
endif()
|
2013-03-18 05:48:10 +01:00
|
|
|
endforeach()
|
2013-03-14 08:26:18 +01:00
|
|
|
|
|
|
|
# synthesise the matlab sources
|
2013-06-19 05:59:22 +02:00
|
|
|
add_custom_target(opencv_matlab_sources ALL
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab_caller.py ${HDR_PARSER_PATH}
|
|
|
|
${opencv_hdrs} ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
)
|
2013-03-14 08:26:18 +01:00
|
|
|
|
2013-06-19 05:59:22 +02:00
|
|
|
# get the matlab sources
|
|
|
|
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/src/*.cpp")
|
2013-03-14 08:26:18 +01:00
|
|
|
foreach(SOURCE_FILE ${SOURCE_FILES})
|
2013-06-19 05:59:22 +02:00
|
|
|
get_filename_component(FILENAME ${SOURCE_FILE} NAME_WE)
|
2013-03-14 08:26:18 +01:00
|
|
|
# compile the source file using mex
|
2013-06-19 05:59:22 +02:00
|
|
|
add_custom_target("opencv_matlab_${FILENAME}" ALL
|
|
|
|
COMMAND "/usr/bin/true"
|
|
|
|
#COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_INCLUDES}
|
|
|
|
# ${SOURCE_FILE}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
|
|
|
|
DEPENDS opencv_matlab_sources
|
|
|
|
)
|
2013-03-14 08:26:18 +01:00
|
|
|
endforeach()
|
2013-06-19 07:04:52 +02:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Install time components
|
|
|
|
# ----------------------------------------------------------------------------
|