forked from CATIA-Systems/FMPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_cvode.py
112 lines (89 loc) · 3.08 KB
/
build_cvode.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
from fmpy import platform_tuple, sharedLibraryExtension
from fmpy.util import download_file
import tarfile
import os
import shutil
from subprocess import check_call
if os.name == 'nt':
generator = 'Visual Studio 15 2017 Win64'
sl_prefix = ''
sl_suffix = sharedLibraryExtension
else:
generator = 'Unix Makefiles'
sl_prefix = 'lib'
sl_suffix = sharedLibraryExtension
sundials_binary_dir = os.path.join('fmpy', 'sundials', platform_tuple)
# clean up
for build_dir in ['cswrapper/build', 'sundials-5.3.0', sundials_binary_dir, 'fmpy/logging/build']:
if os.path.isdir(build_dir):
shutil.rmtree(build_dir)
url = 'https://computing.llnl.gov/projects/sundials/download/sundials-5.3.0.tar.gz'
checksum = '88dff7e11a366853d8afd5de05bf197a8129a804d9d4461fb64297f1ef89bca7'
filename = os.path.basename(url)
download_file(url, checksum)
# response = requests.get(url)
#
# with open(filename, 'wb') as f:
# f.write(response.content)
with tarfile.open(filename, "r:gz") as tar:
tar.extractall()
os.mkdir('sundials-5.3.0/static')
# build CVode as static library
check_call([
'cmake',
'-DBUILD_ARKODE=OFF',
'-DBUILD_CVODES=OFF',
'-DBUILD_IDA=OFF',
'-DBUILD_IDAS=OFF',
'-DBUILD_KINSOL=OFF',
'-DBUILD_SHARED_LIBS=OFF',
'-DCMAKE_INSTALL_PREFIX=sundials-5.3.0/static/install',
'-DCMAKE_USER_MAKE_RULES_OVERRIDE=../OverrideMSVCFlags.cmake',
'-DEXAMPLES_ENABLE_C=OFF',
'-G', generator,
'-S', 'sundials-5.3.0',
'-B', 'sundials-5.3.0/static'
])
check_call(['cmake', '--build', 'sundials-5.3.0/static', '--target', 'install', '--config', 'Release'])
# build CVode as dynamic library
check_call([
'cmake',
'-DBUILD_ARKODE=OFF',
'-DBUILD_CVODES=OFF',
'-DBUILD_IDA=OFF',
'-DBUILD_IDAS=OFF',
'-DBUILD_KINSOL=OFF',
'-DBUILD_STATIC_LIBS=OFF',
'-DEXAMPLES_ENABLE_C=OFF',
'-DCMAKE_INSTALL_PREFIX=sundials-5.3.0/dynamic/install',
'-DCMAKE_USER_MAKE_RULES_OVERRIDE=../OverrideMSVCFlags.cmake',
'-G', generator,
'-S', 'sundials-5.3.0',
'-B', 'sundials-5.3.0/dynamic'
])
check_call(['cmake', '--build', 'sundials-5.3.0/dynamic', '--target', 'install', '--config', 'Release'])
os.mkdir(sundials_binary_dir)
os.path.join('sundials-5.3.0', 'dynamic', 'install', 'sundials_cvode' + sharedLibraryExtension)
for name in ['sundials_cvode', 'sundials_nvecserial', 'sundials_sunlinsoldense', 'sundials_sunmatrixdense']:
src = os.path.join('sundials-5.3.0', 'dynamic', 'install', 'lib', sl_prefix + name + sl_suffix)
dst = os.path.join(sundials_binary_dir, name + sl_suffix)
shutil.copy(src, dst)
# build cswrapper
os.mkdir('cswrapper/build')
check_call([
'cmake',
'-DCVODE_INSTALL_DIR=../sundials-5.3.0/static/install',
'-G', generator,
'-S', 'cswrapper',
'-B', 'cswrapper/build'
])
check_call(['cmake', '--build', 'cswrapper/build', '--config', 'Release'])
# build logging callback
os.mkdir('fmpy/logging/build')
check_call([
'cmake',
'-G', generator,
'-S', 'fmpy/logging',
'-B', 'fmpy/logging/build'
])
check_call(['cmake', '--build', 'fmpy/logging/build', '--config', 'Release'])