From dfda79e673aad8871e7efc8df9361f20825dbeb0 Mon Sep 17 00:00:00 2001 From: hbristow Date: Mon, 5 Aug 2013 00:44:38 +1000 Subject: [PATCH] Added passthrough of CXX FLAGS to mex compiler --- modules/matlab/CMakeLists.txt | 13 +++++++++++-- modules/matlab/compile.cmake | 6 +++--- modules/matlab/include/mxarray.hpp | 11 ++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/matlab/CMakeLists.txt b/modules/matlab/CMakeLists.txt index 417b74969d..00d3a03d00 100644 --- a/modules/matlab/CMakeLists.txt +++ b/modules/matlab/CMakeLists.txt @@ -65,6 +65,7 @@ if (BUILD_TESTS) endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + # ---------------------------------------------------------------------------- # Configure time components # ---------------------------------------------------------------------------- @@ -84,6 +85,10 @@ endforeach() # add extra headers by hand list(APPEND opencv_hdrs "${OPENCV_MODULE_opencv_core_LOCATION}/include/opencv2/core/base.hpp") +# pass the OPENCV_CXX_EXTRA_FLAGS through to the mex compiler +# remove the visibility modifiers, so the mex gateway is visible +string(REGEX REPLACE "[^\ ]*visibility[^\ ]*" "" MEX_CXX_FLAGS "${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}") + # Configure checks # Check to see whether the generator and the mex compiler are working. # The checks currently test: @@ -113,8 +118,8 @@ if (NOT MEX_WORKS) # attempt to compile a gateway using mex message(STATUS "Trying to compile mex file") execute_process( - COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} ${MEX_INCLUDE_DIRS} - ${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp + COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} "CXXFLAGS=\$CXXFLAGS ${MEX_CXXFLAGS}" + ${MEX_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/junk ERROR_VARIABLE MEX_ERROR OUTPUT_QUIET @@ -133,6 +138,7 @@ endif() set_property(GLOBAL PROPERTY MEX_WORKS TRUE) set(MEX_WORKS True CACHE BOOL ADVANCED) + # ---------------------------------------------------------------------------- # Build time components # ---------------------------------------------------------------------------- @@ -142,6 +148,7 @@ set(MEX_WORKS True CACHE BOOL ADVANCED) # (which do the real work) only when they're outdated set(GENERATE_PROXY ${CMAKE_CURRENT_BINARY_DIR}/generate.proxy) set(COMPILE_PROXY ${CMAKE_CURRENT_BINARY_DIR}/compile.proxy) +# TODO: Remove following line before merging with master file(REMOVE ${GENERATE_PROXY} ${COMPILE_PROXY}) # generate @@ -164,6 +171,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -DMATLAB_MEX_SCRIPT=${MATLAB_MEX_SCRIPT} -DMATLAB_MEXEXT=${MATLAB_MEXEXT} -DMEX_OPTS=${MEX_OPTS} + -DMEX_CXXFLAGS=${MEX_CXXFLAGS} -DMEX_INCLUDE_DIRS="${MEX_INCLUDE_DIRS}" -DMEX_LIB_DIR=${MEX_LIB_DIR} -DMEX_LIBS="${MEX_LIBS}" @@ -182,6 +190,7 @@ if (ENABLE_SOLUTION_FOLDERS) set_target_properties(${the_module} PROPERTIES FOLDER "modules") endif() + # ---------------------------------------------------------------------------- # Install time components # ---------------------------------------------------------------------------- diff --git a/modules/matlab/compile.cmake b/modules/matlab/compile.cmake index 4f5e4d4999..d857d24cb1 100644 --- a/modules/matlab/compile.cmake +++ b/modules/matlab/compile.cmake @@ -3,7 +3,6 @@ macro(listify OUT_LIST IN_STRING) endmacro() listify(MEX_INCLUDE_DIRS_LIST ${MEX_INCLUDE_DIRS}) -set(MEX_CXXFLAGS "CXXFLAGS=\$CXXFLAGS -msse -msse2 -msse3 -msse4.1 -msse4.2 -pedantic -Wall -Wextra -Weffc++ -Wno-unused-parameter -Wold-style-cast -Wshadow -Wmissing-declarations -Wmissing-include-dirs -Wnon-virtual-dtor -Wno-newline-eof") file(GLOB SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/src/*.cpp") foreach(SOURCE_FILE ${SOURCE_FILES}) # strip out the filename @@ -11,13 +10,14 @@ foreach(SOURCE_FILE ${SOURCE_FILES}) # compie the source file using mex if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/+cv/${FILENAME}.${MATLAB_MEXEXT}) execute_process( - COMMAND ${MATLAB_MEX_SCRIPT} "${MEX_CXXFLAGS}" ${MEX_INCLUDE_DIRS_LIST} + COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} "CXXFLAGS=\$CXXFLAGS ${MEX_CXXFLAGS}" ${MEX_INCLUDE_DIRS_LIST} ${MEX_LIB_DIR} ${MEX_LIBS} ${SOURCE_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/+cv + OUTPUT_QUIET ERROR_VARIABLE FAILED ) endif() - # TODO: If a mex file fails to cmpile, should we error out? + # TODO: If a mex file fails to compile, should we error out? if (FAILED) message(FATAL_ERROR "Failed to compile ${FILENAME}: ${FAILED}") endif() diff --git a/modules/matlab/include/mxarray.hpp b/modules/matlab/include/mxarray.hpp index 655286b096..697a466d13 100644 --- a/modules/matlab/include/mxarray.hpp +++ b/modules/matlab/include/mxarray.hpp @@ -1,11 +1,12 @@ #ifndef OPENCV_MXARRAY_HPP_ #define OPENCV_MXARRAY_HPP_ +#include +#include +#include +#include #include "mex.h" #include "transpose.hpp" -#include -#include -#include /* * All recent versions of Matlab ship with the MKL library which contains @@ -34,7 +35,7 @@ extern "C" { * expression fails, an error is raised and the mex function returns * to Matlab, otherwise this function does nothing */ -void conditionalError(bool expr, const std::string& str) { +static void conditionalError(bool expr, const std::string& str) { if (!expr) mexErrMsgTxt(std::string("condition failed: ").append(str).c_str()); } @@ -43,7 +44,7 @@ void conditionalError(bool expr, const std::string& str) { * * This function is a wrapper around mexErrMsgTxt */ -void error(const std::string& str) { +static void error(const std::string& str) { mexErrMsgTxt(str.c_str()); }