From 96a0f8e7126a8f7fd93143c29bf0cc4f5daf84f8 Mon Sep 17 00:00:00 2001 From: IonutMuthi Date: Fri, 7 Feb 2025 04:11:23 -0500 Subject: [PATCH] matlabBindings: update interface generation Signed-off-by: IonutMuthi --- bindings/matlab/build_library.m | 110 ++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 49 deletions(-) diff --git a/bindings/matlab/build_library.m b/bindings/matlab/build_library.m index 1aa07db9..20bb1038 100644 --- a/bindings/matlab/build_library.m +++ b/bindings/matlab/build_library.m @@ -32,21 +32,26 @@ % 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'; + libs = fullfile(pwd, 'libm2k/linux', 'libm2k.so'); + myPkg = 'libm2k_linux'; elseif ismac % on mac pc we need to specify the compiler mex -setup C++ - libs = fullfile(pwd, 'libm2k', 'libm2k.dylib'); - myPkg = 'libm2k'; + if strcmp(system('arch'), 'arma64') + libs = fullfile(pwd, 'libm2k/mac_arm64', 'libm2k.dylib'); + myPkg = 'libm2k_mac_arm64'; + else + libs = fullfile(pwd, 'libm2k/mac_x86_64', 'libm2k.dylib'); + myPkg = 'libm2k_mac_x86_64'; + end 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'; + myPkg = 'libm2k_windows'; else error('Build did not find any recognized system'); @@ -78,51 +83,58 @@ h1 = fullfile(hppPath, 'enums.hpp'); h = [{h1}, h(:)']; headers = h; -%% Build interface file -% 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; +% first run this variable is 1 after you manually update the define file +% set it to 0 +isBuildInterface = 1; + +if isBuildInterface + %% Build interface file + if isunix && not(ismac) + % delete definelibm2k_linux.m + clibgen.generateLibraryDefinition(headers, ... + 'IncludePath', includepath, ... + 'Libraries', libs, ... + 'PackageName', myPkg, ... + 'Verbose', true) + delete definelibm2k_linux.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 +else + %% Build library once manually updated + if isunix && not(ismac) + pkg = definelibm2k_linux; + + elseif ismac + if strcmp(computer('arch'), 'maca64') + pkg = definelibm2k_macM1; + else + pkg = definelibm2k_mac86; + end + + elseif ispc + pkg = definelibm2k_win64; + end + + build(pkg); -elseif ispc - pkg = definelibm2k_win64; end - -%% Build library once manually updated -% build(pkg);