-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
146 lines (113 loc) · 4.15 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
146
#!/usr/bin/env python
import subprocess
import platform
import argparse
import os
import sys
from setuptools import setup, Extension
from Cython.Build import cythonize
CUR_DIR = os.path.abspath(os.path.dirname(__file__))
def print_error(*s: str):
print("\033[91m {}\033[00m".format(' '.join(s)))
def print_succes(*s: str):
print("\033[92m {}\033[00m".format(' '.join(s)))
def print_info(*s: str):
print("\033[93m {}\033[00m".format(' '.join(s)))
def main(debug: bool):
print_info('\nBuilding CASC extension...')
print(f'Target mode: {"Debug" if debug else "Release"}')
# build CASCLib
build_dir = os.path.join(CUR_DIR, 'CASCLib', 'build')
os.makedirs(build_dir, exist_ok=True)
os.chdir(build_dir)
cmake_defines = ['-DCMAKE_BUILD_TYPE=Debug' if debug else '-DCMAKE_BUILD_TYPE=Release'
, '-DCASC_BUILD_SHARED_LIB=OFF'
, '-DCASC_BUILD_STATIC_LIB=ON']
if sys.platform != 'win32':
cmake_defines.extend(['-DCMAKE_CXX_FLAGS=-fPIC', '-DCMAKE_C_FLAGS=-fPIC'])
status = subprocess.call(['cmake', '..', *cmake_defines])
if status:
print_error(f'\nError building CASCLib. See CMake error above.')
sys.exit(1)
status = subprocess.check_call(['cmake', '--build', '.', f'--config {"Debug" if debug else "Release"}'])
if status:
print_error(f'\nError building CASCLib. See build error above.')
sys.exit(1)
status = subprocess.call(['cmake', '--install', '.', f'--prefix {CUR_DIR}'
, f'--config {"Debug" if debug else "Release"}'])
if status:
print_error(f'\nError building CASCLib. Error setting install configuration.')
sys.exit(1)
os.chdir(CUR_DIR)
static_libraries = ['casc']
static_lib_dir = 'lib'
libraries = []
library_dirs = []
extra_objects = []
define_macros = []
if sys.platform == 'win32':
libraries.extend(static_libraries)
library_dirs.append(static_lib_dir)
extra_objects = []
define_macros.append(('CASCLIB_NO_AUTO_LINK_LIBRARY', None))
else: # POSIX
extra_objects = ['{}/lib{}.a'.format(static_lib_dir, l) for l in static_libraries]
libraries.append('z')
# compiler and linker settings
if platform.system() == 'Darwin':
if debug:
extra_compile_args = ['-std=c++17', '-g3', '-O0']
extra_link_args = []
else:
extra_compile_args = ['-std=c++17', '-O3']
extra_link_args = []
elif platform.system() == 'Windows':
if debug:
extra_compile_args = ['/std:c++17', '/Zi']
extra_link_args = ['/DEBUG:FULL']
else:
extra_compile_args = ['/std:c++17']
extra_link_args = []
else:
if debug:
extra_compile_args = ['-std=c++17', '-O0', '-g']
extra_link_args = []
else:
extra_compile_args = ['-std=c++17', '-O3']
extra_link_args = []
setup(
name='Python CASC Handler',
ext_modules=cythonize(
Extension(
"CASC",
sources=[
"casc.pyx"
],
language="c++",
libraries=libraries,
library_dirs=library_dirs,
include_dirs = ["include"],
extra_objects=extra_objects,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args
)
),
requires=['Cython']
)
print_succes('\nSuccesfully built CASC extension.')
'''
# fix dylib loading path
if platform.system() == 'Darwin':
for filepath in os.listdir(CUR_DIR):
if 'darwin' in filepath and 'CASC' in filepath:
subprocess.call(['install_name_tool', '-change', 'libcasc.dylib', '@loader_path/libcasc.dylib', filepath])
break
'''
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--wbs_debug', action='store_true', help='Compile CASC extension in debug mode.')
args, unknown = parser.parse_known_args()
if args.wbs_debug:
sys.argv.remove('--wbs_debug')
main(args.wbs_debug)