-
Notifications
You must be signed in to change notification settings - Fork 28
/
setup.py
76 lines (61 loc) · 1.71 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
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
from pybind11.setup_helpers import Pybind11Extension
from setuptools import setup
import ctypes as ct # to call native
import ctypes.util as ctu
import platform # to learn the OS we're on
extra_compile_args = [
"-Ilibs",
"-Ilibs/third_party",
"-Iinclude",
"-Iqasmtools/include",
"-Ipystaq/include",
"-I/opt/homebrew/include",
]
extra_links_args = []
def _load_shared_obj(name):
"""Attempts to load shared library."""
paths = []
# search typical locations
try:
paths += [ctu.find_library(name)]
except FileNotFoundError:
pass
try:
paths += [ctu.find_library("lib" + name)]
except FileNotFoundError:
pass
dll = ct.windll if platform.system() == "Windows" else ct.cdll
for path in paths:
if path:
lib = dll.LoadLibrary(path)
return lib
raise RuntimeError("No " + name + " shared libraries found")
found_GMP = True
try:
_libgmp = _load_shared_obj("gmp")
_libgmpxx = _load_shared_obj("gmpxx")
except Exception:
found_GMP = False
if found_GMP:
extra_compile_args.append("-DGRID_SYNTH")
extra_compile_args.append("-DEXPR_GMP")
extra_links_args = ["-lgmp", "-lgmpxx"]
# If the platform seem to be MSVC
if (
sys.platform == "win32"
and not sys.platform == "cygwin"
and not sys.platform == "msys"
):
extra_compile_args.append("-Ilibs/third_party/pthreadwin32")
ext_modules = [
Pybind11Extension(
"pystaq",
["pystaq/staq_wrapper.cpp"],
extra_compile_args=extra_compile_args,
extra_link_args=extra_links_args,
cxx_std=17,
include_pybind11=False,
),
]
setup(platforms=sys.platform, ext_modules=ext_modules)