parent
ef2c1e1a24
commit
52dc51a62c
9 changed files with 396 additions and 21 deletions
@ -0,0 +1,58 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
def substitute(cv, output_dir): |
||||
|
||||
# setup the template engine |
||||
template_dir = os.path.join(os.path.dirname(__file__), 'templates') |
||||
jtemplate = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True, lstrip_blocks=True) |
||||
|
||||
# add the filters |
||||
jtemplate.filters['cellarray'] = cellarray |
||||
jtemplate.filters['split'] = split |
||||
jtemplate.filters['csv'] = csv |
||||
|
||||
# load the template |
||||
template = jtemplate.get_template('template_cvmex_base.m') |
||||
|
||||
# create the build directory |
||||
output_dir = output_dir+'/+cv' |
||||
if not os.path.isdir(output_dir): |
||||
os.mkdir(output_dir) |
||||
|
||||
# populate template |
||||
populated = template.render(cv=cv, time=time) |
||||
with open(os.path.join(output_dir, 'mex.m'), 'wb') as f: |
||||
f.write(populated) |
||||
|
||||
if __name__ == "__main__": |
||||
""" |
||||
Usage: python cvmex.py --opts [-list -of -opts] |
||||
--include_dirs [-list -of -opencv_include_directories] |
||||
--lib_dir opencv_lib_directory |
||||
--libs [-lopencv_core -lopencv_imgproc ...] |
||||
--flags [-Wall -opencv_build_flags ...] |
||||
--outdir /path/to/generated/output |
||||
|
||||
cvmex.py generates a custom mex compiler that automatically links OpenCV |
||||
libraries to built sources where appropriate. The calling syntax is the |
||||
same as the builtin mex compiler, with added cv qualification: |
||||
>> cv.mex(..., ...); |
||||
""" |
||||
|
||||
# parse the input options |
||||
import sys, re, os, time |
||||
from argparse import ArgumentParser |
||||
parser = ArgumentParser() |
||||
parser.add_argument('--opts') |
||||
parser.add_argument('--include_dirs') |
||||
parser.add_argument('--lib_dir') |
||||
parser.add_argument('--libs') |
||||
parser.add_argument('--flags') |
||||
parser.add_argument('--outdir') |
||||
cv = parser.parse_args() |
||||
|
||||
from filters import * |
||||
from jinja2 import Environment, FileSystemLoader |
||||
|
||||
# populate the mex base template |
||||
substitute(cv, cv.outdir) |
@ -0,0 +1,46 @@ |
||||
function mex(varargin) |
||||
%CV.MEX compile MEX-function with OpenCV linkages |
||||
% |
||||
% Usage: |
||||
% CV.MEX [options ...] file [file file ...] |
||||
% |
||||
% Description: |
||||
% CV.MEX compiles one or more C/C++ source files into a shared-library |
||||
% called a mex-file. This function is equivalent to the builtin MEX |
||||
% routine, with the notable exception that it automatically resolves |
||||
% OpenCV includes, and links in the OpenCV libraries where appropriate. |
||||
% It also forwards the flags used to build OpenCV, so architecture- |
||||
% specific optimizations can be used. |
||||
% |
||||
% CV.MEX is designed to be used in situations where the source(s) you |
||||
% are compiling contain OpenCV definitions. In such cases, it streamlines |
||||
% the finding and including of appropriate OpenCV libraries. |
||||
% |
||||
% See also: mex |
||||
% |
||||
% Copyright {{ time.strftime("%Y", time.localtime()) }} The OpenCV Foundation |
||||
% |
||||
|
||||
% forward the OpenCV build flags (C++ only) |
||||
EXTRA_FLAGS = ['"CXXFLAGS="\$CXXFLAGS '... |
||||
'{{ cv.flags | trim | wordwrap(60, false, '\'...\n \'') }}""']; |
||||
|
||||
% add the OpenCV include dirs |
||||
INCLUDE_DIRS = {{ cv.include_dirs | split | cellarray | wordwrap(60, false, '...\n ') }}; |
||||
|
||||
% add the lib dir (singular in both build tree and install tree) |
||||
LIB_DIR = '{{ cv.lib_dir }}'; |
||||
|
||||
% add the OpenCV libs. Only the used libs will actually be linked |
||||
LIBS = {{ cv.libs | split | cellarray | wordwrap(60, false, '...\n ') }}; |
||||
|
||||
% add the mex opts (usually at least -largeArrayDims) |
||||
OPTS = {{ cv.opts | split | cellarray | wordwrap(60, false, '...\n ') }}; |
||||
|
||||
% merge all of the default options (EXTRA_FLAGS, LIBS, etc) and the options |
||||
% and files passed by the user (varargin) into a single cell array |
||||
merged = [ {EXTRA_FLAGS}, INCLUDE_DIRS, {LIB_DIR}, LIBS, OPTS, varargin ]; |
||||
|
||||
% expand the merged argument list into the builtin mex utility |
||||
mex(merged{:}); |
||||
end |
Loading…
Reference in new issue