def gen_project_builditems(outfile, inproj, independencies, nitems): builditems = builditems_list( inproj) # [ {'file':str, 'filter':str, 'options':[]} ] custombuilds = builditems_custombuilds(inproj) for i in builditems: type = builditem_type(i['file'], custombuilds) if is_builditem_excluded_from_all_cfgs(i['options']): type = 'None' # never included => see http://msdn.microsoft.com/en-us/library/0c6xyb66.aspx i['type'] = type relpath = fs.FileToFile(i['file'], outfile.path) n = nitems.AddNode(type).Define('Include', relpath) gen_project_builditem_metadata(n, i, custombuilds) # Project References if independencies: for dep in independencies: pdep = find_project(dep) pdeppath = pdep.GetOutpath(defext='2010.%s.vcxproj' % sidl.GetPlatform().lower()) pdeppathr = fs.FileToFile(pdeppath, outfile.path) ref = nitems.AddNode('ProjectReference').Define( 'Include', pdeppathr) ref.AddNode('Project').Append('{%s}' % msvc_uuid(dep)) ref.AddNode('ReferenceOutputAssembly').Append('false') ref.AddNode('LinkLibraryDependencies').Append('true') return builditems
def gen_project_filters(outfile, inproj, builditems): def register_filter_rec(f): if not f: return if not IsList(f): f = f.split('.') register_filter_rec(f[0:-1]) s = '\\'.join(f) filters[s] = msvc_uuid(s) outfile.Append('<?xml version="1.0" encoding="utf-8"?>\n') nproject = SIDL_Outputnode('Project').Define('xmlns','http://schemas.microsoft.com/developer/msbuild/2003') \ .Define('ToolsVersion','4.0') g = nproject.AddNode('ItemGroup') # generate filters filters = {} for i in builditems: # [ {'file':str, 'type':str, 'filter':str, 'options':[]} ] register_filter_rec(i['filter']) for f in sorted(filters.keys()): g.AddNode('Filter').Define('Include', f).AddNode('UniqueIdentifier').Append( '{%s}' % filters[f]) # generate items for i in builditems: # [ {'file':str, 'type':str, 'filter':str, 'options':[]} ] relpath = fs.FileToFile(i['file'], outfile.path) g.AddNode(i['type']).Define('Include', relpath).AddNode('Filter').Append( i['filter'].replace('.', '\\')) outfile.Append(nproject) return 1
def gen_solution ( output, solobj ) : outsol = SIDL_Outputfile( path = solobj.GetOutpath(defext='2008.%s.sln'%sidl.GetPlatform().lower()), source = solobj, label = "MSVC 2008 solution '%s'" % solobj.uri, readonly= False ) output.append( outsol ) # MSVC 2008 outsol.Append( 'Microsoft Visual Studio Solution File, Format Version 10.00\n' ) outsol.Append( '# Visual Studio 2008\n' ) for pname in solobj.projects : pobj = find_project( pname ) if pobj : # generates project lines puuid = msvc_uuid( pobj.uri ) ppath = pobj.GetOutpath( defext='2008.%s.vcproj'%sidl.GetPlatform().lower() ) projlines = gen_project( output, ppath, pobj ) if projlines : relpath = fs.FileToFile( ppath, outsol.path ) outsol.Append( 'Project("{{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}}") = "%s", "%s", "{%s}"\n' % (pobj.uri,relpath,puuid) ) pdeps = solobj.dependencies.get( pname, [] ) for pdep in pdeps : outsol.Append( '# dep with %s\n' % pdep ) pdepuuid = msvc_uuid( pdep ) outsol.Append( 'ProjectSection(ProjectDependencies) = postProject\n' ) outsol.Append( '\t{%s} = {%s}\n' % (pdepuuid,pdepuuid) ) outsol.Append( 'EndProjectSection\n' ) outsol.Append( 'EndProject\n' ) # outputs the project file outproj = SIDL_Outputfile( path = ppath, source = pobj, label = "MSVC 2008 project '%s'"%pobj.uri, lines = projlines, readonly= False ) output.append( outproj ) # outputs the project's metadata file projfiles = sidl.CollectProjectFiles( pname ) gen_vcsidl( output, pobj, collectfiles=projfiles ) # register directories to clean up sidl.ShelfOutfile( '%s/tmp' % os.path.dirname(outsol.path) )
def gen_objlist_and_genericrules( outLines, inProjObj, inSolPath ) : vname_objdir = get_vname_objdir( inProjObj ) vname_objlst = get_vname_objlst( inProjObj ) outLines.Append( "%s = " % ( vname_objlst ) ) fileA = get_file_lst( inProjObj, g_compile_file_ext ) dirA_c = [] dirA_cpp = [] for f in fileA : d, f = os.path.split( f ) f, e = os.path.splitext( f ) d = fs.FileToFile( d, inSolPath ).replace( '/', '\\' ) + '\\' if e == '.c' and not d in dirA_c : dirA_c.append( d ) if e == '.cpp' and not d in dirA_cpp : dirA_cpp.append( d ) outLines.Append( "\\\n\t$(%s)/%s.o " % ( vname_objdir, f ) ) outLines.Newline( 2 ) vname_cflags = get_vname_cflags( inProjObj ); vname_lflags = get_vname_lflags( inProjObj ); outLines.Append( "# Generate generic rules for c\n" ) for d in dirA_c : outLines.Append( '{%s}.c{$(%s)}.o:\n' %( d, vname_objdir ) ) outLines.Append( '\t@-echo $<\n' ) outLines.Append( '\t@-$(GCC) -o $@ -c $< $(CFLAGS) $(%s)\n' %( vname_cflags ) ) outLines.Append( "# Generate generic rules for cpp\n" ) for d in dirA_cpp : outLines.Append( '{%s}.cpp{$(%s)}.o:\n' %( d, vname_objdir ) ) outLines.Append( '\t@-echo $<\n' ) outLines.Append( '\t@-$(GPP) -o $@ -c $< $(CFLAGS) $(CFLAGS_cpp) $(%s)\n' %( vname_cflags ) ) outLines.Newline( 2 )
def gen_file ( projpath, filepath, custombuilds=None, options=None ) : lines = [] relpath = fs.FileToFile( filepath, projpath ) lines.append( '<File\n\tRelativePath="%s"\n\t>\n' % relpath ) # sort options by configuration coptions = conf_options( options ) for confname in msvc_configurations.keys(): # excluded from build ? if 1: excluded = False for cname,copts in coptions.items() : cname = confname if cname=='all' else cname if cname!=confname: excluded = True if 'excludedfrombuild' in copts: excluded = True if excluded : lines.append( '\t<FileConfiguration\n' ) lines.append( '\t'*2 + 'Name="%s|Win32"\n' % confname ) lines.append( '\t'*2 + 'ExcludedFromBuild="true"\n' ) lines.append( '\t'*2 + '>\n' ) lines.append( '\t</FileConfiguration>\n' ) continue # custom build ? if custombuilds: for pattern,cb in custombuilds[confname].items() : if fnmatch.fnmatch(filepath,pattern) : lines.append( '\t<FileConfiguration\n' ) lines.append( '\t'*2 + 'Name="%s|Win32"\n' % confname ) lines.append( '\t'*2 + '>\n' ) lines.append( '\t'*2 + '<Tool\n' ) lines.append( '\t'*3 + 'Name="VCCustomBuildTool"\n' ) lines.append( '\t'*3 + 'CommandLine="%s"\n' % (msvc_stringvalue(cb['CommandLine'])) ) lines.append( '\t'*3 + 'Outputs="%s"\n' % (msvc_stringvalue(cb['Outputs'])) ) lines.append( '\t'*3 + 'Description="%s"\n' % (msvc_stringvalue(cb['Description'])) ) lines.append( '\t'*2 + '/>\n' ) lines.append( '\t</FileConfiguration>\n' ) lines.append( '</File>\n' ) return lines
def gen_configuration ( output, confname, projobj, projpath ) : msvcco = msvc_common msvccf = msvc_configurations[confname] projbuild = projobj.GetAttribute('build') or 'program' buildtmp = '%s/msvc2008/$(ProjectName) - $(ConfigurationName)' % (sidl.SubstModuleAttribute('genproj','tmpdir',obj=projobj) or '$(SolutionDir)') platformext = get_platform_ext() target = projobj.GetAttribute('target') if not target: target = projobj.GetOutpath() else: target = projobj.env.Subst( target ) targetpath = '%s%s' % (target,msvccf['TargetSuffix']) targetdir = os.path.dirname( targetpath ) targetbase = os.path.basename( targetpath ) targetext = platformext[projbuild] targetfile = '%s.%s' % (targetpath,targetext) cpppath = msvccf['AdditionalIncludeDirectories'] + collect_project_attributes(projobj,'cpppath',confname) cppdefines = msvccf['PreprocessorDefinitions'] + collect_project_attributes(projobj,'cppdefines',confname) cppoptions = msvcco['CppAdditionalOptions'] + collect_project_attributes(projobj,'cppoptions',confname) linkpath = msvccf['AdditionalLibraryDirectories'] + collect_project_attributes(projobj,'linkpath',confname) linklibs = msvccf['AdditionalDependencies'] + collect_project_attributes(projobj,'linklibs',confname) linkoptions = msvcco['LinkAdditionalOptions'] + collect_project_attributes(projobj,'linkoptions',confname) liboptions = msvcco['LibAdditionalOptions'] + collect_project_attributes(projobj,'liboptions',confname) rcculture = collect_project_attributes(projobj,'culture',confname) or msvcco['ResourceCompilerCulture'] lines = [] lines.append( '\n\t<Configuration' ) lines.append( '\n\t\tName="%s|Win32"' % confname ) lines.append( '\n\t\tOutputDirectory="%s"' % targetdir ) lines.append( '\n\t\tIntermediateDirectory="%s"' % buildtmp ) conftype = {'program':1, 'archive':4, 'dll':2}[projbuild] lines.append( '\n\tConfigurationType="%d"' % conftype ) lines.append( '\n\t\tCharacterSet="%s"' % msvcco['CharacterSet'] ) lines.append( '\n\t>' ) # prebuilder lines.append( '\n\t<Tool Name="VCPreBuildEventTool"' ) prebuild = gen_build_action( output, projobj, 'prebuild' ) if prebuild : actpath, actargs = prebuild relpath = fs.FileToFile( actpath, projpath ) alist = [ '%s="%s"'%(str(n),str(v)) for n,v in actargs.items() ] if actargs else '' lines.append( '\n\t\tCommandLine="%%ATPYTHON%% -u "%s" call="prebuild" project=$(InputPath) target=$(TargetPath) %s"' % (relpath,' '.join(alist)) ) lines.append( '\n\t/>') lines.append( '\n\t<Tool Name="VCCustomBuildTool" />') lines.append( '\n\t<Tool Name="VCXMLDataGeneratorTool" />') lines.append( '\n\t<Tool Name="VCWebServiceProxyGeneratorTool" />') lines.append( '\n\t<Tool Name="VCMIDLTool" />') # compiler options lines.append( '\n\t<Tool Name="VCCLCompilerTool"') if 1 : lines.append( '\n\t\tOptimization="%s"' % msvccf['Optimization'] ) lines.append( '\n\t\tFavorSizeOrSpeed="%s"' % msvccf['FavorSizeOrSpeed'] ) lines.append( '\n\t\tAdditionalOptions="%s"' % ' '.join(cppoptions) ) lines.append( '\n\t\tAdditionalIncludeDirectories="%s"' % ';'.join(cpppath) ) lines.append( '\n\t\tPreprocessorDefinitions="%s"' % ';'.join(cppdefines).replace('"','\\"') ) lines.append( '\n\t\tStringPooling="%s"' % msvcco['StringPooling']) lines.append( '\n\t\tMinimalRebuild="%s"' % msvcco['MinimalRebuild']) lines.append( '\n\t\tExceptionHandling="%s"' % msvcco['ExceptionHandling']) lines.append( '\n\t\tBasicRuntimeChecks="%s"' % msvccf['BasicRuntimeChecks']) lines.append( '\n\t\tRuntimeLibrary="%s"' % msvccf['RuntimeLibrary']) lines.append( '\n\t\tTreatWChar_tAsBuiltInType="%s"' % msvcco['TreatWChar_tAsBuiltInType']) lines.append( '\n\t\tRuntimeTypeInfo="%s"' % msvcco['RuntimeTypeInfo']) lines.append( '\n\t\tUsePrecompiledHeader="%s"' % msvcco['UsePrecompiledHeader']) lines.append( '\n\t\tBrowseInformation="%s"' % msvccf['BrowseInformation']) lines.append( '\n\t\tBrowseInformationFile="%s"' % msvcco['BrowseInformationFile']) lines.append( '\n\t\tWarningLevel="%s"' % msvcco['WarningLevel']) lines.append( '\n\t\tDetect64BitPortabilityProblems="%s"' % msvcco['Detect64BitPortabilityProblems']) lines.append( '\n\t\tEnableEnhancedInstructionSet="%s"' % msvcco['EnableEnhancedInstructionSet']) lines.append( '\n\t\tDebugInformationFormat="%s"' % msvccf['DebugInformationFormat']) lines.append( '\n\t\tCompileAs="%s"' % msvcco['CompileAs']) lines.append( '\n\t/>') # archiver options lines.append( '\n\t<Tool Name="VCLibrarianTool"') lines.append( '\n\t\tOutputFile="%s.%s"' % (targetpath,platformext['archive']) ) lines.append( '\n\t\tLinkLibraryDependencies="%s"' % msvcco['LinkLibraryDependencies']) lines.append( '\n\t\tAdditionalOptions="%s"' % ' '.join(liboptions) ) lines.append( '\n\t/>') # program linker options lines.append( '\n\t<Tool Name="VCLinkerTool"') if 1: deffile = projobj.GetAttribute('deffile') lines.append( '\n\t\tOutputFile="%s.%s"' % (targetpath,platformext['program']) ) lines.append( '\n\t\tLinkLibraryDependencies="%s"' % msvcco['LinkLibraryDependencies']) lines.append( '\n\t\tLinkIncremental="%s"' % msvcco['LinkIncremental']) lines.append( '\n\t\tAdditionalDependencies="%s"' % ' '.join(filter_platform_libs(linklibs)) ) lines.append( '\n\t\tAdditionalLibraryDirectories="%s"' % ';'.join(filter_libs(linkpath)) ) lines.append( '\n\t\tAdditionalOptions="%s"' % ' '.join(linkoptions) ) lines.append( '\n\t\tModuleDefinitionFile="%s"' % (deffile or '') ) lines.append( '\n\t\tGenerateDebugInformation="%s"' % msvccf['GenerateDebugInformation']) lines.append( '\n\t\tSubSystem="%s"' % msvcco['SubSystem']) lines.append( '\n\t\tTargetMachine="%s"' % msvcco['TargetMachine']) lines.append( '\n\t/>') # resource compiler options lines.append( '\n\t<Tool Name="VCResourceCompilerTool"') if 1: lines.append( '\n\t\tPreprocessorDefinitions="%s"' % ';'.join(cppdefines).replace('"','\\"') ) lines.append( '\n\t\tCulture="%s"' % ToList(rcculture)[0] ) lines.append( '\n\t\tAdditionalIncludeDirectories="%s"' % ';'.join(cpppath) ) lines.append( '\n\t/>') # .bsc maker options lines.append( '\n\t<Tool Name="VCBscMakeTool"') if 1: lines.append( '\n\t\tOutputFile="%s.%s"' % (targetpath,'bsc') ) lines.append( '\n\t/>') lines.append( '\n\t<Tool Name="VCManagedResourceCompilerTool" />') lines.append( '\n\t<Tool Name="VCPreLinkEventTool" />') lines.append( '\n\t<Tool Name="VCALinkTool" />') lines.append( '\n\t<Tool Name="VCManifestTool" />') lines.append( '\n\t<Tool Name="VCXDCMakeTool" />') lines.append( '\n\t<Tool Name="VCFxCopTool" />') lines.append( '\n\t<Tool Name="VCAppVerifierTool" />') lines.append( '\n\t<Tool Name="VCWebDeploymentTool" />') # postbuilder lines.append( '\n\t<Tool Name="VCPostBuildEventTool"') postbuild = gen_build_action( output, projobj, 'postbuild' ) if postbuild : actpath, actargs = postbuild relpath = fs.FileToFile( actpath, projpath ) alist = [ '%s="%s"'%(str(n),str(v)) for n,v in actargs.items() ] if actargs else '' lines.append( '\n\t\tCommandLine="%%ATPYTHON%% -u "%s" call="postbuild" project=$(InputPath) target=$(TargetPath) %s"' % (relpath,' '.join(alist)) ) lines.append( '\n\t/>') lines.append( '\n\t</Configuration>' ) return lines
def gen_solution(solobj): outfile = SIDL_Outputfile(path=solobj.GetOutpath( defext='2010.%s.sln' % sidl.GetPlatform().lower()), source=solobj, label="MSVC 2010 solution '%s'" % solobj.uri, readonly=False) outputs.append(outfile) # MSVC 2010 outfile.Append( 'Microsoft Visual Studio Solution File, Format Version 11.00\n') outfile.Append('# Visual Studio 2010\n') puuid_list = [] for pname in solobj.projects: pobj = find_project(pname) if pobj: # generates .vcxproj pdeps = solobj.dependencies.get(pname, []) puuid = msvc_uuid(pobj.uri) puuid_list.append(puuid) ppath = pobj.GetOutpath(defext='2010.%s.vcxproj' % sidl.GetPlatform().lower()) pfile = SIDL_Outputfile(path=ppath, source=pobj, label="MSVC 2010 project '%s'" % pobj.uri, readonly=False) builditems = gen_project(pfile, pobj, pdeps) outputs.append(pfile) # append project file relpath = fs.FileToFile(ppath, outfile.path) outfile.Append( 'Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "%s", "%s", "{%s}"\n' % (pobj.uri, relpath, puuid)) for pdep in pdeps: pdepuuid = msvc_uuid(pdep) outfile.Append( 'ProjectSection(ProjectDependencies) = postProject\n') outfile.Append('\t{%s} = {%s}\n' % (pdepuuid, pdepuuid)) outfile.Append('EndProjectSection\n') outfile.Append('EndProject\n') # generates .vcxproj.filters fpath = pobj.GetOutpath(defext='2010.%s.vcxproj.filters' % sidl.GetPlatform().lower()) ffile = SIDL_Outputfile(path=fpath, source=pobj, label="MSVC 2010 filters '%s'" % pobj.uri, readonly=False) gen_project_filters(ffile, pobj, builditems) outputs.append(ffile) # generates .vcxproj.user upath = pobj.GetOutpath(defext='2010.%s.vcxproj.user' % sidl.GetPlatform().lower()) ufile = SIDL_Outputfile(path=upath, source=pobj, label="MSVC 2010 user '%s'" % pobj.uri, readonly=False) gen_project_user(ufile, pobj) outputs.append(ufile) # generate .vcxsidl metadata file vcpath = pobj.GetOutpath(defext='2010.%s.vcxsidl' % sidl.GetPlatform().lower()) vcfile = SIDL_Outputfile(path=vcpath, source=pobj, label="MSVC 2010 sidl '%s'" % pobj.uri) gen_project_vcsidl(vcfile, pobj) outputs.append(vcfile) # outputs globals outfile.Append('Global\n') if 1: # GlobalSection(SolutionConfigurationPlatforms) = preSolution outfile.Append( '\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n' ) for cfg in msvc_configurations.keys(): outfile.Append('\t\t%s|Win32 = %s|Win32\n' % (cfg, cfg)) outfile.Append('\tEndGlobalSection\n') # ProjectConfigurationPlatforms outfile.Append( '\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n' ) for puuid in puuid_list: for cfg in msvc_configurations.keys(): outfile.Append('\t\t{%s}.%s|Win32.ActiveCfg = %s|Win32\n' % (puuid, cfg, cfg)) outfile.Append('\t\t{%s}.%s|Win32.Build.0 = %s|Win32\n' % (puuid, cfg, cfg)) outfile.Append('\tEndGlobalSection\n') # ProjectConfigurationPlatforms outfile.Append( '\tGlobalSection(SolutionProperties) = preSolution\n') outfile.Append('\t\tHideSolutionNode = FALSE\n') outfile.Append('\tEndGlobalSection\n') outfile.Append('EndGlobal\n') # register directories to clean up sidl.ShelfOutfile('%s/tmp' % os.path.dirname(outfile.path))