[分享]PY的Boost自动编译程序 1.1 根据环境自动编译
Python写的Boost自动编译程序 1.1
改进:
根据自己的环境筛选出已安装环境,并列出 环境提供选择。
支持X64位的自动参数编译。
可以选择编译的参数,其他版本持续改进中
自动编译自动安装到指定目录(需要自己改PY代码)
有需要改进的请继续,自行修改,修改请保留作者版权。
已测试过 WIN10下自动编译B2和编译VS2010版BOOST 1.61
目前仅支持VS2010以及未来版本,仅支持BOOST 1.53以上版本
源码:
# Code by koangel # EMail: jackliu100@gmail.com # version : 1.1 beta # boost 全自动编译工具,仅用于WIN32编译 # import os import sys import string import signal import platform import time reload(sys) # 全局变量设置 # # boost的源码路径 boost_work_path = "E:/boost/boost_1_61_0" # build log文件名 build_log_file_name = "build_log.txt" # 启动环境变量输出 is_write_evn_log = False # 原始目录 temp_old_path = "" ISOTIMEFORMAT='%Y-%m-%d %X' # vc环境 g_vs_env_data = [ # env , vc ver ["VS100COMNTOOLS","VC100","Visual Studio 2010",False,"Microsoft Visual Studio 10.0","10.0"], ["VS110COMNTOOLS","VC110","Visual Studio 2012",False,"Microsoft Visual Studio 11.0","11.0"], ["VS120COMNTOOLS","VC120","Visual Studio 2013",False,"Microsoft Visual Studio 12.0","12.0"], ["VS140COMNTOOLS","VC140","Visual Studio 2015",False,"Microsoft Visual Studio 14.0","14.0"], ["VS150COMNTOOLS","VC150","Visual Studio 2016",False,"Microsoft Visual Studio 15.0","15.0"], ] vaild_vs_num = 0 VERSION_KEY = 'VISUALSTUDIOVERSION' # boost编译选项 ,请在此处调整 # 输出目录 build_install_path = "E:/boost/boost_1_61_0" # 构建32位还是64位 build_is_x64 = True # 线程模式(不建议修改 ,保持默认) build_threading_link = "multi" # 链接模式 build_is_shared_link = False # 运行库链接模式 build_is_shared_runtime = False # 编译模式(不建议调试) build_variant = "debug,release" # 某些特殊编译模式 build_is_with_python = False build_is_with_MPI = False def getLogPath(): return boost_work_path + "/" + build_log_file_name # 写出函数 def logtofile(str): type = sys.getfilesystemencoding() timeStr = time.strftime(ISOTIMEFORMAT,time.localtime(time.time())) print("["+ timeStr + "] " +str.decode('utf-8').encode(type)) os.system("echo " + "["+ timeStr + "] " + str.decode('utf-8').encode(type) + " >> " + getLogPath()) def build_b2_tools( toPath ): logtofile("正在构建B2工具集,请耐心等待....") os.system(toPath + " & bootstrap.bat >> " + getLogPath() ) logtofile("构建B2工具集完成...") def check_compiler_env() : logtofile("开始检测VS环境是否有效...") isFindVC = False vaild_vs_num = 0 for vi in g_vs_env_data: if os.environ.has_key(vi[0]) : logtofile(" 环境:" + vi[2] + " 有效...") vi[3] = True vaild_vs_num = vaild_vs_num+1 else: logtofile(" 环境:" +vi[2] + " 无效...") isFindVC = True return isFindVC def write_env_data(): if is_write_evn_log : logtofile("输出全部环境变量:") for ev in os.environ.data: logtofile("环境变量:" + str(ev) + " data:" + os.environ[ev]) def main(): print("===========================================================================") print(" Boost Auto Build Tools for Windows Version 1.1 beta") print(" Code by Koangel , Using Python 2.7 ") print(" weibo: http:\\www.weibo.com/koangel") print(" Visual Studio for vs2010 or newer ") print(" Boost for boost 1.53 or newer ") print("===========================================================================") sys.setdefaultencoding('gbk') #os.remove(getLogPath()) logtofile("检测是否为WINDOWS...") if (os.name != 'nt'): logtofile("非WINDOWS环境,无法运行...") return write_env_data() # 检查编译环境 logtofile("检测是否安装VS环境....") if (check_compiler_env() == False) : logtofile("未安装VS环境无法继续...") return logtofile("请选择X86 or X64:( 1、x86 2、x64 )...") addrMode = int(raw_input("Select:")) if addrMode == '1' or addrMode == 1: build_is_x64 = False elif addrMode == '2' or addrMode == 2: build_is_x64 = True else: logtofile("选择错误,请重新运行...") return logtofile("请选择Runtime模式:( 1、Shared Runtime 2、Static Runtime )...") smode = int(raw_input("Select:")) if smode == 1: build_is_shared_runtime = True else: build_is_shared_runtime = False logtofile("请选择Link模式:( 1、Shared 2、Static )...") smode = int(raw_input("Select:")) if smode == 1: build_is_shared_link = True else: build_is_shared_link = False nVSIDX = 1 logtofile("请选择一个您需要的编译器版本:") gvslist = [] for vevi in g_vs_env_data: if vevi[3] : logtofile(" " + str(nVSIDX) + "、" + vevi[4] + "。") gvslist.append(vevi) nVSIDX += 1 vsSel = int(raw_input("Select:")) if vsSel < 0 or vsSel > len(gvslist): logtofile("无效的选项,超出选项索引...") return # 运行关键内容 targetVSEnv = gvslist[vsSel-1] logtofile("选择编译环境:" + targetVSEnv[4]) toPath = 'call \"'+os.environ[targetVSEnv[0]] + '..\\..\\VC\\vcvarsall.bat\"' if build_is_x64: toPath += " x86_amd64" else: toPath += " x86" #os.system(toPath) temp_old_path = os.path # 进入BOOST目录 logtofile("跳转进入工作目录...") os.chdir(boost_work_path); #if (os.environ.has_key(VERSION_KEY) == False) : # logtofile("未检测到VS环境,自动输出使用方法:") # logtofile(" 首先使用指定版本的VC工具性运行命令行,具体方法为打开,请尽量使用x86_x64兼容命令行。") # logtofile(" 以VS2010为例:从vs2010的工具菜单进入命令提示窗口(单击“开始”按钮,指向“所有程序”,指向“Microsoft Visual Studio 2010”,指向“Visual Studio tools(工具)”,然后单击“Visual Studio 2010 command prompt(命令提示)”") # logtofile(" 之后运行本Python程序即可,Coding by koangel。") # return toVersion = targetVSEnv[5] #str(os.environ[VERSION_KEY]) # 写出选项 logtofile("检测B2工具集....") if (os.access("b2.exe",os.F_OK) == False) : build_b2_tools(toPath) # X86 还是 X64选项 cpuMode = "86" if build_is_x64: cpuMode = "64" logtofile("检测并构建编译命令...") boost_cmd = "b2 --toolset=msvc-" + toVersion.strip() if (build_is_with_python == False ): boost_cmd += " --without-python" if (build_is_with_MPI == False ): boost_cmd += " --without-mpi" boost_cmd += " threading=" + build_threading_link boost_cmd += " link=" if build_is_shared_link: boost_cmd += "shared" else: boost_cmd += "static" boost_cmd += " runtime-link=" if build_is_shared_runtime: boost_cmd += "shared" else: boost_cmd += "static" boost_cmd += " variant=" + build_variant if build_is_x64: boost_cmd += " address-model="+cpuMode boost_cmd += ' --prefix="' + build_install_path + '"' if build_is_x64 : boost_cmd += ' --stagedir=".\\bin\\x64"' logtofile("生成指令:" + boost_cmd) # 开始编译 #logtofile( toPath + ' & ' + boost_cmd ) os.system( toPath + ' & ' + boost_cmd ) # 生成完毕 logtofile("生成BOOST完成,请检查是否存在具体错误。") # 开始安装 logtofile("开始安装BOOST...") if build_is_x64 == False: os.system(boost_cmd + " install") # ################################################################################ # ========================= # 入口函数 # ========================= if __name__ == '__main__': main()