def generate(solution): import makeprojects # # Find the files to put into the project # codefiles,includedirectories = solution.getfilelist() # # Configure the xcode writer to the type # of solution requested # solution.xcode.defaults(solution) # # Ensure the slashes are correct for XCode # for item in codefiles: item.filename = burger.converttolinuxslashes(item.filename) # # Determine the ide and target type for the final file name # idecode = solution.getidecode() platformcode = solution.getplatformcode() xcodeprojectfile = Project(solution.projectname,idecode,platformcode) rootproject = xcodeprojectfile.pbxprojects[0] # # Let's create the solution file! # solutionfoldername = os.path.join(solution.workingDir,xcodeprojectfile.projectnamecode + '.xcodeproj') burger.createfolderifneeded(solutionfoldername) projectfilename = os.path.join(solutionfoldername,'project.pbxproj') # # Add the configuration file reference (or not) # if solution.xcode.configfilename!=None: configfilereference = xcodeprojectfile.addfilereference(solution.xcode.configfilename,'text.xcconfig') else: configfilereference = None # # Add the frameworks to the build list # for framework in solution.xcode.frameworks: item = makeprojects.SourceFile(framework,'','frameworks') codefiles.append(item) # # Insert all of the files found into the file references # for item in codefiles: # Remove unsupported file types if item.type!='windowsresource' and \ item.type!='macresource' and \ item.type!='hlsl': xcodeprojectfile.addfilereference(item.filename,item.type) # # What's the final output file? # if solution.kind=='library': if solution.platform=='ios': libextension = 'ios.a' else: libextension = 'osx.a' outputfilereference = xcodeprojectfile.addfilereference('lib' + solution.projectname + idecode + libextension,'lib') else: if solution.kind=='game': outputfilereference = xcodeprojectfile.addfilereference(solution.projectname + '.app','exe') else: outputfilereference = xcodeprojectfile.addfilereference(solution.projectname,'exe') # # If a fat library, add references for dev and sim targets # ioslibrary = False if solution.platform=='ios': if solution.kind=='library': ioslibrary = True if ioslibrary == True: devfilereference = xcodeprojectfile.addfilereference('lib' + solution.projectname + idecode + 'dev.a','lib') simfilereference = xcodeprojectfile.addfilereference('lib' + solution.projectname + idecode + 'sim.a','lib') # # Two targets for "fat" libraries # buildphase1 = xcodeprojectfile.addsourcesbuildphase(devfilereference) buildphase2 = xcodeprojectfile.addsourcesbuildphase(simfilereference) framephase1 = xcodeprojectfile.addframeworksbuildphase(devfilereference) framephase2 = xcodeprojectfile.addframeworksbuildphase(simfilereference) # # Add source files to compile for the ARM and the Intel libs # for item in xcodeprojectfile.pbxfilereferences: if item.type=='cpp' or item.type=='glsl': buildphase1.append(xcodeprojectfile.addbuildfile(item,devfilereference)) buildphase2.append(xcodeprojectfile.addbuildfile(item,simfilereference)) elif item.type=='frameworks': framephase1.append(xcodeprojectfile.addbuildfile(item,devfilereference)) framephase2.append(xcodeprojectfile.addbuildfile(item,simfilereference)) else: devfilereference = None simfilereference = None buildphase1 = xcodeprojectfile.addsourcesbuildphase(outputfilereference) framephase1 = xcodeprojectfile.addframeworksbuildphase(outputfilereference) for item in xcodeprojectfile.pbxfilereferences: if item.type=='cpp' or item.type=='glsl': buildphase1.append(xcodeprojectfile.addbuildfile(item,outputfilereference)) elif item.type=='frameworks': framephase1.append(xcodeprojectfile.addbuildfile(item,outputfilereference)) # # Create the root file group and the Products group # groupproducts = xcodeprojectfile.addgroup('Products',None) grouproot = xcodeprojectfile.addgroup(xcodeprojectfile.projectname,None) grouproot.appendgroup(groupproducts) # No frameworks group unless one is warranted frameworksgroup = None # # Insert all the file references into groups # for item in xcodeprojectfile.pbxfilereferences: # Products go into a special group if item.type=='exe': groupproducts.append(item) elif item.type=='lib': groupproducts.append(item) elif item.type=='frameworks': # Create the group if needed if frameworksgroup==None: frameworksgroup = xcodeprojectfile.addgroup('Frameworks',None) grouproot.appendgroup(frameworksgroup) frameworksgroup.append(item) else: # Isolate the path index = item.filename.rfind('/') if index==-1: # Put in the root group grouproot.append(item) else: # Separate the path and name base = item.filename[index+1:] path = item.filename[0:index] # # See if a group already exists # found = False for matchgroup in xcodeprojectfile.pbxgroups: if matchgroup.path!=None and matchgroup.path==path: # Add to a pre-existing group matchgroup.append(item) found = True break if found==True: continue # Group not found. Iterate and create the group # May need multiple levels # # Hack to remove preceding ../ entries # if path.startswith('../'): index = 3 elif path.startswith('../../'): index = 6 else: index = 0 notdone = True previousgroup = grouproot while notdone: endindex = path[index:].find('/') if endindex==-1: # Final level, create group and add reference matchgroup = xcodeprojectfile.addgroup(path[index:],path) matchgroup.append(item) previousgroup.appendgroup(matchgroup) notdone = False else: # # See if a group already exists # temppath = path[0:index+endindex] found = False for matchgroup in xcodeprojectfile.pbxgroups: if matchgroup.path==None: continue if matchgroup.path==temppath: found = True break if found!=True: matchgroup = xcodeprojectfile.addgroup(path[index:index+endindex],temppath) previousgroup.appendgroup(matchgroup) previousgroup = matchgroup index = index+endindex+1 # # Create the config list for the root project # configlistref = xcodeprojectfile.addxcconfigurationlist('PBXProject',xcodeprojectfile.projectnamecode) for item in solution.configurations: configlistref.configurations.append(xcodeprojectfile.addxcbuildconfigurationlist(item,configfilereference,configlistref,None,False)) rootproject.configlistref = configlistref rootproject.rootgroup = grouproot # # Create the PBXNativeTarget config chunks # sdkroot = None if solution.platform=='ios': sdkroot = 'iphoneos' if solution.kind=='library': outputtype = 'com.apple.product-type.library.static' elif solution.kind=='screensaver': outputtype = 'com.apple.product-type.bundle' elif solution.kind=='game': outputtype = 'com.apple.product-type.application' else: outputtype = 'com.apple.product-type.tool' # # For a normal project, attach the config to a native target and we're done # if ioslibrary==False: configlistref = xcodeprojectfile.addxcconfigurationlist('PBXNativeTarget',xcodeprojectfile.projectname) install = False if solution.kind=='game': install = True for item in solution.configurations: configlistref.configurations.append(xcodeprojectfile.addxcbuildconfigurationlist(item,None,configlistref,sdkroot,install)) if solution.kind=='library': finalname = xcodeprojectfile.projectnamecode else: finalname = xcodeprojectfile.projectname nativetarget1 = xcodeprojectfile.addnativeproject(finalname,outputfilereference,xcodeprojectfile.projectname,outputtype) nativetarget1.configlistref = configlistref rootproject.append(nativetarget1) nativetarget1.append(buildphase1.uuid,'Sources') nativetarget1.append(framephase1.uuid,'Frameworks') # # For fat binary iOS projects, it's a lot messier # else: targetname = xcodeprojectfile.projectnamecode configlistref = xcodeprojectfile.addxcconfigurationlist('PBXNativeTarget',targetname) for item in solution.configurations: configlistref.configurations.append(xcodeprojectfile.addxcbuildconfigurationlist(item,None,configlistref,None,False)) nativetarget1 = xcodeprojectfile.addnativeproject(targetname,outputfilereference,xcodeprojectfile.projectname,outputtype) nativetarget1.configlistref = configlistref rootproject.append(nativetarget1) targetname = solution.projectname + idecode + 'dev' configlistref = xcodeprojectfile.addxcconfigurationlist('PBXNativeTarget',targetname) for item in solution.configurations: configlistref.configurations.append(xcodeprojectfile.addxcbuildconfigurationlist(item,None,configlistref,'iphoneos',False)) nativeprojectdev = xcodeprojectfile.addnativeproject(targetname,devfilereference,xcodeprojectfile.projectname,outputtype) nativeprojectdev.configlistref = configlistref rootproject.append(nativeprojectdev) nativeprojectdev.append(buildphase1.uuid,'Sources') nativeprojectdev.append(framephase1.uuid,'Frameworks') devcontainer = xcodeprojectfile.addcontaineritemproxy(nativeprojectdev,xcodeprojectfile.uuid) targetname = solution.projectname + idecode + 'sim' configlistref = xcodeprojectfile.addxcconfigurationlist('PBXNativeTarget',targetname) for item in solution.configurations: configlistref.configurations.append(xcodeprojectfile.addxcbuildconfigurationlist(item,None,configlistref,'iphonesimulator',False)) nativeprojectsim = xcodeprojectfile.addnativeproject(targetname,simfilereference,xcodeprojectfile.projectname,outputtype) nativeprojectsim.configlistref = configlistref rootproject.append(nativeprojectsim) nativeprojectsim.append(buildphase2.uuid,'Sources') nativeprojectsim.append(framephase2.uuid,'Frameworks') simcontainer = xcodeprojectfile.addcontaineritemproxy(nativeprojectsim,xcodeprojectfile.uuid) nativetarget1.depend(xcodeprojectfile.adddependency(devcontainer,nativeprojectdev).uuid,'PBXTargetDependency') nativetarget1.depend(xcodeprojectfile.adddependency(simcontainer,nativeprojectsim).uuid,'PBXTargetDependency') # # Add in a shell script build phase if needed # # # Is this an application? # if solution.platform=='macosx': if solution.kind=='tool': input = ['${CONFIGURATION_BUILD_DIR}/${EXECUTABLE_NAME}'] output = '${SRCROOT}/bin/${EXECUTABLE_NAME}${IDESUFFIX}${SUFFIX}' command = 'if [ ! -d ${SRCROOT}/bin ]; then mkdir ${SRCROOT}/bin; fi\\n' \ '${CP} ${CONFIGURATION_BUILD_DIR}/${EXECUTABLE_NAME} ${SRCROOT}/bin/${EXECUTABLE_NAME}${IDESUFFIX}${SUFFIX}' shellbuildphase = xcodeprojectfile.addshellscriptbuildphase(input,output,command) nativetarget1.append(shellbuildphase.uuid,'ShellScript') elif solution.kind=='game': input = ['${CONFIGURATION_BUILD_DIR}/${EXECUTABLE_NAME}.app/Contents/MacOS/${EXECUTABLE_NAME}'] output = '${SRCROOT}/bin/${EXECUTABLE_NAME}${IDESUFFIX}${SUFFIX}.app/Contents/MacOS/${EXECUTABLE_NAME}${IDESUFFIX}${SUFFIX}' command = 'if [ ! -d ${SRCROOT}/bin ]; then mkdir ${SRCROOT}/bin; fi\\n' \ '${CP} -r ${CONFIGURATION_BUILD_DIR}/${EXECUTABLE_NAME}.app/ ${SRCROOT}/bin/${EXECUTABLE_NAME}${IDESUFFIX}${SUFFIX}.app/\\n' \ 'mv ${SRCROOT}/bin/${EXECUTABLE_NAME}${IDESUFFIX}${SUFFIX}.app/Contents/MacOS/${EXECUTABLE_NAME} ${SRCROOT}/bin/${EXECUTABLE_NAME}${IDESUFFIX}${SUFFIX}.app/Contents/MacOS/${EXECUTABLE_NAME}${IDESUFFIX}${SUFFIX}' shellbuildphase = xcodeprojectfile.addshellscriptbuildphase(input,output,command) nativetarget1.append(shellbuildphase.uuid,'ShellScript') # # Is there a final folder? # if solution.finalfolder!=None: if ioslibrary==False: input = ['${CONFIGURATION_BUILD_DIR}/${EXECUTABLE_NAME}'] else: input = [ '${BUILD_ROOT}/' + solution.projectname + idecode + 'dev${SUFFIX}/lib' + solution.projectname + idecode + 'dev.a', '${BUILD_ROOT}/' + solution.projectname + idecode + 'sim${SUFFIX}/lib' + solution.projectname + idecode + 'sim.a' ] finalfolder = solution.finalfolder.replace('(','{') finalfolder = finalfolder.replace(')','}') if ioslibrary==True: command = '${SDKS}/macosx/bin/p4 edit ' + finalfolder + '${FINAL_OUTPUT}\\nlipo -output ' + \ finalfolder + '${FINAL_OUTPUT} -create ${BUILD_ROOT}/' + solution.projectname + idecode + \ 'dev${SUFFIX}/lib' + solution.projectname + idecode + 'dev.a ${BUILD_ROOT}/' + solution.projectname + idecode + 'sim${SUFFIX}/lib' + solution.projectname + idecode + 'sim.a\\n'; elif solution.kind=='library': command = '${SDKS}/macosx/bin/p4 edit ' + finalfolder + '${FINAL_OUTPUT}\\n${CP} ${CONFIGURATION_BUILD_DIR}/${EXECUTABLE_NAME} ' + finalfolder + '${FINAL_OUTPUT}\\n' else: command = 'if [ \\"${CONFIGURATION}\\" == \\"Release\\" ]; then\\n${SDKS}/macosx/bin/p4 edit ' + finalfolder + '${FINAL_OUTPUT}\\n${CP} ${CONFIGURATION_BUILD_DIR}/${EXECUTABLE_NAME} ' + finalfolder + '${FINAL_OUTPUT}\\nfi\\n' shellbuildphase = xcodeprojectfile.addshellscriptbuildphase(input,solution.finalfolder + '${FINAL_OUTPUT}',command) nativetarget1.append(shellbuildphase.uuid,'ShellScript') # # Serialize the XCode file # fp = StringIO.StringIO() xcodeprojectfile.write(fp) # # Did it change? # if burger.comparefiletostring(projectfilename,fp): if solution.verbose==True: print projectfilename + ' was not changed' else: burger.perforceedit(projectfilename) fp2 = open(projectfilename,'w') fp2.write(fp.getvalue()) fp2.close() fp.close() return 0
def generate(solution): # # Configure the Visual Studio writer to the type # of solution requested # error = solution.visualstudio.defaults(solution) if error!=0: return error # # Obtain the list of files of interest to include in # the project # codefiles,includedirectories = solution.getfilelist(solution.visualstudio.acceptable) # # Create a blank project # project = Project(solution.visualstudio,solution) project.projects.append(vsProject(solution.visualstudio,codefiles,includedirectories)) # # Serialize the solution file and write if changed # fp = io.StringIO() project.writesln(fp) filename = os.path.join(solution.workingDir,solution.visualstudio.projectfilename + '.sln') if comparefiletostring(filename,fp): if solution.verbose==True: print filename + ' was not changed' else: burger.perforceedit(filename) fp2 = io.open(filename,'w') fp2.write(fp.getvalue()) fp2.close() fp.close() # # Create the project file # fp = io.StringIO() if solution.visualstudio.fileversion.value>=FileVersions.vs2010.value: project.writeproject2010(fp,solution) filename = os.path.join(solution.workingDir,solution.visualstudio.projectfilename + projectsuffix[solution.visualstudio.fileversion.value]) if comparefiletostring(filename,fp): if solution.verbose==True: print filename + ' was not changed' else: burger.perforceedit(filename) fp2 = io.open(filename,'w') fp2.write(fp.getvalue()) fp2.close() fp.close() # # If it's visual studio 2010 or higher, output the filter file if needed # if solution.visualstudio.fileversion.value>=FileVersions.vs2010.value: fp = io.StringIO() count = project.writefilter(fp) filename = os.path.join(solution.workingDir,solution.visualstudio.projectfilename + '.vcxproj.filters') # No groups found? if count==0: # Just delete the file os.remove(filename) else: # Did it change? if comparefiletostring(filename,fp): if solution.verbose==True: print filename + ' was not changed' else: # Update the file burger.perforceedit(filename) fp2 = io.open(filename,'w') fp2.write(fp.getvalue()) fp2.close() fp.close() return 0