-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.py
More file actions
76 lines (67 loc) · 1.93 KB
/
setup.py
File metadata and controls
76 lines (67 loc) · 1.93 KB
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
#!/usr/bin/python3 -OO
import os
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
class CustomBuild(build_ext):
def build_extension(self, ext: Extension):
if self.compiler.compiler_type == "msvc":
ldflags = ["/OPT:REF", "/OPT:ICF"]
cflags = ["/O2", "/GS-", "/Gy", "/sdl-", "/Oy", "/Oi"]
else:
ldflags = []
cflags = [
"-Wall",
"-Wextra",
"-fomit-frame-pointer",
"-fno-rtti",
"-fno-exceptions",
"-O3",
"-fPIC",
"-fwrapv",
"-std=c++14"
]
output_dir = os.path.dirname(self.build_lib)
compiled_objects = []
for source_files in [
{
"sources": ["binding/fpnge.cc"],
"depends": ["binding/fpnge.h"],
"gcc_flags": ["-march=native"],
}
]:
args = {
"sources": source_files["sources"],
"output_dir": output_dir,
"extra_postargs": cflags[:],
"macros": [("NDEBUG", 1)]
}
if self.compiler.compiler_type == "msvc":
if "msvc_flags" in source_files:
args["extra_postargs"] += source_files["msvc_flags"]
else:
if "gcc_flags" in source_files:
args["extra_postargs"] += source_files["gcc_flags"]
if "include_dirs" in source_files:
args["include_dirs"] = source_files["include_dirs"]
if "macros" in source_files:
args["macros"].extend(source_files["macros"])
self.compiler.compile(**args)
compiled_objects += self.compiler.object_filenames(source_files["sources"], output_dir=output_dir)
# attach to Extension
ext.extra_link_args = ldflags + compiled_objects
ext.depends = compiled_objects
# proceed with regular Extension build
super(CustomBuild, self).build_extension(ext)
setup(
name="fpnge",
description="Python binding for fpnge",
version="1.1.2",
author="Anime Tosho",
url="https://github.com/animetosho/python-fpnge/",
license="CC0",
ext_modules=[
Extension("fpnge.binding", ["binding/fpnge-binding.cc"])
],
cmdclass={"build_ext": CustomBuild},
packages=["fpnge"]
)