11import os
22import platform
3+ import shutil
34import sys
5+ import warnings
46from glob import glob
57from pathlib import Path
68
@@ -108,14 +110,23 @@ def run(self):
108110 f"{ build_py .get_package_dir (PACKAGE_NAME )} /{ obj_name } " )
109111
110112 obj_name = get_shared_object_name (libmatlab [0 ])
111- build_py .copy_file (f"{ build_py .build_lib } /{ PACKAGE_NAME } /{ obj_name } " ,
112- f"{ build_py .get_package_dir (PACKAGE_NAME )} /{ obj_name } " )
113-
113+ matlab_dll_path = Path (build_py .build_lib ) / PACKAGE_NAME / obj_name
114+ if matlab_dll_path .exists ():
115+ build_py .copy_file (matlab_dll_path ,
116+ f"{ build_py .get_package_dir (PACKAGE_NAME )} /{ obj_name } " )
117+
118+ open (f"{ build_py .get_package_dir (PACKAGE_NAME )} /matlab.txt" , 'w' ).close ()
119+
114120
115121class BuildClib (build_clib ):
116122 def initialize_options (self ):
117123 super ().initialize_options ()
118- self .matlab_install_dir = os .environ .get ("MATLAB_INSTALL_DIR" , "" )
124+ matlab_install_dir = os .environ .get ("MATLAB_INSTALL_DIR" )
125+ if matlab_install_dir is None :
126+ matlab_install_dir = shutil .which ("matlab" )
127+ if matlab_install_dir is not None :
128+ matlab_install_dir = Path (matlab_install_dir ).parent .parent .as_posix ()
129+ self .matlab_install_dir = matlab_install_dir
119130 build_py = self .get_finalized_command ("build_py" )
120131 self .build_clib = f"{ build_py .build_lib } /{ PACKAGE_NAME } "
121132
@@ -137,12 +148,12 @@ def build_libraries(self, libraries):
137148 link_libraries = []
138149 link_library_dirs = []
139150
140- if lib_name == libmatlab [0 ] and not self .matlab_install_dir :
141- print ("No MATLAB install dir was not given so the MATLAB integration cannot be built." )
151+ if lib_name == libmatlab [0 ] and self .matlab_install_dir is None :
152+ warnings . warn ("No MATLAB install dir was not given so the MATLAB integration cannot be built." )
142153 del libraries [index ]
143154 continue
144155
145- if self .matlab_install_dir :
156+ if lib_name == libmatlab [ 0 ] and self .matlab_install_dir is not None :
146157 extra_include .append (f"{ self .matlab_install_dir } /extern/include/" )
147158
148159 build_info ["cflags" ] = compile_args
@@ -159,12 +170,13 @@ def build_libraries(self, libraries):
159170 debug = self .debug ,
160171 )
161172 language = self .compiler .detect_language (sources )
162- if self .matlab_install_dir :
163- link_libraries .extend (["libeng" , "libmx" ])
173+ if lib_name == libmatlab [0 ] and self .matlab_install_dir is not None :
164174 if platform .system () == "Windows" :
165- link_library_dirs .append (f"{ self .matlab_install_dir } /bin/win64" )
175+ link_libraries .extend (["libeng" , "libmx" ])
176+ link_library_dirs .append (f"{ self .matlab_install_dir } /extern/lib/win64/microsoft" )
166177 elif platform .system () == "Linux" :
167- link_library_dirs .append (f"{ self .matlab_install_dir } /bin//microsoft" )
178+ link_libraries .extend (["eng" , "mx" ])
179+ link_library_dirs .append (f"{ self .matlab_install_dir } /bin/glnxa64" ))
168180
169181
170182 self .compiler .link_shared_object (
@@ -189,7 +201,7 @@ def build_libraries(self, libraries):
189201 long_description_content_type = "text/markdown" ,
190202 packages = find_packages (),
191203 include_package_data = True ,
192- package_data = {"" : [get_shared_object_name (libevent [0 ]), get_shared_object_name (libmatlab [0 ])], "RATapi.examples" : ["data/*.dat" ]},
204+ package_data = {"" : ["matlab.txt" , get_shared_object_name (libevent [0 ]), get_shared_object_name (libmatlab [0 ])], "RATapi.examples" : ["data/*.dat" ]},
193205 cmdclass = {"build_clib" : BuildClib , "build_ext" : BuildExt },
194206 libraries = [libevent , libmatlab ],
195207 ext_modules = ext_modules ,
@@ -206,12 +218,6 @@ def build_libraries(self, libraries):
206218 ':python_version < "3.11"' : ["StrEnum >= 0.4.15" ],
207219 "Dev" : ["pytest>=7.4.0" , "pytest-cov>=4.1.0" , "ruff>=0.4.10" ],
208220 "Orso" : ["orsopy>=1.2.1" , "pint>=0.24.4" ],
209- "Matlab_latest" : ["matlabengine" ],
210- "Matlab_2025a" : ["matlabengine == 25.1.*" ],
211- "Matlab_2024b" : ["matlabengine == 24.2.2" ],
212- "Matlab_2024a" : ["matlabengine == 24.1.4" ],
213- "Matlab_2023b" : ["matlabengine == 23.2.3" ],
214- "Matlab_2023a" : ["matlabengine == 9.14.3" ],
215221 },
216222 zip_safe = False ,
217223)
0 commit comments