-
Notifications
You must be signed in to change notification settings - Fork 120
/
build_cvode.py
87 lines (69 loc) · 3.17 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
from fmpy import sharedLibraryExtension, platform
from fmpy import platform_tuple as current_platform_tuple
from fmpy.util import download_file
import tarfile
import os
import shutil
from subprocess import check_call
configuration = 'Release'
if os.name == 'nt':
generators = [
('win32', ['-G', 'Visual Studio 17 2022', '-A', 'Win32'], 'i686-windows'),
('win64', ['-G', 'Visual Studio 17 2022', '-A', 'x64'], 'x86_64-windows')
]
sl_prefix = ''
sl_suffix = sharedLibraryExtension
else:
generators = [(platform, ['-G', 'Unix Makefiles'], current_platform_tuple)]
sl_prefix = 'lib'
sl_suffix = sharedLibraryExtension
# clean up
shutil.rmtree('sundials-5.3.0', ignore_errors=True)
filename = download_file(url='https://github.com/LLNL/sundials/releases/download/v5.3.0/sundials-5.3.0.tar.gz',
checksum='88dff7e11a366853d8afd5de05bf197a8129a804d9d4461fb64297f1ef89bca7')
with tarfile.open(filename, "r:gz") as tar:
tar.extractall()
for platform, cmake_options, platform_tuple in generators:
os.makedirs(f'sundials-5.3.0/{platform}/static')
# build CVode as static library
check_call([
'cmake',
'-D', 'BUILD_ARKODE=OFF',
'-D', 'BUILD_CVODES=OFF',
'-D', 'BUILD_IDA=OFF',
'-D', 'BUILD_IDAS=OFF',
'-D', 'BUILD_KINSOL=OFF',
'-D', 'BUILD_SHARED_LIBS=OFF',
'-D', f'CMAKE_INSTALL_PREFIX=sundials-5.3.0/{platform}/static/install',
'-D', 'CMAKE_USER_MAKE_RULES_OVERRIDE=../OverrideMSVCFlags.cmake',
'-D', 'EXAMPLES_ENABLE_C=OFF',
'-D', 'CMAKE_OSX_ARCHITECTURES=arm64;x86_64',
'-S', 'sundials-5.3.0',
'-B', f'sundials-5.3.0/{platform}/static'
] + cmake_options)
check_call(['cmake', '--build', f'sundials-5.3.0/{platform}/static', '--target', 'install', '--config', configuration])
os.makedirs(f'sundials-5.3.0/{platform}/dynamic')
# build CVode as dynamic library
check_call([
'cmake',
'-D', 'BUILD_ARKODE=OFF',
'-D', 'BUILD_CVODES=OFF',
'-D', 'BUILD_IDA=OFF',
'-D', 'BUILD_IDAS=OFF',
'-D', 'BUILD_KINSOL=OFF',
'-D', 'BUILD_STATIC_LIBS=OFF',
'-D', 'EXAMPLES_ENABLE_C=OFF',
'-D', f'CMAKE_INSTALL_PREFIX=sundials-5.3.0/{platform}/dynamic/install',
'-D', 'CMAKE_USER_MAKE_RULES_OVERRIDE=../OverrideMSVCFlags.cmake',
'-D', 'CMAKE_OSX_ARCHITECTURES=arm64;x86_64',
'-S', 'sundials-5.3.0',
'-B', f'sundials-5.3.0/{platform}/dynamic'
] + cmake_options)
check_call(['cmake', '--build', f'sundials-5.3.0/{platform}/dynamic', '--target', 'install', '--config', configuration])
sundials_binary_dir = os.path.join('fmpy', 'sundials', platform_tuple)
os.makedirs(sundials_binary_dir, exist_ok=True)
os.path.join('sundials-5.3.0', platform, 'dynamic', 'install', 'sundials_cvode' + sharedLibraryExtension)
for name in ['sundials_cvode', 'sundials_nvecserial', 'sundials_sunlinsoldense', 'sundials_sunmatrixdense']:
src = os.path.join('sundials-5.3.0', platform, 'dynamic', 'install', 'lib', sl_prefix + name + sl_suffix)
dst = os.path.join(sundials_binary_dir, name + sl_suffix)
shutil.copy(src, dst)