Skip to content

Commit 0d64d7f

Browse files
authored
matlabBindings: add macos support (#382)
* matlabBindings: add macos support Signed-off-by: IonutMuthi <ionut.muthi@analog.com> * matlabBindings: refactor for build library functionaliy and installer template Signed-off-by: IonutMuthi <ionut.muthi@analog.com> * matlabBindings: make mtlbx installer consider multiple os at the same time Signed-off-by: IonutMuthi <ionut.muthi@analog.com> * matlabBindings: add link to release packages Signed-off-by: IonutMuthi <ionut.muthi@analog.com> --------- Signed-off-by: IonutMuthi <ionut.muthi@analog.com>
1 parent d091a94 commit 0d64d7f

File tree

8 files changed

+10006
-264
lines changed

8 files changed

+10006
-264
lines changed

bindings/matlab/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ Always install the latest release for your MATLAB version from the [releases pag
1414
|:-------:|:-------:|:-------------------:|
1515
| Windows 10 | R2024b |[Matlab Add-On](https://uk.mathworks.com/matlabcentral/fileexchange/74385-libm2k-matlab?s_tid=srchtitle_libm2k_1)|
1616
| Linux | R2024b | [Matlab Add-On](https://uk.mathworks.com/matlabcentral/fileexchange/74385-libm2k-matlab?s_tid=srchtitle_libm2k_1) |
17+
| Macos x86_64 | R2024b | [Release link](https://github.com/analogdevicesinc/libm2k-matlab/releases/tag/v24.2.2) |
18+
| Macos arm64 | R2024b | [Release link](https://github.com/analogdevicesinc/libm2k-matlab/releases/tag/v24.2.2) |

bindings/matlab/bsp.tmpl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
<param.platforms />
3434
<param.guid>9f0bd333-fc8b-4cf0-be27-c48b576ae1c0</param.guid>
3535
<param.exclude.filters>%
36-
CI/*
37-
test/*
38-
*~
36+
CI/*
37+
test/*
38+
*~
39+
*.m
40+
*.tmpl
3941
.Xil/*</param.exclude.filters>
4042
<param.exclude.pcodedmfiles>true</param.exclude.pcodedmfiles>
4143
<param.examples />
@@ -131,7 +133,7 @@ test/*
131133
</matlab>
132134
<platform>
133135
<unix>__LINUX__</unix>
134-
<mac>false</mac>
136+
<mac>__MAC_OS__</mac>
135137
<windows>__WINDOWS__</windows>
136138
<win2k>false</win2k>
137139
<winxp>false</winxp>
@@ -141,7 +143,6 @@ test/*
141143
<osver>4.15.0-34-generic</osver>
142144
<os32>false</os32>
143145
<os64>true</os64>
144-
<arch>__ARCH__</arch>
145146
<matlab>true</matlab>
146147
</platform>
147148
</configuration>

bindings/matlab/build_installer.m

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020

2121
function build_installer()
2222

23-
version = '23.1.1';
23+
version = '24.2.2';
2424
ml = ver('MATLAB');
2525
ml = ml.Release(2:end-1);
26-
arch = computer('arch');
2726

2827
%%
2928
cd(fileparts((mfilename('fullpath'))));
@@ -33,19 +32,31 @@ function build_installer()
3332
f=fread(fid,'*char')';
3433
fclose(fid);
3534

36-
if ispc
35+
% this affects system compatibility for the mltbx package
36+
win = 'false';
37+
unix = 'false';
38+
mac = 'false';
39+
40+
if isfile(fullfile(p, 'libm2k', 'libm2kInterface.dll'))
3741
win = 'true';
38-
unix = 'false';
39-
else
40-
win = 'false';
42+
end
43+
44+
if isfile(fullfile(p, 'libm2k', 'libm2kInterface.so'))
4145
unix = 'true';
4246
end
47+
48+
if isfile(fullfile(p, 'libm2k', 'libm2kInterface.dylib'))
49+
mac = 'true';
50+
end
51+
52+
53+
f = strrep(f,'__PROJECT_ROOT__',p);
4354
f = strrep(f,'__REPO-ROOT__',p);
4455
f = strrep(f,'__VERSION__',version);
4556
f = strrep(f,'__ML-RELEASE__',ml);
46-
f = strrep(f,'__ARCH__',arch);
4757
f = strrep(f,'__LINUX__',unix);
4858
f = strrep(f,'__WINDOWS__',win);
59+
f = strrep(f,'__MAC_OS__',mac);
4960

5061
fid = fopen('bsp.prj','w');
5162
fprintf(fid,'%s',f);

bindings/matlab/build_library.m

Lines changed: 88 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,69 +18,111 @@
1818
% along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
%
2020

21-
clear all; clc;
21+
clear all; % clc;
2222

2323
%% MATLAB API Builder
2424
% This script will build the basic template file for the MATLAB bindings
2525
% however since the library processor isn't perfect manual modifications
2626
% need to be done with the generated interface file
2727

28+
includepath = fullfile(pwd, 'libm2k', 'include');
29+
hppPath = fullfile(pwd, 'libm2k', 'include', 'libm2k');
30+
2831
%%
29-
% Full path to files in the library
30-
if isunix
31-
hppPath = fullfile('/usr','local','include','libm2k');
32-
libs = fullfile('/usr','local','lib','libm2k.so');
33-
myPkg = 'libm2k';
32+
% check if we have an unix based system but not macos
33+
if isunix && not(ismac)
34+
% Full path to files in the library
35+
libs = fullfile(pwd, 'libm2k', 'libm2k.so');
36+
myPkg = 'libm2k';
37+
38+
elseif ismac
39+
% on mac pc we need to specify the compiler
40+
mex -setup C++
41+
libs = fullfile(pwd, 'libm2k', 'libm2k.dylib');
42+
myPkg = 'libm2k';
43+
44+
elseif ispc
45+
% on windows pc we need to specify the compiler
46+
mex -setup C++ -v
47+
% Full path to files in the library
48+
libs = fullfile(pwd, 'libm2k', 'libm2k.lib');
49+
myPkg = 'libm2k';
50+
3451
else
35-
error('Unix builds only tested so far');
52+
error('Build did not find any recognized system');
3653
end
3754

3855
%% Add related headers
3956
h = {};
4057

41-
h1 = fullfile(hppPath,'m2kcalibration.hpp'); h = [{h1},h(:)'];
42-
h1 = fullfile(hppPath,'m2kexceptions.hpp'); h = [{h1},h(:)'];
43-
h1 = fullfile(hppPath,'logger.hpp'); h = [{h1},h(:)'];
44-
h1 = fullfile(hppPath,'digital','genericdigital.hpp'); h = [{h1},h(:)'];
45-
h1 = fullfile(hppPath,'digital','m2kdigital.hpp'); h = [{h1},h(:)'];
46-
h1 = fullfile(hppPath,'analog','m2kanalogout.hpp'); h = [{h1},h(:)'];
47-
h1 = fullfile(hppPath,'analog','m2kanalogin.hpp'); h = [{h1},h(:)'];
48-
h1 = fullfile(hppPath,'m2kcalibration.hpp'); h = [{h1},h(:)'];
49-
h1 = fullfile(hppPath,'analog','m2khardwaretrigger.hpp'); h = [{h1},h(:)'];
50-
h1 = fullfile(hppPath,'analog','m2kpowersupply.hpp'); h = [{h1},h(:)'];
51-
h1 = fullfile(hppPath,'analog','powersupply.hpp'); h = [{h1},h(:)'];
52-
h1 = fullfile(hppPath,'utils','utils.hpp'); h = [{h1},h(:)'];
53-
h1 = fullfile(hppPath,'utils','enums.hpp'); h = [{h1},h(:)'];
54-
h1 = fullfile(hppPath,'contextbuilder.hpp'); h = [{h1},h(:)'];
55-
h1 = fullfile(hppPath,'m2k.hpp'); h = [{h1},h(:)'];
56-
h1 = fullfile(hppPath,'context.hpp'); h = [{h1},h(:)'];
57-
h1 = fullfile(hppPath,'m2kglobal.hpp'); h = [{h1},h(:)'];
58-
h1 = fullfile(hppPath,'digital','enums.hpp'); h = [{h1},h(:)'];
59-
h1 = fullfile(hppPath,'analog','enums.hpp'); h = [{h1},h(:)'];
60-
h1 = fullfile(hppPath,'enums.hpp'); h = [{h1},h(:)'];
61-
h1 = fullfile('/usr','include','iio.h'); h = [{h1},h(:)'];
58+
h1 = fullfile(hppPath, 'digital', 'm2kdigital.hpp'); h = [{h1}, h(:)'];
59+
h1 = fullfile(hppPath, 'digital', 'enums.hpp'); h = [{h1}, h(:)'];
60+
61+
h1 = fullfile(hppPath, 'analog', 'm2kanalogout.hpp'); h = [{h1}, h(:)'];
62+
h1 = fullfile(hppPath, 'analog', 'm2kanalogin.hpp'); h = [{h1}, h(:)'];
63+
h1 = fullfile(hppPath, 'analog', 'm2kpowersupply.hpp'); h = [{h1}, h(:)'];
64+
h1 = fullfile(hppPath, 'analog', 'dmm.hpp'); h = [{h1}, h(:)'];
65+
h1 = fullfile(hppPath, 'analog', 'enums.hpp'); h = [{h1}, h(:)'];
66+
67+
h1 = fullfile(hppPath, 'utils', 'utils.hpp'); h = [{h1}, h(:)'];
68+
h1 = fullfile(hppPath, 'utils', 'enums.hpp'); h = [{h1}, h(:)'];
69+
70+
h1 = fullfile(hppPath, 'm2khardwaretrigger.hpp'); h = [{h1}, h(:)'];
71+
h1 = fullfile(hppPath, 'contextbuilder.hpp'); h = [{h1}, h(:)'];
72+
h1 = fullfile(hppPath, 'm2k.hpp'); h = [{h1}, h(:)'];
73+
h1 = fullfile(hppPath, 'm2kglobal.hpp'); h = [{h1}, h(:)'];
74+
h1 = fullfile(hppPath, 'context.hpp'); h = [{h1}, h(:)'];
75+
h1 = fullfile(hppPath, 'logger.hpp'); h = [{h1}, h(:)'];
76+
h1 = fullfile(hppPath, 'm2kcalibration.hpp'); h = [{h1}, h(:)'];
77+
h1 = fullfile(hppPath, 'm2kexceptions.hpp'); h = [{h1}, h(:)'];
78+
h1 = fullfile(hppPath, 'enums.hpp'); h = [{h1}, h(:)'];
6279
headers = h;
6380

6481
%% Build interface file
65-
clibgen.generateLibraryDefinition(headers,...
66-
'IncludePath', hppPath,...
67-
'Libraries', libs,...
68-
'PackageName', myPkg,...
69-
'Verbose',true)
70-
delete definelibm2k.mlx
71-
72-
%% Build library once manually updated
73-
% pkg = definelibm2k;
74-
% build(pkg);
75-
76-
77-
78-
79-
80-
81-
82-
82+
% delete definelibm2k.m
83+
84+
if isunix && not(ismac)
85+
clibgen.generateLibraryDefinition(headers, ...
86+
'IncludePath', includepath, ...
87+
'Libraries', libs, ...
88+
'PackageName', myPkg, ...
89+
'Verbose', true)
90+
delete definelibm2k.mlx
91+
92+
elseif ismac
93+
%% Add 'DefinedMacros' to fix bugs related to compiler versions used by matlab
94+
clibgen.generateLibraryDefinition(headers, ...
95+
'IncludePath', includepath, ...
96+
'Libraries', libs, ...
97+
'InterfaceName', myPkg, ...
98+
'Verbose', true, ...
99+
'DefinedMacros', ["_HAS_CONDITIONAL_EXPLICIT=0", "_USE_EXTENDED_LOCALES_"])
100+
delete definelibm2k.mlx
101+
102+
elseif ispc
103+
%% Add 'DefinedMacros' to fix builds using Visual Studio 16 2019
104+
clibgen.generateLibraryDefinition(headers, ...
105+
'IncludePath', includepath, ...
106+
'Libraries', libs, ...
107+
'PackageName', myPkg, ...
108+
'Verbose', true, ...
109+
'DefinedMacros', ["_HAS_CONDITIONAL_EXPLICIT=0"])
110+
delete definelibm2k.mlx
111+
end
83112

113+
if isunix && not(ismac)
114+
pkg = definelibm2k_linux64;
84115

116+
elseif ismac
117+
if strcmp(computer('arch'), 'maca64')
118+
pkg = definelibm2k_macM1;
119+
else
120+
pkg = definelibm2k_mac86;
121+
end
85122

123+
elseif ispc
124+
pkg = definelibm2k_win64;
125+
end
86126

127+
%% Build library once manually updated
128+
% build(pkg);

bindings/matlab/build_library_linux64.m

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)