下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
#!/usr/bin/python"""2015.06.30ModifIEd some functions.Now this configration can be run on both windows and linux.*************************************************************************************2015.06.29This is a configration function code which can be only run on Win SysWritten by Grey 2015.06.29"""#Coding:utf-8import os,shutil,re# Function DeleteCmakefilesDirectory can delete the directory generated by cmake.def DeleteCmakefilesDirectory(): try: shutil.rmtree("./CMakefiles") except: print "cannot find the object!"# Function RemoveEmptyFolder can remove all the empty folders in pwddef RemoveEmptyFolder(): for root,dirs,files in os.walk("./"): if dirs == [] and files == []: os.rmdir(root)# Function subdirectoryCmakeListsGen can generate a CMakeLists.txt for a subdirectorydef subdirectoryCmakeListsGen(): pwd = os.getcwd() directory_name = os.path.basename(pwd) directory_source_name = directory_name + '_DIR_SRCS' directory_lib_name = directory_name + '_lib' cmakeLists_obj = open('CMakeLists.txt','w') cmakeLists_obj.write("aux_source_directory(. %s)\n" % directory_source_name) cmakeLists_obj.write("add_library(%s ${%s})\n\n" % (directory_lib_name,directory_source_name)) cmakeLists_obj.close()def MainCmakeListsGen(): cmakeLists_obj = open('CMakeLists.txt','w') pwd = os.getcwd() directory_name = os.path.basename(pwd) directory_source_name = directory_name + '_DIR_SRCS' directory_lib_name = directory_name + '_lib' cmakeLists_obj = open('CMakeLists.txt','w') cmakeLists_obj.write("cmake_minimum_required(VERSION 3.3)\n") cmakeLists_obj.write("project(%s_prj)\n" % directory_name) cmakeLists_obj.write("aux_source_directory(. %s)\n" % directory_source_name) cmakeLists_obj.write("add_subdirectory_for_replace\n") cmakeLists_obj.write("add_executable(%s_bin ${%s})\n" % (directory_name,directory_source_name)) cmakeLists_obj.write("target_link_librarIEs(%s_bin all_libs_for_replace)\n" % directory_name) cmakeLists_obj.close()def MainCmakeListsUpdate(): main_text = open('CMakeLists.txt','r').read() include_text = open('include.txt','r').read() subdirectory_text = open('subdirectory.txt','r').read() lib_text = open('lib_List.txt','r').read() subdirectory_text = re.sub(r'add_subdirectory\(./\)\n','',subdirectory_text) main_text = re.sub('add_subdirectory_for_replace','%s',main_text) % (include_text + '\n' + subdirectory_text) main_text = re.sub('all_libs_for_replace',main_text) % lib_text main_text = re.sub(r'\','/',main_text) main_text = re.sub(r'\n\n','\n',main_text) main_write_fID = open('CMakeLists.txt','w') main_write_fID.write(main_text) main_write_fID.close()def MainConfig(): # step1 : delete all the empty code folders RemoveEmptyFolder() # step2 : delete 'CMakefiles' in main folder DeleteCmakefilesDirectory() # step3 : process for subdirectorIEs subdirectorIEs = [] sub_libs = [] pwd = os.getcwd() for root,files in os.walk("./"): os.chdir(root) DeleteCmakefilesDirectory() subdirectoryCmakeListsGen() subdirectorIEs.append(root) subdirectory_name = os.path.basename(root) sub_libs.append(subdirectory_name + "_lib") os.chdir(pwd) include_obj = open('include.txt','w') subdir_obj = open('subdirectory.txt','w') include_obj.write("include_directorIEs(") for subdirectory in subdirectorIEs: include_obj.write("%s " % subdirectory) subdir_obj.write("add_subdirectory(%s)\n" % subdirectory) include_obj.write(")") include_obj.close() subdir_obj.close() # step4 : try to generate main CMakeLists.txt MainCmakeListsGen() lib_flag = 0 lib_List_obj = open('lib_List.txt','w') for each_sub_lib in sub_libs: if lib_flag != 0: lib_List_obj.write("%s " % each_sub_lib) lib_flag += 1 lib_List_obj.close() MainCmakeListsUpdate()MainConfig()
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的基于Python的cmake多目录工程的自动配置实现全部内容,希望文章能够帮你解决基于Python的cmake多目录工程的自动配置实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)