Commit dfda79e6 authored by hbristow's avatar hbristow

Added passthrough of CXX FLAGS to mex compiler

parent 5e50791a
......@@ -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
# ----------------------------------------------------------------------------
......
......@@ -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()
......
#ifndef OPENCV_MXARRAY_HPP_
#define OPENCV_MXARRAY_HPP_
#include "mex.h"
#include "transpose.hpp"
#include <vector>
#include <stdint.h>
#include <string>
#include <vector>
#include <opencv2/core.hpp>
#include "mex.h"
#include "transpose.hpp"
/*
* 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());
}
......
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