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 2 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
8 changes: 5 additions & 3 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
14 changes: 12 additions & 2 deletions bindings/matlab/build_installer.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

function build_installer()

version = '23.1.1';
version = '24.2.2';
ml = ver('MATLAB');
ml = ml.Release(2:end-1);
arch = computer('arch');
Expand All @@ -36,16 +36,26 @@ function build_installer()
if ispc
win = 'true';
unix = 'false';
else
mac = 'false';

elseif isunix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code will return true for both Linux and Mac, therefore the final else clause setting the mac flag will never be reached.

win = 'false';
unix = 'true';
mac = 'false';

else
win = 'false';
unix = 'false';
mac = 'true';
end
f = strrep(f,'__PROJECT_ROOT__',p);
Copy link
Contributor

@Adrian-Stanea Adrian-Stanea Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__REPO-ROOT__ placeholder from bsp.tmpl is not being updated

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,'__APPLE__',mac);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, the bsp.tmpl file needs to include macos in the platform tags.


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if file exists, then delete to avoid warning


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