Commit 538dbfe5 authored by hbristow's avatar hbristow

Now compiling under much more strigent warnings, with Clang and optional C++11 support

parent 53a7fbf7
...@@ -32,6 +32,11 @@ set(OPENCV_EXTRA_EXE_LINKER_FLAGS "") ...@@ -32,6 +32,11 @@ set(OPENCV_EXTRA_EXE_LINKER_FLAGS "")
set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "") set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "")
set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "") set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "")
# if Apple and Clang, enable C++11 support :)
if(APPLE AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(OPENCV_EXTRA_CXX_FLAGS "-std=c++11 -stdlib=libc++")
endif()
macro(add_extra_compiler_option option) macro(add_extra_compiler_option option)
if(CMAKE_BUILD_TYPE) if(CMAKE_BUILD_TYPE)
set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE}) set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
...@@ -294,4 +299,4 @@ if(MSVC) ...@@ -294,4 +299,4 @@ if(MSVC)
if(NOT ENABLE_NOISY_WARNINGS) if(NOT ENABLE_NOISY_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") #class 'std::XXX' needs to have dll-interface to be used by clients of YYY set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") #class 'std::XXX' needs to have dll-interface to be used by clients of YYY
endif() endif()
endif() endif()
\ No newline at end of file
...@@ -58,7 +58,7 @@ set(HDR_PARSER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../python/src2) ...@@ -58,7 +58,7 @@ set(HDR_PARSER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../python/src2)
prepend("-I" MEX_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include) prepend("-I" MEX_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
prepend("-L" MEX_LIB_DIR ${CMAKE_BINARY_DIR}/lib) prepend("-L" MEX_LIB_DIR ${CMAKE_BINARY_DIR}/lib)
prepend("-l" MEX_LIBS opencv_core) prepend("-l" MEX_LIBS opencv_core)
set(MEX_OPTS "-largeArrayDims") set(MEX_OPTS -largeArrayDims)
if (ENABLE_SOLUTION_FOLDERS) if (ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_module} PROPERTIES FOLDER "Matlab bindings") set_target_properties(${the_module} PROPERTIES FOLDER "Matlab bindings")
...@@ -118,7 +118,7 @@ if (NOT MEX_WORKS) ...@@ -118,7 +118,7 @@ if (NOT MEX_WORKS)
${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)
......
...@@ -12,9 +12,9 @@ def inputs(args): ...@@ -12,9 +12,9 @@ def inputs(args):
except: except:
return [arg for arg in args if arg.I] return [arg for arg in args if arg.I]
def ninputs(args): def ninputs(fun):
'''Counts the number of input arguments in the input list''' '''Counts the number of input arguments in the input list'''
return len(inputs(args)) return len(inputs(fun.req)) + len(inputs(fun.opt))
def outputs(args): def outputs(args):
'''Determines whether any of the given arguments is an output '''Determines whether any of the given arguments is an output
...@@ -39,9 +39,9 @@ def void(arg): ...@@ -39,9 +39,9 @@ def void(arg):
def flip(arg): def flip(arg):
return not arg return not arg
def noutputs(args): def noutputs(fun):
'''Counts the number of output arguments in the input list''' '''Counts the number of output arguments in the input list'''
return len(outputs(args)) return int(not void(fun.rtp)) + len(outputs(fun.req)) + len(outputs(fun.opt))
def convertibleToInt(string): def convertibleToInt(string):
salt = '1+' salt = '1+'
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// create a full function invocation // create a full function invocation
{%- macro generate(fun) -%} {%- macro generate(fun) -%}
{% if fun|ninputs or fun|noutputs %}
// unpack the arguments // unpack the arguments
{# ----------- Inputs ------------- #} {# ----------- Inputs ------------- #}
{% for arg in fun.req|inputs %} {% for arg in fun.req|inputs %}
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
{% if not fun.rtp|void %} {% if not fun.rtp|void %}
{{fun.rtp}} retval; {{fun.rtp}} retval;
{% endif %} {% endif %}
{% endif %}
// call the opencv function // call the opencv function
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn); // [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
...@@ -60,6 +62,7 @@ ...@@ -60,6 +62,7 @@
mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}"); mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}");
} }
{% if fun|noutputs %}
// assign the outputs into the bridge // assign the outputs into the bridge
{% if not fun.rtp|void %} {% if not fun.rtp|void %}
outputs[0] = retval; outputs[0] = retval;
...@@ -70,5 +73,6 @@ ...@@ -70,5 +73,6 @@
{% for opt in fun.opt|outputs %} {% for opt in fun.opt|outputs %}
outputs[{{loop.index0 + fun.rtp|void|not + fun.req|outputs|length}}] = {{opt.name}}; outputs[{{loop.index0 + fun.rtp|void|not + fun.req|outputs|length}}] = {{opt.name}};
{% endfor %} {% endfor %}
{% endif %}
{% endmacro %} {% endmacro %}
...@@ -26,26 +26,29 @@ using namespace cv; ...@@ -26,26 +26,29 @@ using namespace cv;
* nrhs - number of input arguments * nrhs - number of input arguments
* prhs - pointers to input arguments * prhs - pointers to input arguments
*/ */
void mexFunction(int nlhs, mxArray* plhs[], void mexFunction(int nlhs, mxArray*{% if fun|noutputs %} plhs[]{% else %}*{% endif %},
int nrhs, const mxArray* prhs[]) { int nrhs, const mxArray*{% if fun|ninputs %} prhs[]{% else %}*{% endif %}) {
// assertions // assertions
conditionalError(nrhs >= {{fun.req|length - fun.req|only|outputs|length}}, "Too few required input arguments specified"); conditionalError(nrhs >= {{fun.req|length - fun.req|only|outputs|length}}, "Too few required input arguments specified");
conditionalError(nrhs <= {{fun.req|length + fun.opt|length - fun.req|only|outputs|length - fun.opt|only|outputs|length}}, "Too many input arguments specified"); conditionalError(nrhs <= {{fun.req|length + fun.opt|length - fun.req|only|outputs|length - fun.opt|only|outputs|length}}, "Too many input arguments specified");
conditionalError(nlhs <= {{ fun.rtp|void|not + fun.req|outputs|length + fun.opt|outputs|length}}, "Too many output arguments specified"); conditionalError(nlhs <= {{ fun.rtp|void|not + fun.req|outputs|length + fun.opt|outputs|length}}, "Too many output arguments specified");
{% if fun|ninputs or fun|noutputs %}
// setup // setup
{% if fun|ninputs %}
std::vector<Bridge> inputs(prhs, prhs+nrhs); std::vector<Bridge> inputs(prhs, prhs+nrhs);
{% set noutputs = fun.rtp|void|not + fun.req|outputs|length + fun.opt|outputs|length %} {% endif -%}
{%- if noutputs %} {%- if fun|noutputs %}
std::vector<Bridge> outputs({{noutputs}}); std::vector<Bridge> outputs({{fun|noutputs}});
{% endif %}
{% endif %} {% endif %}
{{ functional.generate(fun) }} {{ functional.generate(fun) }}
{%- if noutputs %} {%- if fun|noutputs %}
// push the outputs back to matlab // push the outputs back to matlab
for (size_t n = 0; n < nlhs; ++n) { for (size_t n = 0; n < static_cast<size_t>(nlhs); ++n) {
plhs[n] = outputs[n].toMxArray().releaseOwnership(); plhs[n] = outputs[n].toMxArray().releaseOwnership();
} }
{% endif %} {% endif %}
......
This diff is collapsed.
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
* Copyright 2013 The OpenCV Foundation * Copyright 2013 The OpenCV Foundation
*/ */
#include "mex.h" #include "mex.h"
#include "bridge.hpp"
#include <vector> #include <vector>
/* /*
......
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