-
Notifications
You must be signed in to change notification settings - Fork 36
/
mexcompiler.m
102 lines (97 loc) · 2.39 KB
/
mexcompiler.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
93
94
95
96
97
98
99
100
101
102
function [compiler,options] = mexcompiler
% mexcompiler returns the name of the compiler used by mex.
% Written by Tom Minka
compiler = '';
options = struct;
options.vcvarsopts = '';
if ispc
mexopts = fullfile(prefdir,'mexopts.bat');
if ~exist(mexopts,'file')
try
[compiler,options] = getcc;
catch
end
return
end
fid = fopen(mexopts);
while 1
txt = fgetl(fid);
if ~ischar(txt), break, end
if isempty(compiler) && strncmp('rem ',txt,4)
compiler = txt(5:end-8);
elseif ~isempty(strmatch('set ',txt))
txt = txt(5:end);
pos = strfind(txt,'=');
if ~isempty(pos)
pos = pos(1);
field = txt(1:(pos-1));
txt = txt((pos+1):end);
txt = strrep(txt,'%MATLAB%',matlabroot);
options.(field) = txt;
if strcmp(field,'VSINSTALLDIR')
vsinstalldir = txt;
if ~isempty(strmatch(':\Program Files (x86)\',vsinstalldir(2:end)))
% http://msdn.microsoft.com/en-us/library/x4d2c09s(VS.80).aspx
if exist(fullfile(vsinstalldir,'VC','bin','x86_amd64','cl.exe'))
options.vcvarsopts = 'x86_amd64';
else
options.vcvarsopts = 'x86';
end
end
end
end
end
end
fclose(fid);
else
mexopts = fullfile(prefdir,'mexopts.sh');
if ~exist(mexopts,'file')
try
[compiler,options] = getcc;
catch
end
return
end
fid = fopen(mexopts);
while 1
txt = fgetl(fid);
if ~ischar(txt), break, end
if isempty(compiler) && strncmp('rem ',txt,4)
compiler = txt(5:end-8);
else
pos = strfind(txt,'=');
if ~isempty(pos)
pos = pos(1);
field = txt(1:(pos-1));
txt = txt((pos+1):end);
txt = strrep(txt,'%MATLAB%',matlabroot);
options.(field) = txt;
end
end
end
fclose(fid);
end
function [compiler,options] = getcc
% C:\Program Files\MATLAB\R2014a\help\matlab\ref\mex.getcompilerconfigurations.html
cc = mex.getCompilerConfigurations('c','selected');
compiler = cc.ShortName;
options = struct;
options.COMPILER = cc.Details.CompilerExecutable;
options.COMPFLAGS = cc.Details.CompilerFlags;
options.OPTIMFLAGS = cc.Details.OptimizationFlags;
arch = computer('arch');
if strcmpi(cc.Manufacturer,'microsoft')
foldername = cc.Manufacturer;
else
foldername = compiler;
end
options.LIBLOC = fullfile(matlabroot,'extern','lib',arch,foldername);
vsinstalldir = cc.Location;
options.VSINSTALLDIR = vsinstalldir;
if ispc
if strcmpi(arch, 'win64')
options.vcvarsopts = 'x86_amd64';
else
options.vcvarsopts = 'x86';
end
end