template_cvmex_base.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. function mex(varargin)
  2. %CV.MEX compile MEX-function with OpenCV linkages
  3. %
  4. % Usage:
  5. % CV.MEX [options ...] file [file file ...]
  6. %
  7. % Description:
  8. % CV.MEX compiles one or more C/C++ source files into a shared-library
  9. % called a mex-file. This function is equivalent to the builtin MEX
  10. % routine, with the notable exception that it automatically resolves
  11. % OpenCV includes, and links in the OpenCV libraries where appropriate.
  12. % It also forwards the flags used to build OpenCV, so architecture-
  13. % specific optimizations can be used.
  14. %
  15. % CV.MEX is designed to be used in situations where the source(s) you
  16. % are compiling contain OpenCV definitions. In such cases, it streamlines
  17. % the finding and including of appropriate OpenCV libraries.
  18. %
  19. % See also: mex
  20. %
  21. % Copyright {{ time.strftime("%Y", time.localtime()) }} The OpenCV Foundation
  22. %
  23. % forward the OpenCV build flags (C++ only)
  24. EXTRA_FLAGS = ['"CXXFLAGS="\$CXXFLAGS '...
  25. '{{ cv.flags | trim | wordwrap(60, false, '\'...\n \'') }}""'];
  26. % add the OpenCV include dirs
  27. INCLUDE_DIRS = {{ cv.include_dirs | split | cellarray | wordwrap(60, false, '...\n ') }};
  28. % add the lib dir (singular in both build tree and install tree)
  29. LIB_DIR = '{{ cv.lib_dir }}';
  30. % add the OpenCV libs. Only the used libs will actually be linked
  31. LIBS = {{ cv.libs | split | cellarray | wordwrap(60, false, '...\n ') }};
  32. % add the mex opts (usually at least -largeArrayDims)
  33. OPTS = {{ cv.opts | split | cellarray | wordwrap(60, false, '...\n ') }};
  34. % merge all of the default options (EXTRA_FLAGS, LIBS, etc) and the options
  35. % and files passed by the user (varargin) into a single cell array
  36. merged = [ {EXTRA_FLAGS}, INCLUDE_DIRS, {LIB_DIR}, LIBS, OPTS, varargin ];
  37. % expand the merged argument list into the builtin mex utility
  38. mex(merged{:});
  39. end