-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
123 lines (104 loc) · 3.88 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
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext as _build_ext
import sys
import os
import platform
class get_pybind_include(object):
"""Helper class to determine the pybind11 include path
The purpose of this class is to postpone importing pybind11
until it is actually installed, so that the ``get_include()``
method can be invoked."""
def __init__(self, user=False):
self.user = user
def __str__(self):
import pybind11
return pybind11.get_include(self.user)
def get_src_cpps(path):
"""
Go through src/cliquematch recursively,
and return all cpp file paths
"""
cpps = []
for root, dirnames, filenames in os.walk(path):
for filename in filenames:
if os.path.splitext(filename)[-1] == ".cpp":
cpps.append(os.path.join(root, filename))
return cpps
# extension naming matters, because
# 1) the .DEF file used by the linker
# 2) the copying from build/ to dist/
ext_modules = [
Extension(
name="cliquematch.core",
sources=get_src_cpps("src/cliquematch/detail/")
+ get_src_cpps("src/cliquematch/core/")
+ get_src_cpps("src/cliquematch/ext/"),
include_dirs=[
str(get_pybind_include(True)),
str(get_pybind_include(False)),
"src/cliquematch/",
os.environ.get("EIGEN_DIR", "include/"),
],
language="c++",
)
]
class BuildExt(_build_ext):
"""A custom build extension for adding compiler-specific options."""
c_opts = {
"msvc": ["/EHsc"], # msvc has c++11 by default
"unix": ["-Wall", "-Wpedantic", "-Wno-unused-result", "-std=c++11"],
}
if platform.system() == "Windows":
os.environ["CC"] = "msvc"
os.environ["CXX"] = "msvc"
if sys.platform == "darwin":
c_opts["unix"] += ["-stdlib=libc++", "-mmacosx-version-min=10.7"]
def build_extensions(self):
ct = self.compiler.compiler_type
opts = self.c_opts.get(ct)
if ct == "unix":
opts.append("-fvisibility=hidden")
if self.compiler.compiler_so:
if "-g" in self.compiler.compiler_so:
self.compiler.compiler_so.remove("-g")
elif ct == "mingw32":
opts = self.c_opts.get("unix")
eigen_dir = os.environ.get("EIGEN_DIR", "include")
sample_file = os.path.abspath(os.path.join(eigen_dir, "Eigen", "Dense"))
print("Checking for the Eigen Matrix Library at %s ..." % (sample_file))
if os.path.exists(sample_file):
print("File exists! Assuming the Eigen Matrix Library is available")
else:
err_str = (
"Could not find Eigen. Please download Eigen from:\n"
+ "\t https://gitlab.com/libeigen/eigen/-/releases#3.3.7\n"
+ "extract into a folder, and set the EIGEN_DIR environment variable accordingly"
)
print(err_str)
exit(1)
for ext in self.extensions:
ext.extra_compile_args = opts
_build_ext.build_extensions(self)
setup(
name="cliquematch",
version="3.0.1",
author="Gautham Venkatasubramanian",
author_email="[email protected]",
description="Finding correspondence via maximum cliques in large graphs",
license="MIT",
long_description=open("README.md", "r").read(),
long_description_content_type="text/markdown",
url="https://github.com/ahgamut/cliquematch",
packages=find_packages("src"),
package_dir={"": "src"},
classifiers=[
"Intended Audience :: Science/Research",
"Programming Language :: C++",
"Programming Language :: Python :: 3",
],
zip_safe=False,
install_requires=["pybind11>=2.2", "numpy>=1.14"],
setup_requires=["pybind11>=2.2"],
ext_modules=ext_modules,
cmdclass={"build_ext": BuildExt},
)