Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matlabBindings: add macos support #382

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/matlab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ Always install the latest release for your MATLAB version from the [releases pag
|:-------:|:-------:|:-------------------:|
| Windows 10 | R2024b |[Matlab Add-On](https://uk.mathworks.com/matlabcentral/fileexchange/74385-libm2k-matlab?s_tid=srchtitle_libm2k_1)|
| Linux | R2024b | [Matlab Add-On](https://uk.mathworks.com/matlabcentral/fileexchange/74385-libm2k-matlab?s_tid=srchtitle_libm2k_1) |
| Macos x86_64 | R2024b | [Release link](https://github.com/analogdevicesinc/libm2k-matlab/releases/tag/v24.2.2) |
| Macos arm64 | R2024b | [Release link](https://github.com/analogdevicesinc/libm2k-matlab/releases/tag/v24.2.2) |
11 changes: 6 additions & 5 deletions bindings/matlab/bsp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
<param.platforms />
<param.guid>9f0bd333-fc8b-4cf0-be27-c48b576ae1c0</param.guid>
<param.exclude.filters>%
CI/*
test/*
*~
CI/*
test/*
*~
*.m
*.tmpl
.Xil/*</param.exclude.filters>
<param.exclude.pcodedmfiles>true</param.exclude.pcodedmfiles>
<param.examples />
Expand Down Expand Up @@ -131,7 +133,7 @@ test/*
</matlab>
<platform>
<unix>__LINUX__</unix>
<mac>false</mac>
<mac>__MAC_OS__</mac>
<windows>__WINDOWS__</windows>
<win2k>false</win2k>
<winxp>false</winxp>
Expand All @@ -141,7 +143,6 @@ test/*
<osver>4.15.0-34-generic</osver>
<os32>false</os32>
<os64>true</os64>
<arch>__ARCH__</arch>
<matlab>true</matlab>
</platform>
</configuration>
Expand Down
25 changes: 18 additions & 7 deletions bindings/matlab/build_installer.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@

function build_installer()

version = '23.1.1';
version = '24.2.2';
ml = ver('MATLAB');
ml = ml.Release(2:end-1);
arch = computer('arch');

%%
cd(fileparts((mfilename('fullpath'))));
Expand All @@ -33,19 +32,31 @@ function build_installer()
f=fread(fid,'*char')';
fclose(fid);

if ispc
% this affects system compatibility for the mltbx package
win = 'false';
unix = 'false';
mac = 'false';

if isfile(fullfile(p, 'libm2k', 'libm2kInterface.dll'))
win = 'true';
unix = 'false';
else
win = 'false';
end

if isfile(fullfile(p, 'libm2k', 'libm2kInterface.so'))
unix = 'true';
end

if isfile(fullfile(p, 'libm2k', 'libm2kInterface.dylib'))
mac = 'true';
end


f = strrep(f,'__PROJECT_ROOT__',p);
f = strrep(f,'__REPO-ROOT__',p);
f = strrep(f,'__VERSION__',version);
f = strrep(f,'__ML-RELEASE__',ml);
f = strrep(f,'__ARCH__',arch);
f = strrep(f,'__LINUX__',unix);
f = strrep(f,'__WINDOWS__',win);
f = strrep(f,'__MAC_OS__',mac);

fid = fopen('bsp.prj','w');
fprintf(fid,'%s',f);
Expand Down
134 changes: 88 additions & 46 deletions bindings/matlab/build_library.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,111 @@
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%

clear all; clc;
clear all; % clc;

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

includepath = fullfile(pwd, 'libm2k', 'include');
hppPath = fullfile(pwd, 'libm2k', 'include', 'libm2k');

%%
% Full path to files in the library
if isunix
hppPath = fullfile('/usr','local','include','libm2k');
libs = fullfile('/usr','local','lib','libm2k.so');
myPkg = 'libm2k';
% check if we have an unix based system but not macos
if isunix && not(ismac)
% Full path to files in the library
libs = fullfile(pwd, 'libm2k', 'libm2k.so');
myPkg = 'libm2k';

elseif ismac
% on mac pc we need to specify the compiler
mex -setup C++
libs = fullfile(pwd, 'libm2k', 'libm2k.dylib');
myPkg = 'libm2k';

elseif ispc
% on windows pc we need to specify the compiler
mex -setup C++ -v
% Full path to files in the library
libs = fullfile(pwd, 'libm2k', 'libm2k.lib');
myPkg = 'libm2k';

else
error('Unix builds only tested so far');
error('Build did not find any recognized system');
end

%% Add related headers
h = {};

h1 = fullfile(hppPath,'m2kcalibration.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'m2kexceptions.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'logger.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'digital','genericdigital.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'digital','m2kdigital.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'analog','m2kanalogout.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'analog','m2kanalogin.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'m2kcalibration.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'analog','m2khardwaretrigger.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'analog','m2kpowersupply.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'analog','powersupply.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'utils','utils.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'utils','enums.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'contextbuilder.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'m2k.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'context.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'m2kglobal.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'digital','enums.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'analog','enums.hpp'); h = [{h1},h(:)'];
h1 = fullfile(hppPath,'enums.hpp'); h = [{h1},h(:)'];
h1 = fullfile('/usr','include','iio.h'); h = [{h1},h(:)'];
h1 = fullfile(hppPath, 'digital', 'm2kdigital.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'digital', 'enums.hpp'); h = [{h1}, h(:)'];

h1 = fullfile(hppPath, 'analog', 'm2kanalogout.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'analog', 'm2kanalogin.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'analog', 'm2kpowersupply.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'analog', 'dmm.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'analog', 'enums.hpp'); h = [{h1}, h(:)'];

h1 = fullfile(hppPath, 'utils', 'utils.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'utils', 'enums.hpp'); h = [{h1}, h(:)'];

h1 = fullfile(hppPath, 'm2khardwaretrigger.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'contextbuilder.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'm2k.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'm2kglobal.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'context.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'logger.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'm2kcalibration.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'm2kexceptions.hpp'); h = [{h1}, h(:)'];
h1 = fullfile(hppPath, 'enums.hpp'); h = [{h1}, h(:)'];
headers = h;

%% Build interface file
clibgen.generateLibraryDefinition(headers,...
'IncludePath', hppPath,...
'Libraries', libs,...
'PackageName', myPkg,...
'Verbose',true)
delete definelibm2k.mlx

%% Build library once manually updated
% pkg = definelibm2k;
% build(pkg);








% delete definelibm2k.m

if isunix && not(ismac)
clibgen.generateLibraryDefinition(headers, ...
'IncludePath', includepath, ...
'Libraries', libs, ...
'PackageName', myPkg, ...
'Verbose', true)
delete definelibm2k.mlx

elseif ismac
%% Add 'DefinedMacros' to fix bugs related to compiler versions used by matlab
clibgen.generateLibraryDefinition(headers, ...
'IncludePath', includepath, ...
'Libraries', libs, ...
'InterfaceName', myPkg, ...
'Verbose', true, ...
'DefinedMacros', ["_HAS_CONDITIONAL_EXPLICIT=0", "_USE_EXTENDED_LOCALES_"])
delete definelibm2k.mlx

elseif ispc
%% Add 'DefinedMacros' to fix builds using Visual Studio 16 2019
clibgen.generateLibraryDefinition(headers, ...
'IncludePath', includepath, ...
'Libraries', libs, ...
'PackageName', myPkg, ...
'Verbose', true, ...
'DefinedMacros', ["_HAS_CONDITIONAL_EXPLICIT=0"])
delete definelibm2k.mlx
end

if isunix && not(ismac)
pkg = definelibm2k_linux64;

elseif ismac
if strcmp(computer('arch'), 'maca64')
pkg = definelibm2k_macM1;
else
pkg = definelibm2k_mac86;
end

elseif ispc
pkg = definelibm2k_win64;
end

%% Build library once manually updated
% build(pkg);
110 changes: 0 additions & 110 deletions bindings/matlab/build_library_linux64.m

This file was deleted.

Loading