|
| 1 | +import os |
1 | 2 | import platform
|
2 | 3 | from datetime import datetime
|
3 | 4 | from pathlib import Path
|
4 | 5 |
|
5 | 6 | from pybind11.setup_helpers import Pybind11Extension, build_ext
|
6 | 7 | from setuptools import setup
|
7 | 8 |
|
| 9 | +if "Darwin" == platform.system(): |
| 10 | + os.environ["CC"] = "gcc-13" |
| 11 | + os.environ["CXX"] = "g++-13" |
| 12 | + |
| 13 | +include_dirs = [ |
| 14 | + "eigen", |
| 15 | + "eigen/unsupported", |
| 16 | + "mpreal", |
| 17 | + "exprtk", |
| 18 | + "exprtk-custom-types", |
| 19 | +] |
| 20 | + |
| 21 | +library_dirs = [] |
| 22 | + |
| 23 | + |
| 24 | +def add_to_include(target: str): |
| 25 | + if not os.path.exists(target): |
| 26 | + return |
| 27 | + |
| 28 | + for root, dirs, _ in os.walk(target): |
| 29 | + if "include" in dirs: |
| 30 | + include_dirs.append(root + "/include") |
| 31 | + break |
| 32 | + |
| 33 | + |
| 34 | +def add_to_library(target: str, header: str): |
| 35 | + if not os.path.exists(target): |
| 36 | + return |
| 37 | + |
| 38 | + for root, _, files in os.walk(target): |
| 39 | + if any(header in file for file in files): |
| 40 | + library_dirs.append(root) |
| 41 | + break |
| 42 | + |
| 43 | + |
| 44 | +for root in ["/opt/homebrew/Cellar", "/usr/local/Cellar"]: |
| 45 | + add_to_include(f"{root}/mpfr") |
| 46 | + add_to_include(f"{root}/gmp") |
| 47 | + add_to_include(f"{root}/tbb") |
| 48 | + |
| 49 | + add_to_library(f"{root}/mpfr", "libmpfr") |
| 50 | + add_to_library(f"{root}/gmp", "libgmp") |
| 51 | + add_to_library(f"{root}/tbb", "libtbb") |
| 52 | + |
8 | 53 | # noinspection PyTypeChecker
|
9 | 54 | setup(
|
10 | 55 | version=datetime.now().strftime("%y%m%d"),
|
|
18 | 63 | Pybind11Extension(
|
19 | 64 | "_pyvpmr",
|
20 | 65 | ["src/VPMR.cpp"],
|
21 |
| - include_dirs=[ |
22 |
| - "eigen", |
23 |
| - "eigen/unsupported", |
24 |
| - "mpreal", |
25 |
| - "exprtk", |
26 |
| - "exprtk-custom-types", |
27 |
| - ], |
| 66 | + include_dirs=include_dirs, |
| 67 | + library_dirs=library_dirs, |
28 | 68 | libraries=["mpfr", "gmp", "tbb"],
|
29 | 69 | define_macros=[("PYVPMR", 1)],
|
30 |
| - extra_compile_args=["-fno-aligned-allocation"] |
31 |
| - if "Darwin" == platform.system() |
32 |
| - else [], |
33 | 70 | ),
|
34 | 71 | ],
|
35 | 72 | cmdclass={"build_ext": build_ext},
|
|
0 commit comments