This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmake-lrc.py
158 lines (124 loc) · 4.23 KB
/
make-lrc.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
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
import tempfile
import re
import sys
import os
import subprocess
import platform
import argparse
import multiprocessing
import shutil
import fileinput
import re
from enum import Enum
qt_version_default = '6.2.3'
vs_where_path = os.path.join(
os.environ['ProgramFiles(x86)'], 'Microsoft Visual Studio', 'Installer', 'vswhere.exe'
)
host_is_64bit = (False, True)[platform.machine().endswith('64')]
this_dir = os.path.dirname(os.path.realpath(__file__))
build_dir = os.path.join(this_dir, 'build')
qt_path = os.path.join('c:', os.sep, 'Qt')
qt_kit_path = 'msvc2019_64'
qt_root_path = os.getenv('QT_ROOT_DIRECTORY', qt_path)
def execute_cmd(cmd, with_shell=False, env_vars=None, cmd_dir=os.getcwd()):
p = subprocess.Popen(cmd,
shell=with_shell,
stdout=sys.stdout,
env=env_vars,
cwd=cmd_dir)
_, _ = p.communicate()
return p.returncode
def getLatestVSVersion():
args = [
'-latest',
'-products *',
'-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'-property installationVersion'
]
cmd = [vs_where_path] + args
output = subprocess.check_output(' '.join(cmd)).decode('utf-8')
if output:
return output.splitlines()[0].split('.')[0]
else:
return
def findVSLatestDir():
args = [
'-latest',
'-products *',
'-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'-property installationPath'
]
cmd = [vs_where_path] + args
output = subprocess.check_output(' '.join(cmd)).decode('utf-8')
if output:
return output.splitlines()[0]
else:
return
def getVSEnv(arch='x64', platform='', version=''):
env_cmd = 'set path=%path:"=% && ' + \
getVSEnvCmd(arch, platform, version) + ' && set'
p = subprocess.Popen(env_cmd,
shell=True,
stdout=subprocess.PIPE)
stdout, _ = p.communicate()
out = stdout.decode('utf-8', 'ignore').split("\r\n")[5:-1]
return dict(s.split('=', 1) for s in out)
def getVSEnvCmd(arch='x64', platform='', version=''):
vcEnvInit = [findVSLatestDir() + r'\VC\Auxiliary\Build\"vcvarsall.bat']
if platform != '':
args = [arch, platform, version]
else:
args = [arch, version]
if args:
vcEnvInit.extend(args)
vcEnvInit = 'call \"' + ' '.join(vcEnvInit)
return vcEnvInit
def build(qtver):
print("Building with Qt " + qtver)
config_str = 'Release'
vs_env_vars = {}
vs_env_vars.update(getVSEnv())
qt_dir = os.path.join(qt_root_path, qtver, qt_kit_path)
daemon_dir = os.path.dirname(this_dir) + '\\daemon'
daemon_bin = daemon_dir + '\\build\\x64\\ReleaseLib_win32\\bin\\jami.lib'
cmake_options = [
'-DCMAKE_PREFIX_PATH=' + qt_dir,
'-Dring_BIN=' + daemon_bin,
'-DRING_INCLUDE_DIR=' + daemon_dir + '\\src\\jami'
]
if not os.path.exists(build_dir):
os.makedirs(build_dir)
cmd = ['cmake', '..']
print('Configuring…')
cmd.extend(cmake_options)
if(execute_cmd(cmd, False, vs_env_vars, build_dir)):
print("Cmake generate error")
sys.exit(1)
print('Building…')
cmd = [
'cmake', '--build', '.',
'--config', config_str,
'--', '-m'
]
if(execute_cmd(cmd, False, vs_env_vars, build_dir)):
print("Cmake build error")
sys.exit(1)
def parse_args():
ap = argparse.ArgumentParser(description="Windows Jami-lrc build tool")
ap.add_argument(
'-q', '--qtver', default=qt_version_default,
help='Sets the Qt version to build with')
parsed_args = ap.parse_args()
return parsed_args
def main():
if not host_is_64bit:
print('These scripts will only run on a 64-bit Windows system for now!')
sys.exit(1)
if int(getLatestVSVersion()) < 15:
print('These scripts require at least Visual Studio v15 2017!')
sys.exit(1)
parsed_args = parse_args()
build(parsed_args.qtver)
if __name__ == '__main__':
main()