Skip to content

Commit b932cd3

Browse files
committed
Use downloaded include if available
1 parent 75c8cd4 commit b932cd3

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Instead, you can download the source, the dependencies, and build yourself. This
2727

2828
## How to Use
2929

30-
1. Add this folder to your MATLAB path recursively
30+
1. Add the liblsl-Matlab folder to your MATLAB path recursively
3131
* Using the MATLAB GUI, use File/Set Path...
3232
* Alternatively, in a script, use `addpath(genpath('path/to/liblsl-Matlab'));`
3333
2. Load the library then call a function.

build_mex.m

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
% For Octave on Linux, you need the package liboctave-dev installed
33
% You also need the liblsl64 binary in the bin folder and a configured
44
% C compiler (mex -setup)
5-
libs = {};
5+
6+
orig_path = pwd(); % Will change back to this when done.
7+
ext = ['.' mexext];
8+
script_dir = fileparts(mfilename('fullpath'));
9+
files = dir('mex/*.c');
10+
11+
% Find liblsl, possibly downloading it if it can't be found locally.
612
lsl_fname = lsl_get_dll();
13+
14+
% Build cell array of libray dependencies (liblsl and maybe others)
15+
libs = {};
716
if contains(lsl_fname, '32')
817
libs{end+1} = '-llsl32';
918
elseif contains(lsl_fname, '64')
@@ -15,25 +24,29 @@
1524
libs{end+1} = '-ldl';
1625
end
1726

18-
ext = ['.' mexext];
19-
20-
files = dir('mex/*.c');
27+
% Find liblsl headers. If liblsl was downloaded above then check there.
28+
% Otherwise assume they are in a sister directory.
29+
if exist(fullfile(script_dir, 'bin', 'liblsl_archive', 'include'), 'dir')
30+
incl_dir = fullfile(script_dir, 'bin', 'liblsl_archive', 'include');
31+
else
32+
incl_dir = fullfile(script_dir, '..', 'liblsl', 'include');
33+
end
2134

22-
orig_path = pwd();
2335
disp('Building mex files. This may take a few minutes.');
24-
binarypath = fullfile(fileparts(mfilename('fullpath')), 'bin');
36+
binarypath = fullfile(script_dir, 'bin');
2537
cd(binarypath);
2638
for i = 1:length(files)
2739
f = files(i);
2840
[~, base, ~] = fileparts(f.name);
2941
targetstats = dir([base, ext]);
3042
if isempty(targetstats) || f.datenum > targetstats.datenum
31-
mex('-I../../liblsl/include','-L.', libs{:}, ['../mex/', f.name]);
43+
mex(['-I', incl_dir], '-L.', libs{:}, ['../mex/', f.name]);
3244
else
3345
disp([base, ext, ' up to date']);
3446
end
3547
end
3648
if ismac
3749
system('install_name_tool -add_rpath "@loader_path/" lsl_loadlib_.mexmaci64')
3850
end
51+
3952
cd(orig_path);

lsl_get_dll.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,12 @@
6363
LIBLSL_TAG = 'v1.14.0';
6464
LIBLSL_VER = '1.14.0';
6565
liblsl_url = ['https://github.com/sccn/liblsl/releases/download/' LIBLSL_TAG '/'];
66-
if ispc
67-
if strcmpi(bitness, '64')
68-
arch_suffix = '_amd64';
69-
else
70-
arch_suffix = '_i386';
71-
end
72-
liblsl_url_fname = ['liblsl-' LIBLSL_VER '-Win' arch_suffix '.zip'];
66+
if ispc && contains(computer,'64')
67+
liblsl_url_fname = ['liblsl-' LIBLSL_VER '-Win_amd64.zip'];
68+
elseif ispc
69+
liblsl_url_fname = ['liblsl-' LIBLSL_VER '-Win_i386.zip'];
7370
elseif ismac
7471
liblsl_url_fname = ['liblsl-' LIBLSL_VER '-OSX_amd64.tar.bz2'];
75-
7672
elseif isunix
7773
liblsl_url_fname = ['liblsl-' LIBLSL_VER '-focal_amd64.deb'];
7874
end

0 commit comments

Comments
 (0)