Skip to content

Commit 637ffcd

Browse files
Update mk_win_dist_cmake.py
1 parent dec5715 commit 637ffcd

File tree

1 file changed

+60
-57
lines changed

1 file changed

+60
-57
lines changed

scripts/mk_win_dist_cmake.py

+60-57
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@
1010
import os
1111
import subprocess
1212
import zipfile
13+
import re
14+
import getopt
15+
import sys
16+
import shutil
1317
from mk_exception import *
18+
from fnmatch import fnmatch
19+
20+
def getenv(name, default):
21+
try:
22+
return os.environ[name].strip(' "\'')
23+
except:
24+
return default
1425

1526
BUILD_DIR = 'build-dist'
1627
BUILD_X64_DIR = os.path.join('build-dist', 'x64')
@@ -156,44 +167,55 @@ def get_git_hash():
156167
return ls[0]
157168

158169

170+
159171
# Create a build directory using mk_make.py
160-
def mk_build_dir(path, arch):
161-
if not check_build_dir(path) or FORCE_MK:
162-
subprocess.call(["call", "md", path, "2>NUL"], shell=True)
172+
def mk_build_dir(arch):
173+
global ARCHS
174+
build_path = ARCHS[arch]
175+
install_path = DIST_DIR
176+
if not check_build_dir(build_path) or FORCE_MK:
177+
mk_dir(build_path)
163178

164179
if arch == "arm64":
165180
arch = "amd64_arm64"
166181

167-
opts0 = ["cd", path]
168-
169-
opts1 = ['"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvarsall.bat"', arch]
170-
171-
opts = ["cmake", "-S", "."]
182+
cmds = []
183+
cmds.append(f"cd {build_path}")
184+
cmds.append(f"call \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvarsall.bat\" {arch}")
185+
cmd = []
186+
cmd.append("cmake -S .")
172187
if DOTNET_CORE_ENABLED:
173-
opts.append('-DZ3_BUILD_DOTNET_BINDINGS=ON')
188+
cmd.append(' -DZ3_BUILD_DOTNET_BINDINGS=ON')
189+
cmd.append(' -DZ3_INSTALL_DOTNET_BINDINGS=ON')
174190
if JAVA_ENABLED:
175-
opts.append('-DZ3_BUILD_JAVA_BINDINGS=ON')
191+
cmd.append(' -DZ3_BUILD_JAVA_BINDINGS=ON')
192+
cmd.append(' -DZ3_INSTALL_JAVA_BINDINGS=ON')
193+
if PYTHON_ENABLED:
194+
cmd.append(' -DZ3_BUILD_PYTHON_BINDINGS=ON')
195+
cmd.append(' -DZ3_INSTALL_PYTHON_BINDINGS=ON')
196+
cmd.append(' -DCMAKE_INSTALL_PYTHON_PKG_DIR=python')
197+
176198
if GIT_HASH:
177199
git_hash = get_git_hash()
178-
opts.append('-DGIT_HASH=' + git_hash)
179-
if PYTHON_ENABLED:
180-
opts.append('-DZ3_BUILD_PYTHON_BINDINGS=ON')
181-
opts.append('-DZ3_USE_LIB_GMP=OFF')
182-
opts.append('-DZ3_BUILD_LIBZ3_SHARED=ON')
183-
opts.append('-DCMAKE_INSTALL_PREFIX=' + path)
184-
opts.append('-G "NMake Makefiles"')
185-
opts.append('../..')
186-
args = " ".join(opts0) + "& " + " ".join(opts1) + "& " + " ".join(opts)
187-
print(args)
188-
if subprocess.call(args, shell=True) != 0:
189-
raise MKException("Failed to generate build directory at '%s'" % path)
200+
cmd.append(' -DGIT_HASH=' + git_hash)
201+
cmd.append(' -DZ3_USE_LIB_GMP=OFF')
202+
cmd.append(' -DZ3_BUILD_LIBZ3_SHARED=ON')
203+
cmd.append(' -DCMAKE_BUILD_TYPE=RelWithDebInfo')
204+
cmd.append(' -DCMAKE_INSTALL_PREFIX=' + install_path)
205+
cmd.append(' -G "NMake Makefiles"')
206+
cmd.append(' ../..\n')
207+
cmds.append("".join(cmd))
208+
print(cmds)
209+
sys.stdout.flush()
210+
if exec_cmds(cmds) != 0:
211+
raise MKException("failed to run commands")
190212

191213

192214
# Create build directories
193215
def mk_build_dirs():
194216
global ARCHS
195217
for k in ARCHS:
196-
mk_build_dir(ARCHS[k], k)
218+
mk_build_dir(k)
197219

198220
# Check if on Visual Studio command prompt
199221
def check_vc_cmd_prompt():
@@ -222,11 +244,8 @@ def exec_cmds(cmds):
222244
return res
223245

224246
def get_build_dir(arch):
225-
if arch == 'x64':
226-
return BUILD_X64_DIR
227-
if arch == 'x86':
228-
return BUILD_X86_DIR
229-
return BUILD_ARM64_DIR
247+
global ARCHS
248+
return ARCHS[arch]
230249

231250
def mk_z3(arch):
232251
build_dir = get_build_dir(arch)
@@ -235,7 +254,7 @@ def mk_z3(arch):
235254
cmds = []
236255
cmds.append('call "%VCINSTALLDIR%Auxiliary\\build\\vcvarsall.bat" ' + arch + ' ')
237256
cmds.append('cd %s' % build_dir)
238-
cmds.append('nmake')
257+
cmds.append('nmake install')
239258
if exec_cmds(cmds) != 0:
240259
raise MKException("Failed to make z3, x64: %s" % x64)
241260

@@ -255,28 +274,16 @@ def get_z3_name(arch):
255274
else:
256275
return 'z3-%s-%s-win' % (version, arch)
257276

258-
def mk_dist_dir(arch):
259-
build_path = get_build_dir(arch)
260-
dist_path = os.path.join(DIST_DIR, get_z3_name(arch))
261-
mk_dir(dist_path)
262-
mk_win_dist(build_path, dist_path)
263-
if is_verbose():
264-
print(f"Generated {platform} distribution folder at '{dist_path}'")
265-
266-
def mk_dist_dirs():
267-
global ARCHS
268-
for k in ARCHS:
269-
mk_dist_dir(k)
270-
271-
def get_dist_path(arch):
272-
return get_z3_name(arch)
273-
277+
274278
def mk_zip(arch):
275-
dist_path = get_dist_path(arch)
279+
global ARCHS
280+
build_dir = ARCHS[arch]
281+
dist_dir = os.path.join(build_dir, DIST_DIR)
282+
dist_name = get_z3_name(arch)
276283
old = os.getcwd()
277284
try:
278-
os.chdir(DIST_DIR)
279-
zfname = '%s.zip' % dist_path
285+
os.chdir(dist_dir)
286+
zfname = '%s.zip' % dist_name
280287
zipout = zipfile.ZipFile(zfname, 'w', zipfile.ZIP_DEFLATED)
281288
for root, dirs, files in os.walk(dist_path):
282289
for f in files:
@@ -324,8 +331,9 @@ def check_root(root):
324331
if not os.path.isdir(fname):
325332
vs_runtime_files.append(fname)
326333
if not vs_runtime_files:
327-
raise MKException("Did not find any runtime files to include")
328-
bin_dist_path = os.path.join(DIST_DIR, get_dist_path(arch), 'bin')
334+
raise MKException("Did not find any runtime files to include")
335+
build_dir = get_build_dir(arch)
336+
bin_dist_path = os.path.join(build_dir, DIST_DIR, 'bin')
329337
for f in vs_runtime_files:
330338
shutil.copy(f, bin_dist_path)
331339
if is_verbose():
@@ -337,7 +345,7 @@ def cp_vs_runtimes():
337345
cp_vs_runtime(k)
338346

339347
def cp_license(arch):
340-
shutil.copy("LICENSE.txt", os.path.join(DIST_DIR, get_dist_path(arch)))
348+
shutil.copy("LICENSE.txt", os.path.join(DIST_DIR, get_z3_name(arch)))
341349

342350
def cp_licenses():
343351
global ARCHS
@@ -347,11 +355,8 @@ def cp_licenses():
347355

348356
def build_for_arch(arch):
349357
global ARCHS
350-
build_dir = ARCHS[arch]
351-
mk_build_dir(build_dir, arch)
358+
mk_build_dir(arch)
352359
mk_z3(arch)
353-
init_project_def()
354-
mk_dist_dir(arch)
355360
cp_license(arch)
356361
cp_vs_runtime(arch)
357362
if ZIP_BUILD_OUTPUTS:
@@ -374,8 +379,6 @@ def main():
374379
else:
375380
mk_build_dirs()
376381
mk_z3s()
377-
init_project_def()
378-
mk_dist_dirs()
379382
cp_licenses()
380383
cp_vs_runtimes()
381384
if ZIP_BUILD_OUTPUTS:

0 commit comments

Comments
 (0)