-
Notifications
You must be signed in to change notification settings - Fork 40
/
setup.py
145 lines (130 loc) · 4.48 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright 2024 D-Wave Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import platform
import sys
from Cython.Build import cythonize
from setuptools import setup, Extension
# Change directories so this works when called from other locations.
# Useful in build systems that build from source.
setup_folder_loc = os.path.dirname(os.path.abspath(__file__))
os.chdir(setup_folder_loc)
DEBUG = '--debug' in sys.argv or '-g' in sys.argv or 'CPPDEBUG' in os.environ
SAFE_COORDS = 'SAFE_COORDS' in os.environ
extra_compile_args = []
extra_compile_args_glasgow = [] # specific to glasgow
extra_compile_args_minorminer = [] # specific to minorminer
if platform.system().lower() == "windows":
extra_compile_args.extend([
'/std:c++17',
'/MT',
'/EHsc',
])
extra_compile_args_glasgow.extend([
'/external:W4',
'/external:I external',
'/DUSE_PORTABLE_SNIPPETS_BUILTIN',
])
extra_compile_args_minorminer.extend([
'/DCPPDEBUG' if DEBUG else None,
'/DSAFE_COORDS' if SAFE_COORDS else None,
])
else: # Unix
extra_compile_args.extend([
'-std=c++17',
'-Wall',
'-Wno-format-security',
'--O0' if DEBUG else '-Ofast',
'-fomit-frame-pointer',
'-fipa-pure-const' if DEBUG else None,
'-g' if DEBUG else '-g1',
])
extra_compile_args_glasgow.extend([
'-isystemexternal',
'-DUSE_PORTABLE_SNIPPETS_BUILTIN',
])
extra_compile_args_minorminer.extend([
'-fno-rtti',
'-DSAFE_COORDS' if SAFE_COORDS else None,
])
# filter out any None or empty arguments
extra_compile_args = list(filter(None, extra_compile_args))
extra_compile_args_glasgow = list(filter(None, extra_compile_args_glasgow))
extra_compile_args_minorminer = list(filter(None, extra_compile_args_minorminer))
# this is a subset of the total source files, so we can't just use glob or similar
glasgow_cc = [
'/'.join(['external/glasgow-subgraph-solver/src', f])
for f in [
'cheap_all_different.cc',
'clique.cc',
'configuration.cc',
'graph_traits.cc',
'homomorphism.cc',
'homomorphism_domain.cc',
'homomorphism_model.cc',
'homomorphism_searcher.cc',
'homomorphism_traits.cc',
'lackey.cc',
'proof.cc',
'restarts.cc',
'sip_decomposer.cc',
'svo_bitset.cc',
'timeout.cc',
'thread_utils.cc',
'watches.cc',
'formats/input_graph.cc',
'formats/graph_file_error.cc',
]
]
extensions = [
Extension(
name="minorminer._minorminer",
sources=["./minorminer/_minorminer.pyx"],
include_dirs=['', './include/', './include/find_embedding'],
language='c++',
extra_compile_args=extra_compile_args + extra_compile_args_minorminer,
),
Extension(
name="minorminer.busclique",
sources=["./minorminer/busclique.pyx"],
include_dirs=['', './include/', '.include/busclique'],
language='c++',
extra_compile_args=extra_compile_args + extra_compile_args_minorminer,
),
Extension(
name="minorminer.subgraph",
sources=["./minorminer/subgraph.pyx"] + glasgow_cc,
include_dirs=['', './include', './external',
'./external/glasgow-subgraph-solver/src'],
library_dirs=['./include'],
language='c++',
extra_compile_args=extra_compile_args + extra_compile_args_glasgow,
),
Extension(
name="minorminer._extern.rpack._core",
sources=["./minorminer/_extern/rpack/_core.pyx",
"./minorminer/_extern/rpack/src/rpackcore.c"],
include_dirs=["./minorminer/_extern/rpack/include"],
language='c',
),
]
setup(
ext_modules=cythonize(extensions),
packages=['minorminer',
'minorminer.layout',
'minorminer.utils',
'minorminer._extern.rpack',
],
include_package_data=True,
)