Skip to content

Commit

Permalink
matlabBindings: refactor for build library functionaliy and installer…
Browse files Browse the repository at this point in the history
… template

Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Feb 6, 2025
1 parent b2cbc35 commit 24f0289
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 451 deletions.
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
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.

96 changes: 0 additions & 96 deletions bindings/matlab/build_library_mac86.m

This file was deleted.

Loading

0 comments on commit 24f0289

Please sign in to comment.