-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
63 lines (51 loc) · 1.62 KB
/
setup.py
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
"""setup for piqtree."""
import os
import platform
import subprocess
from pathlib import Path
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup
LIBRARY_DIR = "src/piqtree/_libiqtree"
def get_brew_prefix(package: str) -> Path:
"""Get the prefix path for a specific Homebrew package."""
return Path(
subprocess.check_output(["brew", "--prefix", package]).strip().decode("utf-8"),
)
if platform.system() == "Darwin":
brew_prefix_llvm = get_brew_prefix("llvm")
brew_prefix_libomp = get_brew_prefix("libomp")
# Use Homebrew's clang/clang++
os.environ["CC"] = str(brew_prefix_llvm / "bin" / "clang")
os.environ["CXX"] = str(brew_prefix_llvm / "bin" / "clang++")
# Define OpenMP flags and libraries for macOS
openmp_flags = ["-Xpreprocessor", "-fopenmp"]
openmp_libs = ["omp"]
# Use the paths from Homebrew for libomp
openmp_include = str(brew_prefix_libomp / "include")
library_dirs = [
str(brew_prefix_libomp / "lib"),
str(brew_prefix_llvm / "lib"),
]
else:
openmp_flags = ["-fopenmp"]
openmp_libs = ["gomp"]
openmp_include = None
library_dirs = []
ext_modules = [
Pybind11Extension(
"_piqtree",
["src/piqtree/_libiqtree/_piqtree.cpp"],
library_dirs=[
*library_dirs,
LIBRARY_DIR,
],
libraries=["iqtree2", "z", *openmp_libs],
extra_compile_args=openmp_flags,
include_dirs=[openmp_include] if openmp_include else [],
),
]
setup(
ext_modules=ext_modules,
cmdclass={"build_ext": build_ext},
zip_safe=False,
)