-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpolyhcsgsetup.m
92 lines (75 loc) · 2.35 KB
/
mpolyhcsgsetup.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function mpolyhcsgsetup(dodebug, verbose)
% compiles the fpproc mexfunction
%
% Syntax
% mpolyhcsgsetup()
% mpolyhcsgsetup(dodebug)
% mpolyhcsgsetup(dodebug, verbose)
%
% Input
%
% dodebug - flag determines whether to include debugging symbols
%
% verbose - flag determines whether to print compiler output to command
% line
%
% Copyright 2012-2014 Richard Crozier
%
if nargin < 1
dodebug = false;
end
if nargin < 2
verbose = false;
end
if isoctave
cc.Name = 'gcc';
else
try
% First check a C++ compiler is present, and selected
cc = mex.getCompilerConfigurations('C++', 'Selected');
catch
% if the getCompilerConfigurations call fails, try with gcc,
% assuming that we are on windows and perhaps using gnumex
cc.Name = 'gcc';
end
end
% store the current directory
origdir = pwd;
% return to original dir on interruption or completion
OC = onCleanup (@() cd(origdir));
thisfiledir = fullfile (fileparts(which('mpolyhcsgsetup.m')));
% change to the directory where
cd(thisfiledir);
% make architecture specific mex directory if it doesn't already exist
warning off MATLAB:MKDIR:DirectoryExists
mexdir = ['mpolyhcsgsetup_mex_files_for_' computer('arch')];
mkdir (mexdir);
warning on MATLAB:MKDIR:DirectoryExists
cd (mexdir);
% set some common compiler flags, we replace all calls to printf to
% calls to mexPrintf
if dodebug
common_compiler_flags = {'-g', '-D"_MEX_DEBUG"'};
else
common_compiler_flags={};% common_compiler_flags = '-D"printf=mexPrintf"';
end
if verbose
common_compiler_flags = [common_compiler_flags, {'-v'}];
end
libcommands = {'-lpolyhcsg' };
% put all the compiler commands in a cell array
mexcommands = [ common_compiler_flags, ...
{ ...
'../src/mexpolyhedron.cpp', ...
['-I"', fullfile(thisfiledir, 'src') ,'"'], ...
}, ...
libcommands ...
];
if isoctave
mkoctfile('--mex', mexcommands{:});
else
% call mex with the appropriately constructed commands
mex(mexcommands{:});
end
addpath (fullfile (thisfiledir, mexdir));
end