-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
executable file
·68 lines (59 loc) · 1.95 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
#!/usr/bin/env python
import os
import sys
import subprocess
import configure
# Thanks to http://patorjk.com/software/taag/
# and http://www.chris.com/ascii/index.php?art=creatures/dragons
# for ASCII art inspiriation
def parse_args():
distutils = []
cmake = []
make = []
argsets = [distutils, cmake, make]
i = 0
for arg in sys.argv:
if arg == '--':
i += 1
else:
argsets[i].append(arg)
hdf5opt = [o.split('=')[1] for o in distutils if o.startswith('--hdf5=')]
if 0 < len(hdf5opt):
os.environ['HDF5_ROOT'] = hdf5opt[0] # Expose to CMake
distutils = [o for o in distutils if not o.startswith('--hdf5=')]
return distutils, cmake, make
def main_body():
if not os.path.exists('build'):
os.mkdir('build')
sys.argv, cmake_args, make_args = parse_args()
makefile = os.path.join('build', 'Makefile')
if not os.path.exists(makefile) and cmake_args != ['--skip']:
cmake_cmd = ['cmake', '..'] + cmake_args
if os.name == 'nt':
files_on_path = set()
for p in os.environ['PATH'].split(';')[::-1]:
if os.path.exists(p):
files_on_path.update(os.listdir(p))
if 'cl.exe' in files_on_path:
pass
elif 'sh.exe' in files_on_path:
cmake_cmd += ['-G "MSYS Makefiles"']
elif 'gcc.exe' in files_on_path:
cmake_cmd += ['-G "MinGW Makefiles"']
cmake_cmd = ' '.join(cmake_cmd)
rtn = subprocess.check_call(cmake_cmd, cwd='build', shell=(os.name=='nt'))
if make_args != ['--skip']:
rtn = subprocess.check_call(['make'] + make_args, cwd='build')
cwd = os.getcwd()
os.chdir('build')
configure.setup()
os.chdir(cwd)
def main():
success = False
try:
main_body()
success = True
finally:
configure.final_message(success)
if __name__ == "__main__":
main()