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:
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/test/trigger.cpp # - whether the python generator can be found
COMMAND ${PYTHON_EXECUTABLE} # - whether the python generator correctly outputs a file for a definition
${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab_caller.py ${HDR_PARSER_PATH} # - whether the mex compiler can find the required headers
${CMAKE_CURRENT_SOURCE_DIR}/test/test_generator.hpp ${CMAKE_BINARY_DIR}/junk # - whether the mex compiler can compile a trivial definition
ERROR_VARIABLE GEN_ERROR if (NOT MEX_WORKS)
OUTPUT_QUIET # attempt to generate a gateway for a function
) message("-- Trying to generate Matlab code")
execute_process(
if (GEN_ERROR) COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/test/trigger.cpp
message(${GEN_ERROR}) COMMAND ${PYTHON_EXECUTABLE}
message("-- Error generating Matlab code. Disabling Matlab bindings...") ${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_matlab_caller.py ${HDR_PARSER_PATH}
return() ${CMAKE_CURRENT_SOURCE_DIR}/test/test_generator.hpp ${CMAKE_BINARY_DIR}/junk
else() ERROR_VARIABLE GEN_ERROR
message("-- Trying to generate Matlab code - OK") OUTPUT_QUIET
endif() )
# attempt to compile a gateway using mex if (GEN_ERROR)
message("-- Trying to compile mex file") message(${GEN_ERROR})
execute_process( message("-- Error generating Matlab code. Disabling Matlab bindings...")
COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} ${MEX_INCLUDE_DIRS} return()
${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp else()
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/junk message("-- Trying to generate Matlab code - OK")
ERROR_VARIABLE MEX_ERROR endif()
OUTPUT_QUIET
)
if (MEX_ERROR) # attempt to compile a gateway using mex
message(${MEX_ERROR}) message("-- Trying to compile mex file")
message("-- Error compiling mex file. Disabling Matlab bindings...") execute_process(
return() COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} ${MEX_INCLUDE_DIRS}
else() ${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp
message("-- Trying to compile mex file - OK") WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/junk
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()
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