-
Notifications
You must be signed in to change notification settings - Fork 119
/
build_remoting.py
120 lines (92 loc) · 3.45 KB
/
build_remoting.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
import os
import tarfile
import shutil
from subprocess import check_call
from fmpy.util import download_file
# build configuration
config = 'Release'
basedir = os.path.abspath(os.path.dirname(__file__))
rpclib_dir = os.path.join(basedir, 'rpclib-2.3.0').replace('\\', '/')
if not os.path.isdir(rpclib_dir):
filename = download_file(url='https://github.com/rpclib/rpclib/archive/refs/tags/v2.3.0.tar.gz',
checksum='eb9e6fa65e1a79b37097397f60599b93cb443d304fbc0447c50851bc3452fdef')
print("Extracting %s" % filename)
with tarfile.open(filename, 'r:gz') as tar:
tar.extractall()
# patch the CMake project to link static against the MSVC runtime
with open(os.path.join(rpclib_dir, 'CMakeLists.txt'), 'a') as file:
file.write('''
message(${CMAKE_CXX_FLAGS_RELEASE})
message(${CMAKE_CXX_FLAGS_DEBUG})
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
message(${CMAKE_CXX_FLAGS_RELEASE})
message(${CMAKE_CXX_FLAGS_DEBUG})
''')
if os.name == 'nt':
for bitness, architecture in [('win32', 'Win32'), ('win64', 'x64')]:
# clean up
shutil.rmtree(os.path.join(basedir, 'remoting', bitness), ignore_errors=True)
print(f"Building rpclib for {bitness}...")
check_call(args=[
'cmake',
'-B', rpclib_dir + '/' + bitness,
'-D', 'RPCLIB_MSVC_STATIC_RUNTIME=ON',
'-D', 'CMAKE_INSTALL_PREFIX=' + os.path.join(rpclib_dir, bitness, 'install'),
'-G', 'Visual Studio 17 2022',
'-A', architecture,
rpclib_dir
])
check_call(args=[
'cmake',
'--build', os.path.join(rpclib_dir, bitness),
'--target', 'install',
'--config', config
])
print(f"Building remoting binaries for {bitness}...")
check_call(args=[
'cmake',
'-B', 'remoting/' + bitness,
'-G', 'Visual Studio 17 2022',
'-A', architecture,
'-D', 'RPCLIB=' + os.path.join(rpclib_dir, bitness, 'install'),
'-B', 'remoting/' + bitness,
'remoting'
])
check_call(['cmake', '--build', 'remoting/' + bitness, '--config', config])
else:
# clean up
shutil.rmtree(os.path.join(basedir, 'remoting', 'linux64'), ignore_errors=True)
print("Building rpclib...")
check_call(args=[
'cmake',
'-B', os.path.join(rpclib_dir, 'linux64'),
'-D', 'CMAKE_INSTALL_PREFIX=' + os.path.join(rpclib_dir, 'linux64', 'install'),
'-D', 'CMAKE_POSITION_INDEPENDENT_CODE=ON',
'-G', 'Unix Makefiles',
rpclib_dir
])
check_call(args=[
'cmake',
'--build', os.path.join(rpclib_dir, 'linux64'),
'--target', 'install',
'--config', config
])
print("Building remoting binaries...")
check_call(args=[
'cmake',
'-B', 'remoting/' + 'linux64',
'-G', 'Unix Makefiles',
'-D', 'RPCLIB=' + os.path.join(rpclib_dir, 'linux64', 'install'),
'-B', 'remoting/linux64', 'remoting'
])
check_call(['cmake', '--build', 'remoting/linux64', '--config', config])