-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
90 lines (71 loc) · 2.43 KB
/
setup.py
File metadata and controls
90 lines (71 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import sys
from setuptools import Extension, setup
import pybind11
def _parse_csv_env(name, default_value):
raw = os.environ.get(name, default_value)
return [item.strip() for item in raw.split(",") if item.strip()]
def _parse_path_env(name):
raw = os.environ.get(name, "")
if not raw:
return []
normalized = raw.replace(",", os.pathsep)
return [item.strip() for item in normalized.split(os.pathsep) if item.strip()]
sources = [
"easysba/_easysba.cpp",
"src/sba_chkjac.c",
"src/sba_crsm.c",
"src/sba_lapack.c",
"src/sba_levmar.c",
"src/sba_levmar_wrap.c",
]
libraries = _parse_csv_env("EASYSBA_LAPACK_LIBS", "lapack,blas")
include_dirs = [pybind11.get_include(), "src"]
library_dirs = []
extra_link_args = []
include_dirs.extend(_parse_path_env("EASYSBA_INCLUDE_DIRS"))
library_dirs.extend(_parse_path_env("EASYSBA_LIBRARY_DIRS"))
use_accelerate = sys.platform == "darwin" and os.environ.get("EASYSBA_USE_ACCELERATE") == "1"
if use_accelerate:
libraries = []
extra_link_args.extend(["-framework", "Accelerate"])
if sys.platform == "darwin" and not library_dirs and not use_accelerate:
for prefix in ("/opt/homebrew/opt/openblas", "/usr/local/opt/openblas"):
inc = os.path.join(prefix, "include")
lib = os.path.join(prefix, "lib")
if os.path.isdir(lib):
if os.path.isdir(inc):
include_dirs.append(inc)
library_dirs.append(lib)
if sys.platform == "darwin" and not use_accelerate:
for libdir in library_dirs:
extra_link_args.append(f"-Wl,-rpath,{libdir}")
# if sys.platform == "win32":
# for libdir in library_dirs:
# extra_link_args.append(f"/LIBPATH:{libdir}")
extra_compile_args = []
if sys.platform == "win32":
# Remove the manual /LIBPATH addition, setuptools handles library_dirs
extra_compile_args.extend(["/O2"])
else:
extra_compile_args.extend(["-O3"])
extra_compile_args.extend(_parse_csv_env("EASYSBA_EXTRA_COMPILE_ARGS", ""))
ext_modules = [
Extension(
"easysba._easysba",
sources=sources,
include_dirs=include_dirs,
language="c++",
libraries=libraries,
library_dirs=library_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
]
setup(
name="easysba",
version="0.1.0",
description="Python bindings for easySBA",
packages=["easysba"],
ext_modules=ext_modules,
)