Commit 24d5adfd authored by hbristow's avatar hbristow

Added commenting to modules/matlab/CMakeLists.txt

parent 755ce9d6
...@@ -77,52 +77,68 @@ foreach(module ${OPENCV_MATLAB_MODULES}) ...@@ -77,52 +77,68 @@ foreach(module ${OPENCV_MATLAB_MODULES})
endif() endif()
endforeach() endforeach()
# attempt to generate a gateway for a function # Configure checks
message("-- Trying to generate Matlab code") # Check to see whether the generator and the mex compiler are working.
execute_process( # The checks currently test:
# - whether the python generator can be found
# - whether the python generator correctly outputs a file for a definition
# - whether the mex compiler can find the required headers
# - whether the mex compiler can compile a trivial definition
if (NOT MEX_WORKS)
# attempt to generate a gateway for a function
message("-- Trying to generate Matlab code")
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/test/trigger.cpp 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_caller.py ${HDR_PARSER_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab_caller.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
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("-- Error generating Matlab code. Disabling Matlab bindings...") message("-- Error generating Matlab code. Disabling Matlab bindings...")
return() return()
else() else()
message("-- Trying to generate Matlab code - OK") message("-- Trying to generate Matlab code - OK")
endif() endif()
# attempt to compile a gateway using mex # attempt to compile a gateway using mex
message("-- Trying to compile mex file") message("-- Trying to compile mex file")
execute_process( execute_process(
COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} ${MEX_INCLUDE_DIRS} COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} ${MEX_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/junk WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/junk
ERROR_VARIABLE MEX_ERROR ERROR_VARIABLE MEX_ERROR
OUTPUT_QUIET OUTPUT_QUIET
) )
if (MEX_ERROR) if (MEX_ERROR)
message(${MEX_ERROR}) message(${MEX_ERROR})
message("-- Error compiling mex file. Disabling Matlab bindings...") message("-- Error compiling mex file. Disabling Matlab bindings...")
return() return()
else() else()
message("-- Trying to compile mex file - OK") message("-- Trying to compile mex file - OK")
endif()
endif() 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)
set(MEX_WORKS True CACHE BOOL ADVANCED)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Build time components # Build time components
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# proxies
# these proxies are used to trigger the add_custom_commands
# (which do the real work) only when they're outdated
set(GENERATE_PROXY ${CMAKE_CURRENT_BINARY_DIR}/generate.proxy) set(GENERATE_PROXY ${CMAKE_CURRENT_BINARY_DIR}/generate.proxy)
set(COMPILE_PROXY ${CMAKE_CURRENT_BINARY_DIR}/compile.proxy) set(COMPILE_PROXY ${CMAKE_CURRENT_BINARY_DIR}/compile.proxy)
# generate
# call the python executable to generate the Matlab gateways
add_custom_command( add_custom_command(
OUTPUT ${GENERATE_PROXY} OUTPUT ${GENERATE_PROXY}
COMMAND ${PYTHON_EXECUTABLE} COMMAND ${PYTHON_EXECUTABLE}
...@@ -132,6 +148,10 @@ add_custom_command( ...@@ -132,6 +148,10 @@ add_custom_command(
COMMENT "Generating matlab source files" COMMENT "Generating matlab source files"
) )
# compile
# call the mex compiler to compile the gateways
# because we don't know the source files at configure-time, this
# has to be executed in a separate script in cmake's script processing mode
add_custom_command( add_custom_command(
OUTPUT ${COMPILE_PROXY} OUTPUT ${COMPILE_PROXY}
COMMAND ${CMAKE_COMMAND} -DMATLAB_MEX_SCRIPT=${MATLAB_MEX_SCRIPT} COMMAND ${CMAKE_COMMAND} -DMATLAB_MEX_SCRIPT=${MATLAB_MEX_SCRIPT}
...@@ -144,6 +164,8 @@ add_custom_command( ...@@ -144,6 +164,8 @@ add_custom_command(
COMMENT "Compiling Matlab source files. This could take a while..." COMMENT "Compiling Matlab source files. This could take a while..."
) )
# targets
# opencv_matlab_sources --> opencv_matlab_compile
add_custom_target(${the_module}_sources ALL DEPENDS ${GENERATE_PROXY}) add_custom_target(${the_module}_sources ALL DEPENDS ${GENERATE_PROXY})
add_custom_target(${the_module} ALL DEPENDS ${COMPILE_PROXY}) add_custom_target(${the_module} ALL DEPENDS ${COMPILE_PROXY})
add_dependencies(${the_module} ${the_module}_sources) add_dependencies(${the_module} ${the_module}_sources)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment