@@ -11,6 +11,14 @@ def _parse_csv_env(name, default_value):
1111 return [item .strip () for item in raw .split ("," ) if item .strip ()]
1212
1313
14+ def _parse_path_env (name ):
15+ raw = os .environ .get (name , "" )
16+ if not raw :
17+ return []
18+ normalized = raw .replace ("," , os .pathsep )
19+ return [item .strip () for item in normalized .split (os .pathsep ) if item .strip ()]
20+
21+
1422sources = [
1523 "easysba/_easysba.cpp" ,
1624 "src/sba_chkjac.c" ,
@@ -22,6 +30,26 @@ def _parse_csv_env(name, default_value):
2230
2331libraries = _parse_csv_env ("EASYSBA_LAPACK_LIBS" , "lapack,blas" )
2432
33+ include_dirs = [pybind11 .get_include (), "src" ]
34+ library_dirs = []
35+ extra_link_args = []
36+
37+ include_dirs .extend (_parse_path_env ("EASYSBA_INCLUDE_DIRS" ))
38+ library_dirs .extend (_parse_path_env ("EASYSBA_LIBRARY_DIRS" ))
39+
40+ if sys .platform == "darwin" and not library_dirs :
41+ for prefix in ("/opt/homebrew/opt/openblas" , "/usr/local/opt/openblas" ):
42+ inc = os .path .join (prefix , "include" )
43+ lib = os .path .join (prefix , "lib" )
44+ if os .path .isdir (lib ):
45+ if os .path .isdir (inc ):
46+ include_dirs .append (inc )
47+ library_dirs .append (lib )
48+
49+ if sys .platform == "darwin" :
50+ for libdir in library_dirs :
51+ extra_link_args .append (f"-Wl,-rpath,{ libdir } " )
52+
2553extra_compile_args = []
2654if sys .platform == "win32" :
2755 extra_compile_args .extend (["/O2" ])
@@ -34,10 +62,12 @@ def _parse_csv_env(name, default_value):
3462 Extension (
3563 "easysba._easysba" ,
3664 sources = sources ,
37- include_dirs = [ pybind11 . get_include (), "src" ] ,
65+ include_dirs = include_dirs ,
3866 language = "c++" ,
3967 libraries = libraries ,
68+ library_dirs = library_dirs ,
4069 extra_compile_args = extra_compile_args ,
70+ extra_link_args = extra_link_args ,
4171 )
4272]
4373
0 commit comments