-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
116 lines (99 loc) · 3.19 KB
/
Copy pathsetup.py
File metadata and controls
116 lines (99 loc) · 3.19 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (C) 2024-2026 Theodore Chang
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import platform
from pathlib import Path
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup
def initialize():
include_dirs = [
"eigen",
"eigen/unsupported",
"mpreal",
"exprtk",
"exprtk-custom-types",
]
library_dirs = []
def add_to_include(target: str):
if not os.path.exists(target):
return
for root, dirs, _ in os.walk(target):
if "include" in dirs:
include_dirs.append(root + "/include")
break
def add_to_library(target: str, header: str):
if not os.path.exists(target):
return
for root, _, files in os.walk(target):
if any(header in file for file in files):
library_dirs.append(root)
break
if "Darwin" == platform.system():
os.environ["CC"] = "gcc-13"
os.environ["CXX"] = "g++-13"
for path in ["/opt/homebrew/Cellar", "/usr/local/Cellar"]:
add_to_include(f"{path}/mpfr")
add_to_include(f"{path}/gmp")
add_to_include(f"{path}/tbb")
add_to_library(f"{path}/mpfr", "libmpfr")
add_to_library(f"{path}/gmp", "libgmp")
add_to_library(f"{path}/tbb", "libtbb")
libraries = ["mpfr", "gmp", "tbb"]
extra = []
# for path in [
# "/usr/lib/libmpfr.a",
# "/usr/lib/x86_64-linux-gnu/libmpfr.a",
# ]:
# if Path(path).exists():
# extra.append(path)
# break
# else:
# libraries.append("mpfr")
#
# for path in [
# "/usr/lib/x86_64-linux-gnu/libgmp.a",
# "/usr/lib64/libgmp.a",
# "/usr/lib/libgmp.a",
# ]:
# if Path(path).exists():
# extra.append(path)
# break
# else:
# libraries.append("gmp")
return Pybind11Extension(
"_pyvpmr",
["src/VPMR.cpp"],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_objects=extra,
define_macros=[("PYVPMR", 1)],
extra_compile_args=["-fPIC"],
)
# noinspection PyTypeChecker
setup(
long_description=(Path(__file__).parent / "README.md")
.read_text(encoding="utf8")
.replace(
"resource/", "https://raw.githubusercontent.com/TLCFEM/vpmr/master/resource/"
),
long_description_content_type="text/markdown",
ext_modules=[
initialize(),
],
cmdclass={"build_ext": build_ext},
zip_safe=False,
packages=["pyvpmr"],
)