From 4915f2da0403e608d9ea3965bb55f54d5f652984 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 4 Jan 2016 21:53:24 +0000 Subject: [PATCH] Added facilities for generating a libz3.vcxproj next to z3.vcxproj for simplified DLL build in VS. --- scripts/mk_make.py | 5 +- scripts/mk_util.py | 206 ++++++++++++++++++++++++++------------------- 2 files changed, 123 insertions(+), 88 deletions(-) diff --git a/scripts/mk_make.py b/scripts/mk_make.py index ecf70a8c5..813cd3a66 100644 --- a/scripts/mk_make.py +++ b/scripts/mk_make.py @@ -1,7 +1,7 @@ ############################################ # Copyright (c) 2012 Microsoft Corporation -# -# Scripts for generating Makefiles and Visual +# +# Scripts for generating Makefiles and Visual # Studio project files. # # Author: Leonardo de Moura (leonardo) @@ -17,6 +17,7 @@ update_version() mk_auto_src() mk_bindings(API_files) mk_vs_proj('z3', ['shell']) +mk_vs_proj_dll('libz3', ['api_dll']) mk_makefile() diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8a92d832d..89634c952 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -559,7 +559,7 @@ def dos2unix_tree(): for root, dirs, files in os.walk('src'): for f in files: dos2unix(os.path.join(root, f)) - + def check_eol(): if not IS_WINDOWS: @@ -1372,8 +1372,8 @@ class PythonInstallComponent(Component): "Python package directory." % (PYTHON_PACKAGE_DIR, PREFIX)) def main_component(self): - return False - + return False + def mk_install(self, out): if not is_python_install_enabled(): return @@ -1729,7 +1729,7 @@ class JavaDLLComponent(Component): MakeRuleCmd.remove_installed_files(out, os.path.join(INSTALL_LIB_DIR, jarfile)) class MLComponent(Component): - + def __init__(self, name, lib_name, path, deps): Component.__init__(self, name, path, deps) if lib_name is None: @@ -1747,14 +1747,14 @@ class MLComponent(Component): out.write('CXXFLAGS_OCAML=$(CXXFLAGS:/GL=)\n') # remove /GL; the ocaml tools don't like it. if IS_WINDOWS: - prefix_lib = '-L' + os.path.abspath(BUILD_DIR).replace('\\', '\\\\') + prefix_lib = '-L' + os.path.abspath(BUILD_DIR).replace('\\', '\\\\') else: prefix_lib = '-L' + PREFIX + '/lib' substitutions = { 'LEXTRA': prefix_lib, 'VERSION': "{}.{}.{}.{}".format(VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) } - + configure_file(os.path.join(self.src_dir, 'META.in'), - os.path.join(BUILD_DIR, self.sub_dir, 'META'), + os.path.join(BUILD_DIR, self.sub_dir, 'META'), substitutions) mlis = '' @@ -1766,7 +1766,7 @@ class MLComponent(Component): z3dllso = get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)' out.write('%s: %s %s\n' % (stubso, stubsc, z3dllso)) out.write('\t%s -ccopt "$(CXXFLAGS_OCAML) -I %s -I %s -I %s $(CXX_OUT_FLAG)%s" -c %s\n' % - (OCAMLC, OCAML_LIB, api_src, src_dir, stubso, stubsc)) + (OCAMLC, OCAML_LIB, api_src, src_dir, stubso, stubsc)) cmis = '' for m in self.modules: @@ -1776,7 +1776,7 @@ class MLComponent(Component): out.write('\t%s -I %s -o %s -c %s\n' % (OCAMLC, self.sub_dir, ft, ff)) cmis = cmis + ' ' + ft - cmos = '' + cmos = '' for m in self.modules: ff = os.path.join(src_dir, m + '.ml') ft = os.path.join(self.sub_dir, m + '.cmo') @@ -1802,7 +1802,7 @@ class MLComponent(Component): out.write('\tocamlmklib -o %s -I %s %s %s -L. -lz3\n' % (z3mls, self.sub_dir, stubso, cmxs)) out.write('%s.cmxs: %s.cmxa\n' % (z3mls, z3mls)) out.write('\t%s -shared -o %s.cmxs -I %s %s.cmxa\n' % (OCAMLOPT, z3mls, self.sub_dir, z3mls)) - + out.write('\n') out.write('ml: %s.cma %s.cmxa %s.cmxs\n' % (z3mls, z3mls, z3mls)) out.write('\n') @@ -1816,7 +1816,7 @@ class MLComponent(Component): out.write('ocamlfind_uninstall:\n') self.mk_uninstall(out) out.write('\n') - + def mk_install_deps(self, out): if is_ml_enabled() and OCAMLFIND != '': out.write(get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT) ') @@ -1885,8 +1885,8 @@ class CppExampleComponent(ExampleComponent): out.write(' -I%s' % get_component(API_COMPONENT).to_src_dir) out.write(' -I%s' % get_component(CPP_COMPONENT).to_src_dir) out.write(' %s' % os.path.join(self.to_ex_dir, cppfile)) - out.write('\n') - + out.write('\n') + exefile = '%s$(EXE_EXT)' % self.name out.write('%s: %s %s\n' % (exefile, dll, objfiles)) out.write('\t$(LINK) $(LINK_OUT_FLAG)%s $(LINK_FLAGS) %s ' % (exefile, objfiles)) @@ -3305,15 +3305,7 @@ def mk_z3consts_ml(api_files): def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id -def mk_vs_proj(name, components): - if not VS_PROJ: - return - proj_name = '%s.vcxproj' % os.path.join(BUILD_DIR, name) - modes=['Debug', 'Release'] - PLATFORMS=['Win32'] - f = open(proj_name, 'w') - f.write('\n') - f.write('\n') +def mk_vs_proj_property_groups(f, name, type): f.write(' \n') f.write(' \n') f.write(' Debug\n') @@ -3324,35 +3316,45 @@ def mk_vs_proj(name, components): f.write(' Win32\n') f.write(' \n') f.write(' \n') - f.write(' \n') + f.write(' \n') f.write(' {%s}\n' % mk_gui_str(0)) f.write(' %s\n' % name) f.write(' Win32Proj\n') f.write(' \n') f.write(' \n') f.write(' \n') - f.write(' Application\n') + f.write(' %s\n' % type) f.write(' Unicode\n') f.write(' false\n') f.write(' \n') f.write(' \n') - f.write(' \n') - f.write(' \n') + f.write(' \n') f.write(' \n') f.write(' \n') f.write(' \n') f.write(' \n') - f.write(' $(SolutionDir)$(Configuration)\\n') + f.write(' $(SolutionDir)\$(ProjectName)\$(Configuration)\\n') f.write(' %s\n' % name) - f.write(' .exe\n') - f.write(' $(SolutionDir)$(Configuration)\\n') + f.write(' .dll\n') + f.write(' $(SolutionDir)\$(ProjectName)\$(Configuration)\\n') f.write(' %s\n' % name) - f.write(' .exe\n') + f.write(' .dll\n') f.write(' \n') - f.write(' \n') + f.write(' \n') + f.write(' $(ProjectName)\$(Configuration)\\n') + f.write(' \n') + f.write(' \n') + f.write(' $(ProjectName)\$(Configuration)\\n') + f.write(' \n') + + +def mk_vs_proj_cl_compile(f, name, components, debug): f.write(' \n') f.write(' Disabled\n') - f.write(' WIN32;_DEBUG;Z3DEBUG;_TRACE;_MP_INTERNAL;_WINDOWS;%(PreprocessorDefinitions)\n') + if debug: + f.write(' WIN32;_DEBUG;Z3DEBUG;_TRACE;_MP_INTERNAL;_WINDOWS;%(PreprocessorDefinitions)\n') + else: + f.write(' WIN32;_NDEBUG;_MP_INTERNAL;_WINDOWS;%(PreprocessorDefinitions)\n') if VS_PAR: f.write(' false\n') f.write(' true\n') @@ -3360,8 +3362,14 @@ def mk_vs_proj(name, components): f.write(' true\n') f.write(' EnableFastChecks\n') f.write(' Level3\n') - f.write(' MultiThreadedDebugDLL\n') - f.write(' true\n') + if debug: + f.write(' MultiThreadedDebugDLL\n') + else: + f.write(' MultiThreadedDLL\n') + if USE_OMP: + f.write(' true\n') + else: + f.write(' false\n') f.write(' ProgramDatabase\n') f.write(' ') deps = find_all_deps(name, components) @@ -3374,63 +3382,89 @@ def mk_vs_proj(name, components): f.write(get_component(dep).to_src_dir) f.write('\n') f.write(' \n') - f.write(' \n') - f.write(' $(OutDir)%s.exe\n' % name) - f.write(' true\n') - f.write(' Console\n') - f.write(' 8388608\n') - f.write(' false\n') - f.write(' \n') - f.write(' \n') - f.write(' MachineX86\n') - f.write(' %(AdditionalLibraryDirectories)\n') - f.write('psapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)\n') - f.write(' \n') - f.write(' \n') - f.write(' \n') - f.write(' \n') - f.write(' Disabled\n') - f.write(' WIN32;_NDEBUG;_MP_INTERNAL;_WINDOWS;%(PreprocessorDefinitions)\n') - if VS_PAR: - f.write(' false\n') - f.write(' true\n') - else: - f.write(' true\n') - f.write(' EnableFastChecks\n') - f.write(' Level3\n') - f.write(' MultiThreadedDLL\n') - f.write(' true\n') - f.write(' ProgramDatabase\n') - f.write(' ') - deps = find_all_deps(name, components) - first = True - for dep in deps: - if first: - first = False - else: - f.write(';') - f.write(get_component(dep).to_src_dir) - f.write('\n') - f.write(' \n') - f.write(' \n') - f.write(' $(OutDir)%s.exe\n' % name) - f.write(' true\n') - f.write(' Console\n') - f.write(' 8388608\n') - f.write(' false\n') - f.write(' \n') - f.write(' \n') - f.write(' MachineX86\n') - f.write(' %(AdditionalLibraryDirectories)\n') - f.write('psapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)\n') - f.write(' \n') - f.write(' \n') + +def mk_vs_proj_dep_groups(f, name, components): f.write(' \n') + deps = find_all_deps(name, components) for dep in deps: dep = get_component(dep) for cpp in filter(lambda f: f.endswith('.cpp'), os.listdir(dep.src_dir)): f.write(' \n' % os.path.join(dep.to_src_dir, cpp)) f.write(' \n') + +def mk_vs_proj_link_exe(f, name, debug): + f.write(' \n') + f.write(' $(OutDir)%s.exe\n' % name) + f.write(' true\n') + f.write(' Console\n') + f.write(' 8388608\n') + f.write(' false\n') + f.write(' \n') + f.write(' MachineX86\n') + f.write(' %(AdditionalLibraryDirectories)\n') + f.write(' psapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)\n') + f.write(' \n') + +def mk_vs_proj(name, components): + if not VS_PROJ: + return + proj_name = '%s.vcxproj' % os.path.join(BUILD_DIR, name) + modes=['Debug', 'Release'] + PLATFORMS=['Win32'] + f = open(proj_name, 'w') + f.write('\n') + f.write('\n') + mk_vs_proj_property_groups(f, name, 'Application') + f.write(' \n') + mk_vs_proj_cl_compile(f, name, components, debug=True) + mk_vs_proj_link_exe(f, name, debug=True) + f.write(' \n') + f.write(' \n') + mk_vs_proj_cl_compile(f, name, components, debug=False) + mk_vs_proj_link_exe(f, name, debug=False) + f.write(' \n') + mk_vs_proj_dep_groups(f, name, components) + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.close() + if is_verbose(): + print("Generated '%s'" % proj_name) + +def mk_vs_proj_link_dll(f, name, debug): + f.write(' \n') + f.write(' $(OutDir)%s.dll\n' % name) + f.write(' true\n') + f.write(' Console\n') + f.write(' 8388608\n') + f.write(' false\n') + f.write(' \n') + f.write(' MachineX86\n') + f.write(' %(AdditionalLibraryDirectories)\n') + f.write(' psapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)\n') + f.write(' %s' % os.path.join(get_component('api_dll').to_src_dir, 'api_dll.def')) + f.write(' \n') + +def mk_vs_proj_dll(name, components): + if not VS_PROJ: + return + proj_name = '%s.vcxproj' % os.path.join(BUILD_DIR, name) + modes=['Debug', 'Release'] + PLATFORMS=['Win32'] + f = open(proj_name, 'w') + f.write('\n') + f.write('\n') + mk_vs_proj_property_groups(f, name, 'DynamicLibrary') + f.write(' \n') + mk_vs_proj_cl_compile(f, name, components, debug=True) + mk_vs_proj_link_dll(f, name, debug=True) + f.write(' \n') + f.write(' \n') + mk_vs_proj_cl_compile(f, name, components, debug=False) + mk_vs_proj_link_dll(f, name, debug=False) + f.write(' \n') + mk_vs_proj_dep_groups(f, name, components) f.write(' \n') f.write(' \n') f.write(' \n') @@ -3478,7 +3512,7 @@ class MakeRuleCmd(object): @classmethod def _install_root(cls, path, in_prefix, out, is_install=True): if not in_prefix: - # The Python bindings on OSX are sometimes not installed inside the prefix. + # The Python bindings on OSX are sometimes not installed inside the prefix. install_root = "$(DESTDIR)" action_string = 'install' if is_install else 'uninstall' cls.write_cmd(out, 'echo "WARNING: {}ing files/directories ({}) that are not in the install prefix ($(PREFIX))."'.format(