Skip to content

Commit 9d59d86

Browse files
update cmake build
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
1 parent ee2be7d commit 9d59d86

File tree

1 file changed

+75
-74
lines changed

1 file changed

+75
-74
lines changed

scripts/mk_win_dist_cmake.py

+75-74
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import subprocess
1212
import zipfile
1313
from mk_exception import *
14-
from mk_project import *
15-
import mk_util
1614

1715
BUILD_DIR = 'build-dist'
1816
BUILD_X64_DIR = os.path.join('build-dist', 'x64')
@@ -33,6 +31,7 @@
3331
ARM64ONLY = False # ARM64 flag
3432
MAKEJOBS = getenv("MAKEJOBS", "24")
3533

34+
ARCHS = []
3635

3736
def set_verbose(flag):
3837
global VERBOSE
@@ -46,11 +45,12 @@ def mk_dir(d):
4645
os.makedirs(d)
4746

4847
def set_build_dir(path):
49-
global BUILD_DIR, BUILD_X86_DIR, BUILD_X64_DIR, BUILD_ARM64_DIR
50-
BUILD_DIR = mk_util.norm_path(path)
48+
global BUILD_DIR, BUILD_X86_DIR, BUILD_X64_DIR, BUILD_ARM64_DIR, ARCHS
49+
BUILD_DIR = os.path.expanduser(os.path.normpath(path))
5150
BUILD_X86_DIR = os.path.join(path, 'x86')
5251
BUILD_X64_DIR = os.path.join(path, 'x64')
5352
BUILD_ARM64_DIR = os.path.join(path, 'arm64') # Set ARM64 build directory
53+
ARCHS = {'x64': BUILD_X64_DIR, 'x86':BUILD_X86_DIR, 'arm64':BUILD_ARM64_DIR}
5454
mk_dir(BUILD_X86_DIR)
5555
mk_dir(BUILD_X64_DIR)
5656
mk_dir(BUILD_ARM64_DIR)
@@ -59,11 +59,12 @@ def display_help():
5959
print("mk_win_dist.py: Z3 Windows distribution generator\n")
6060
print("This script generates the zip files containing executables, dlls, header files for Windows.")
6161
print("It must be executed from the Z3 root directory.")
62-
print("\nOptions:")
62+
print("\nOptions:")
6363
print(" -h, --help display this message.")
6464
print(" -s, --silent do not print verbose messages.")
6565
print(" -b <sudir>, --build=<subdir> subdirectory where x86 and x64 Z3 versions will be built (default: build-dist).")
6666
print(" -f, --force force script to regenerate Makefiles.")
67+
print(" --version=<version> release version.")
6768
print(" --assembly-version assembly version for dll")
6869
print(" --nodotnet do not include .NET bindings in the binary distribution files.")
6970
print(" --dotnet-key=<file> strongname sign the .NET assembly with the private key in <file>.")
@@ -134,6 +135,27 @@ def parse_options():
134135
def check_build_dir(path):
135136
return os.path.exists(path) and os.path.exists(os.path.join(path, 'Makefile'))
136137

138+
def check_output(cmd):
139+
out = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
140+
if out != None:
141+
enc = sys.getdefaultencoding()
142+
if enc != None: return out.decode(enc).rstrip('\r\n')
143+
else: return out.rstrip('\r\n')
144+
else:
145+
return ""
146+
147+
def get_git_hash():
148+
try:
149+
branch = check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
150+
r = check_output(['git', 'show-ref', '--abbrev=12', 'refs/heads/%s' % branch])
151+
except:
152+
raise MKException("Failed to retrieve git hash")
153+
ls = r.split(' ')
154+
if len(ls) != 2:
155+
raise MKException("Unexpected git output " + r)
156+
return ls[0]
157+
158+
137159
# Create a build directory using mk_make.py
138160
def mk_build_dir(path, arch):
139161
if not check_build_dir(path) or FORCE_MK:
@@ -149,18 +171,14 @@ def mk_build_dir(path, arch):
149171
opts = ["cmake", "-S", "."]
150172
if DOTNET_CORE_ENABLED:
151173
opts.append('-DZ3_BUILD_DOTNET_BINDINGS=ON')
152-
if DOTNET_KEY_FILE is not None:
153-
opts.append('-DDOTNET_SIGNING_KEY_FILE=' + DOTNET_KEY_FILE)
154-
if ASSEMBLY_VERSION is not None:
155-
opts.append('-DZ3_ASSEMBLY_VERSION=' + ASSEMBLY_VERSION)
156174
if JAVA_ENABLED:
157175
opts.append('-DZ3_BUILD_JAVA_BINDINGS=ON')
158176
if GIT_HASH:
159-
git_hash = mk_util.git_hash()
177+
git_hash = get_git_hash()
160178
opts.append('-DGIT_HASH=' + git_hash)
161179
if PYTHON_ENABLED:
162180
opts.append('-DZ3_BUILD_PYTHON_BINDINGS=ON')
163-
opts.append('-DZ3_USE_LIBGMP=OFF')
181+
opts.append('-DZ3_USE_LIB_GMP=OFF')
164182
opts.append('-DZ3_BUILD_LIBZ3_SHARED=ON')
165183
opts.append('-DCMAKE_INSTALL_PREFIX=' + path)
166184
opts.append('-G "NMake Makefiles"')
@@ -173,10 +191,10 @@ def mk_build_dir(path, arch):
173191

174192
# Create build directories
175193
def mk_build_dirs():
176-
mk_build_dir(BUILD_X86_DIR, 'x86')
177-
mk_build_dir(BUILD_X64_DIR, 'x64')
178-
mk_build_dir(BUILD_ARM64_DIR, 'arm64') # ARM64 build directory creation
179-
194+
global ARCHS
195+
for k in ARCHS:
196+
mk_build_dir(ARCHS[k], k)
197+
180198
# Check if on Visual Studio command prompt
181199
def check_vc_cmd_prompt():
182200
try:
@@ -222,18 +240,20 @@ def mk_z3(arch):
222240
raise MKException("Failed to make z3, x64: %s" % x64)
223241

224242
def mk_z3s():
225-
mk_z3('x86')
226-
mk_z3('x64')
227-
mk_z3('arm64')
243+
global ARCHS
244+
for k in ARCHS:
245+
mk_z3(k)
228246

229247
def get_z3_name(arch):
230-
major, minor, build, revision = get_version()
231-
print("Assembly version:", major, minor, build, revision)
232-
platform = arch
248+
global ASSEMBLY_VERSION
249+
version = "4"
250+
if ASSEMBLY_VERSION:
251+
version = ASSEMBLY_VERSION
252+
print("Assembly version:", version)
233253
if GIT_HASH:
234-
return 'z3-%s.%s.%s.%s-%s-win' % (major, minor, build, mk_util.git_hash(), platform)
254+
return 'z3-%s.%s-%s-win' % (version, get_git_hash(), arch)
235255
else:
236-
return 'z3-%s.%s.%s-%s-win' % (major, minor, build, platform)
256+
return 'z3-%s-%s-win' % (version, arch)
237257

238258
def mk_dist_dir(arch):
239259
build_path = get_build_dir(arch)
@@ -244,10 +264,10 @@ def mk_dist_dir(arch):
244264
print(f"Generated {platform} distribution folder at '{dist_path}'")
245265

246266
def mk_dist_dirs():
247-
mk_dist_dir("x86")
248-
mk_dist_dir("x64")
249-
mk_dist_dir("arm64")
250-
267+
global ARCHS
268+
for k in ARCHS:
269+
mk_dist_dir(k)
270+
251271
def get_dist_path(arch):
252272
return get_z3_name(arch)
253273

@@ -269,8 +289,9 @@ def mk_zip(arch):
269289

270290
# Create a zip file for each platform
271291
def mk_zips():
272-
mk_zip(False)
273-
mk_zip(True)
292+
global ARCHS
293+
for k in ARCHS:
294+
mk_zip(k)
274295

275296

276297
VS_RUNTIME_PATS = [re.compile(r'vcomp.*\.dll'),
@@ -311,65 +332,45 @@ def check_root(root):
311332
print("Copied '%s' to '%s'" % (f, bin_dist_path))
312333

313334
def cp_vs_runtimes():
314-
cp_vs_runtime("x86")
315-
cp_vs_runtime("x64")
316-
cp_vs_runtime("arm64")
317-
335+
global ARCHS
336+
for k in ARCHS:
337+
cp_vs_runtime(k)
338+
318339
def cp_license(arch):
319340
shutil.copy("LICENSE.txt", os.path.join(DIST_DIR, get_dist_path(arch)))
320341

321342
def cp_licenses():
322-
cp_license("x86")
323-
cp_license("x64")
324-
cp_license("arm64")
325-
326-
def init_flags():
327-
global DOTNET_KEY_FILE, JAVA_ENABLED, PYTHON_ENABLED, ASSEMBLY_VERSION
328-
mk_util.DOTNET_CORE_ENABLED = True
329-
mk_util.DOTNET_KEY_FILE = DOTNET_KEY_FILE
330-
mk_util.ASSEMBLY_VERSION = ASSEMBLY_VERSION
331-
mk_util.JAVA_ENABLED = JAVA_ENABLED
332-
mk_util.PYTHON_ENABLED = PYTHON_ENABLED
333-
mk_util.ALWAYS_DYNAMIC_BASE = True
334-
335-
343+
global ARCHS
344+
for k in ARCHS:
345+
cp_license(k)
346+
347+
348+
def build_for_arch(arch):
349+
global ARCHS
350+
build_dir = ARCHS[arch]
351+
mk_build_dir(build_dir, arch)
352+
mk_z3(arch)
353+
init_project_def()
354+
mk_dist_dir(arch)
355+
cp_license(arch)
356+
cp_vs_runtime(arch)
357+
if ZIP_BUILD_OUTPUTS:
358+
mk_zip(arch)
359+
336360
# Entry point
337361
def main():
338362
if os.name != 'nt':
339363
raise MKException("This script is for Windows only")
340364

341365
parse_options()
342366
check_vc_cmd_prompt()
343-
init_flags()
344367

345368
if X86ONLY:
346-
mk_build_dir(BUILD_X86_DIR, 'x86')
347-
mk_z3('x86')
348-
init_project_def()
349-
mk_dist_dir('x86')
350-
cp_license('x86')
351-
cp_vs_runtime('x86')
352-
if ZIP_BUILD_OUTPUTS:
353-
mk_zip('x86')
369+
build_for_arch("x86")
354370
elif X64ONLY:
355-
mk_build_dir(BUILD_X64_DIR, 'x64')
356-
mk_z3('x64')
357-
init_project_def()
358-
mk_dist_dir('x64')
359-
cp_license('x64')
360-
cp_vs_runtime('x64')
361-
if ZIP_BUILD_OUTPUTS:
362-
mk_zip('x64')
363-
elif ARM64ONLY: # ARM64 build process
364-
mk_build_dir(BUILD_ARM64_DIR, 'arm64')
365-
mk_z3('arm64')
366-
init_project_def()
367-
mk_dist_dir('arm64')
368-
cp_license('arm64')
369-
cp_vs_runtime('arm64')
370-
if ZIP_BUILD_OUTPUTS:
371-
mk_zip('arm64')
372-
371+
build_for_arch("x64")
372+
elif ARM64ONLY:
373+
build_for_arch("arm64")
373374
else:
374375
mk_build_dirs()
375376
mk_z3s()

0 commit comments

Comments
 (0)