From ce4d872c32c5637dc6f67335d8e11bf42d4fcf3f Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 2 Oct 2023 14:22:06 -0400 Subject: [PATCH 1/2] support for Apple Silicon --- cmake/MatlabWrap.cmake | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cmake/MatlabWrap.cmake b/cmake/MatlabWrap.cmake index c45d8c0..55b7cdb 100644 --- a/cmake/MatlabWrap.cmake +++ b/cmake/MatlabWrap.cmake @@ -105,7 +105,12 @@ function(wrap_library_internal interfaceHeader moduleName linkLibraries extraInc set(mexModuleExt mexglx) endif() elseif(APPLE) - set(mexModuleExt mexmaci64) + check_cxx_compiler_flag("-arch arm64" arm64Supported) + if (arm64Supported) + set(mexModuleExt mexmaca64) + else() + set(mexModuleExt mexmaci64) + endif() elseif(MSVC) if(CMAKE_CL_64) set(mexModuleExt mexw64) @@ -299,7 +304,12 @@ function(wrap_library_internal interfaceHeader moduleName linkLibraries extraInc APPEND PROPERTY COMPILE_FLAGS "/bigobj") elseif(APPLE) - set(mxLibPath "${MATLAB_ROOT}/bin/maci64") + check_cxx_compiler_flag("-arch arm64" arm64Supported) + if (arm64Supported) + set(mxLibPath "${MATLAB_ROOT}/bin/maca64") + else() + set(mxLibPath "${MATLAB_ROOT}/bin/maci64") + endif() target_link_libraries( ${moduleName}_matlab_wrapper "${mxLibPath}/libmex.dylib" "${mxLibPath}/libmx.dylib" "${mxLibPath}/libmat.dylib") @@ -367,7 +377,12 @@ function(check_conflicting_libraries_internal libraries) if(UNIX) # Set path for matlab's built-in libraries if(APPLE) - set(mxLibPath "${MATLAB_ROOT}/bin/maci64") + check_cxx_compiler_flag("-arch arm64" arm64Supported) + if (arm64Supported) + set(mxLibPath "${MATLAB_ROOT}/bin/maca64") + else() + set(mxLibPath "${MATLAB_ROOT}/bin/maci64") + endif() else() if(CMAKE_CL_64) set(mxLibPath "${MATLAB_ROOT}/bin/glnxa64") From 1467cf23ab789f7955ceb77f357be80f48b86f4b Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 2 Oct 2023 14:22:54 -0400 Subject: [PATCH 2/2] small improvements to Matlab wrapper --- gtwrap/matlab_wrapper/wrapper.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gtwrap/matlab_wrapper/wrapper.py b/gtwrap/matlab_wrapper/wrapper.py index 146209c..9cd367c 100755 --- a/gtwrap/matlab_wrapper/wrapper.py +++ b/gtwrap/matlab_wrapper/wrapper.py @@ -1284,7 +1284,8 @@ def _collector_return(self, [instantiated_class.name]) else: # Get the full namespace - class_name = ".".join(instantiated_class.parent.full_namespaces()[1:]) + class_name = ".".join( + instantiated_class.parent.full_namespaces()[1:]) if class_name != "": class_name += '.' @@ -1860,6 +1861,7 @@ def generate_content(self, cc_content, path): """ for c in cc_content: if isinstance(c, list): + # c is a namespace if len(c) == 0: continue @@ -1875,6 +1877,7 @@ def generate_content(self, cc_content, path): self.generate_content(sub_content[1], path_to_folder) elif isinstance(c[1], list): + # c is a wrapped function path_to_folder = osp.join(path, c[0]) if not osp.isdir(path_to_folder): @@ -1882,11 +1885,13 @@ def generate_content(self, cc_content, path): os.makedirs(path_to_folder, exist_ok=True) except OSError: pass + for sub_content in c[1]: path_to_file = osp.join(path_to_folder, sub_content[0]) with open(path_to_file, 'w') as f: f.write(sub_content[1]) else: + # c is a wrapped class path_to_file = osp.join(path, c[0]) if not osp.isdir(path_to_file): @@ -1921,6 +1926,8 @@ def wrap(self, files, path): for module in modules.values(): # Wrap the full namespace self.wrap_namespace(module) + + # Generate the wrapping code (both C++ and .m files) self.generate_wrapper(module) # Generate the corresponding .m and .cpp files