-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
105 lines (90 loc) · 3.14 KB
/
setup.py
File metadata and controls
105 lines (90 loc) · 3.14 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
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
import glob
import os
import platform
import re
import shutil
import subprocess
from setuptools import setup, Extension
import setuptools.command.build_py
UTM_VERSION = "0.14.1"
PACKAGE_NAME = "tmTable"
PACKAGE_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), PACKAGE_NAME))
UTM_BASE = os.environ.get("UTM_BASE")
if not UTM_BASE:
raise RuntimeError("UTM_BASE not defined")
BOOST_BASE = os.environ.get("BOOST_BASE", "")
XERCES_C_BASE = os.environ.get("XERCES_C_BASE", "")
class BuildPyCommand(setuptools.command.build_py.build_py):
"""Custom build command."""
def copy_package_data(self):
xsd_dir = os.path.join(PACKAGE_DIR, "xsd")
xsd_type_dir = os.path.join(xsd_dir, "xsd-type")
if not os.path.exists(xsd_dir):
os.makedirs(xsd_dir)
if not os.path.exists(xsd_type_dir):
os.makedirs(xsd_type_dir)
for filename in glob.glob(os.path.join(UTM_BASE, "*.xsd")):
shutil.copy(filename, xsd_dir)
for filename in glob.glob(os.path.join(UTM_BASE, "xsd-type", "*.xsd")):
shutil.copy(filename, xsd_type_dir)
def create_swig_wrapper(self):
command = []
subprocess.check_call([
"swig",
"-c++",
"-python",
"-I{}".format(os.path.join(BOOST_BASE, "include")),
"-I{}".format(os.path.join(XERCES_C_BASE, "include")),
"-I{}".format(os.path.join(UTM_BASE, "include")),
os.path.join(PACKAGE_DIR, f"{PACKAGE_NAME}.i"),
])
def create_version_module(self):
with open(os.path.join(PACKAGE_DIR, "_version.py"), "w") as f:
f.write("# This file was auto generated by `setup.py`, changes might be lost.\n")
f.write(f"__version__ = \"{UTM_VERSION}\"\n")
def run(self):
self.copy_package_data()
self.create_swig_wrapper()
self.create_version_module()
# run actual build command
setuptools.command.build_py.build_py.run(self)
def get_extra_link_args():
extra_link_args = []
if platform.system() == "Darwin":
extra_link_args.append("-Wl,-headerpad_max_install_names") # macos install_name_tool issues
return extra_link_args
tmTable_ext = Extension(
name="_tmTable",
define_macros=[("SWIG", "1"), ("DNDEBUG", "1")],
sources=[
os.path.join("tmTable", "tmTable_wrap.cxx")
],
include_dirs=[
os.path.join(BOOST_BASE, "include"),
os.path.join(XERCES_C_BASE, "include"),
os.path.join(UTM_BASE, "include"),
],
library_dirs=[
os.path.join(BOOST_BASE, "lib"),
os.path.join(XERCES_C_BASE, "lib"),
os.path.join(UTM_BASE, "lib"),
],
libraries=["xerces-c", "tmutil", "tmxsd", "tmtable"],
extra_compile_args=["-std=c++11", "-O2"],
extra_link_args=get_extra_link_args()
)
setup(
version=UTM_VERSION,
ext_modules=[tmTable_ext],
cmdclass={
"build_py": BuildPyCommand,
},
packages=[PACKAGE_NAME],
package_data={
PACKAGE_NAME: [
os.path.join("xsd", "*.xsd"),
os.path.join("xsd", "xsd-type", "*.xsd"),
f"{PACKAGE_NAME}.i",
]
}
)