Exemplo n.º 1
0
	def getAcrossDependencies(self, deps, key, get_context = None):
		if get_context == None:
			get_context = self.ctx

		# gether across dependencies
		val = None
		for dep in deps:
			val = api.appendToList(val, self.get(key, get_context.clone({'project': dep, 'group': '*'})))	# EJ look in all groups

		# append context specific
		return api.appendToList(val, self.get(key, get_context))
Exemplo n.º 2
0
	def get(self, key, get_context = None):
		if get_context == None:
			get_context = self.ctx

		cache_key = key + str(get_context)

		self.cache_query += 1
		if cache_key in self.cache:
			self.cache_hit += 1
			return self.cache[cache_key]

		if key not in self.config:
			self.cache[cache_key] = None
			return None

		config_key_values = self.config[key]

		rval = None
		for value in config_key_values:
			value_context = value['context']

			mismatch = False
			for get_key in get_context.ctx.keys():
				if get_key in value_context:
					if not self.filterContext(value_context[get_key], get_context.ctx[get_key]):
						mismatch = True
						break

			if mismatch == False:
				rval = api.appendToList(rval, value['value'])

		self.cache[cache_key] = rval
		return rval
Exemplo n.º 3
0
	def getLinksAcrossDependencies(self, deps, get_context = None):
		if get_context == None:
			get_context = self.ctx

		# deps are the base links
		out = copy.deepcopy(deps)

		# append explicit links for each dependency
		for dep in deps:
			links = self.get('link', get_context.clone({'project': dep, 'group': '*'}))	# EJ look in all groups
			if links != None:
				out = api.appendToList(out, [l for l in links if l not in out])

		# append context explicit links	
		links = self.get('link', get_context)
		if links != None:
			out = api.appendToList(out, [l for l in links if l not in out])

		return out
Exemplo n.º 4
0
def outputProject(make, project, projects, output_path):
	project_ctx = project['ctx']

	api.log("Output project '" + project['name'] + "'", 1)
	f = open(output_path + '/' + project['name'] + '.vcxproj', 'w')

	f.write('<?xml version="1.0" encoding="utf-8"?>\n')
	f.write('<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\n')

	# configurations
	f.write('  <ItemGroup Label="ProjectConfigurations">\n')
	for cfg in project['configurations']:
		cfg['qualified_name'] = cfg['name'] + '|' + cfg['vsplatform']
		f.write('    <ProjectConfiguration Include="' + cfg['qualified_name'] + '">\n')
		f.write('      <Configuration>' + cfg['name'] + '</Configuration>\n')
		f.write('      <Platform>' + cfg['vsplatform'] + '</Platform>\n')
		f.write('    </ProjectConfiguration>\n')
	f.write('  </ItemGroup>\n')

	# global properties
	f.write('  <PropertyGroup Label="Globals">\n')
	f.write('    <ProjectGuid>{' + project['guid'] + '}</ProjectGuid>\n')
	f.write('    <RootNamespace>' + project['name'] + '</RootNamespace>\n')
	f.write('    <Keyword>' + getProjectKeyword(make, project_ctx) + '</Keyword>\n')
	f.write('  </PropertyGroup>\n')

	# store a few commonly used values directly in the configuration
	for cfg in project['configurations']:
		cfg['deps'] = make.getDependencies(cfg['ctx'])
		cfg['links'] = make.getLinksAcrossDependencies(cfg['deps'], cfg['ctx'])
		cfg['type'] = make.getBestMatch('type', cfg['ctx'])
		cfg['cflags'] = make.get('cflags', cfg['ctx'])
		cfg['pflags'] = make.get('pflags', cfg['ctx'])

	# build the project link list across all configurations (we'll disable unused ones on a per project basis in the solution)
	project['all_link'] = None
	for cfg in project['configurations']:
		project['all_link'] = api.appendToList(project['all_link'], cfg['links'])
	if project['all_link'] != None:
		project['all_link'] = list(set(project['all_link']))

	# cpp default properties
	f.write('  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\n')

	# general project properties
	for cfg in project['configurations']:
		f.write('  <PropertyGroup ' + getCondition(cfg) + ' Label="Configuration">\n')
		outputGeneralProjectProperty(f, make, project, cfg)
		f.write('  </PropertyGroup>\n')

	# cpp extension settings
	f.write('  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\n')
	f.write('  <ImportGroup Label="ExtensionSettings">\n')
	f.write('  </ImportGroup>\n')

	# default props
	for cfg in project['configurations']:
		f.write('  <ImportGroup Label="PropertySheets" ' + getCondition(cfg) + '>\n')
		f.write('    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists(\'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props\')" Label="LocalAppDataPlatform" />\n')
		f.write('  </ImportGroup>\n')

	# user macros
	f.write('  <PropertyGroup Label="UserMacros" />\n')

	# binary output
	for cfg in project['configurations']:
		f.write('  <PropertyGroup ' + getCondition(cfg) + '>\n')
		f.write('    <OutDir>' + getBinaryPath(make, cfg) + '</OutDir>\n')
		f.write('    <IntDir>' + getIntermediatePath(make, cfg) + '</IntDir>\n')

		target_name = make.getBestMatch('target_name', cfg['ctx'])
		if not target_name:
			target_name = getBinaryName(project['name'], cfg['type'], cfg['ctx']['target'])

		suffix = make.getBestMatch('bin_suffix', cfg['ctx'])
		if suffix:
			target_name += suffix

		target_ext = make.getBestMatch('bin_ext', cfg['ctx'])
		if not target_ext:
			target_ext = getBinaryExt(cfg['type'], cfg['ctx']['target'])

		f.write('    <TargetName>' + target_name + '</TargetName>\n')
		f.write('    <TargetExt>' + target_ext + '</TargetExt>\n')
		f.write('  </PropertyGroup>\n')

	# compiler / linker properties
	for cfg in project['configurations']:
		ctx = cfg['ctx']
		suffix = make.get('bin_suffix', ctx)

		f.write('  <ItemDefinitionGroup ' + getCondition(cfg) + '>\n')

		# compiler
		cflags = cfg['cflags']

		outDir = '$(OutDir)' if 'debug' in cfg['cflags'] else '$(IntDir)'

		f.write('    <ClCompile>\n')
		f.write('      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n')
		f.write('      <WarningLevel>' + getWarningLevel(cflags) + '</WarningLevel>\n')
		f.write('      <PreprocessorDefinitions>' + getDefines(make, cfg) + '</PreprocessorDefinitions>\n')
		f.write('      <AdditionalIncludeDirectories>' + getAdditionalIncludes(make, cfg, output_path) + '</AdditionalIncludeDirectories>\n')
		f.write('      <DebugInformationFormat>' + getDebugInformation(cflags) + '</DebugInformationFormat>\n')
		f.write('      <ProgramDataBaseFileName>'+ outDir + getPDBName(project['name'], suffix) + '.pdb</ProgramDataBaseFileName>\n')
		f.write('      <Optimization>' + getOptimization(cflags) + '</Optimization>\n')
		f.write('      <ExceptionHandling>' + getUseExceptions(cflags) + '</ExceptionHandling>\n')
		f.write('      <RuntimeTypeInfo>' + getUseRTTI(cflags) + '</RuntimeTypeInfo>\n')
		f.write('      <FloatingPointModel>' + getFloatingPointModel(cflags) + '</FloatingPointModel>\n')
		
		if 'omit-frame-pointers' in cflags:
			f.write('      <OmitFramePointers>true</OmitFramePointers>\n')

		f.write('      <RuntimeLibrary>' + getRuntimeLibrary(make, cfg) + '</RuntimeLibrary>\n')

		f.write('      <MultiProcessorCompilation>' + getMultiProcessorCompilation(cflags) + '</MultiProcessorCompilation>\n')
		f.write('      <MinimalRebuild>' + getMinimalRebuild(cflags) + '</MinimalRebuild>\n')

		additionalClOptions = getAdditionalClOptions(make, cfg)
		if additionalClOptions != None:
			f.write('      <AdditionalOptions>' + additionalClOptions + ' %(AdditionalOptions)</AdditionalOptions>\n')

		align_dict = {'struct-member-align-1': 1, 'struct-member-align-2': 2, 'struct-member-align-4': 4, 'struct-member-align-8': 8, 'struct-member-align-16': 16}
		for key in align_dict.keys():
			if key in cflags:
				f.write('      <StructMemberAlignment>' + str(align_dict[key]) + 'Bytes</StructMemberAlignment>\n')
				break

		if 'x64' not in ctx['arch'] and 'use-sse2' in cflags:
			f.write('      <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>\n')

		outputPrecompiledHeaderTags(f, make, cfg)
		f.write('    </ClCompile>\n')

		f.write('    <Link>\n')
		f.write('      <SubSystem>' + getSubSystem(make, cfg) + '</SubSystem>\n')
		f.write('      <AdditionalDependencies>' + getAdditionalDependencies(make, cfg, projects) + '</AdditionalDependencies>\n')
		f.write('      <AdditionalLibraryDirectories>' + getAdditionalLibraryDirectories(make, cfg, output_path) +'</AdditionalLibraryDirectories>\n')
		f.write('      <GenerateDebugInformation>' + ('True' if ('debug' in cfg['cflags'] or 'debug-info' in cfg['cflags']) else 'False') + '</GenerateDebugInformation>\n')

		ModuleDefFile = getModuleDefinitionFile(make, cfg);
		if (ModuleDefFile != None):
			f.write('      <ModuleDefinitionFile>' + ModuleDefFile + '</ModuleDefinitionFile>\n')

		additionalLinkOptions = getAdditionalLinkOptions(make, cfg)
		if additionalLinkOptions != None:
			f.write('      <AdditionalOptions>' + additionalLinkOptions + ' %(AdditionalOptions)</AdditionalOptions>\n')

		UACExecutionLevel = getUACExecutionLevel(make, cfg)
		if UACExecutionLevel != None:
			f.write('      <UACExecutionLevel>' + UACExecutionLevel + '</UACExecutionLevel>\n')

		outputAdditionalLinkTags(f, make, cfg)

		f.write('    </Link>\n')

		f.write('    <Lib>\n')

		additionalLibDependencies = getAdditionalLibDependencies(make, cfg)
		if additionalLibDependencies != None:
			f.write('      <AdditionalDependencies>' + additionalLibDependencies + '</AdditionalDependencies>\n')

		LibTargetMachine = getLibTargetMachine(make, cfg)
		if LibTargetMachine != None:
			f.write('      <TargetMachine>' + LibTargetMachine + '</TargetMachine>\n')

		f.write('    </Lib>\n')

		PreBuildEventCommand = getPreBuildEventCommand(make, cfg)
		PreBuildEventMessage = getPreBuildEventMessage(make, cfg)
		if (PreBuildEventCommand != None):
			f.write('    <PreBuildEvent>\n')
			f.write('      <Command>' + PreBuildEventCommand + '</Command>\n')
			if (PreBuildEventMessage != None):
				f.write('      <Message>' + PreBuildEventMessage + '</Message>\n')
			f.write('    </PreBuildEvent>\n')


		PreLinkEventCommand = getPreLinkEventCommand(make, cfg)
		PreLinkEventMessage = getPreLinkEventMessage(make, cfg)
		if (PreLinkEventCommand != None):
			f.write('    <PreLinkEvent>\n')
			f.write('      <Command>' + PreLinkEventCommand + '</Command>\n')
			if (PreLinkEventMessage != None):
				f.write('      <Message>' + PreLinkEventMessage + '</Message>\n')
			f.write('    </PreLinkEvent>\n')

		PostBuildEventCommand = getPostBuildEventCommand(make, cfg)
		PostBuildEventMessage = getPostBuildEventMessage(make, cfg)
		if (PostBuildEventCommand != None):
			f.write('    <PostBuildEvent>\n')
			f.write('      <Command>' + PostBuildEventCommand + '</Command>\n')
			if (PostBuildEventMessage != None):
				f.write('      <Message>' + PostBuildEventMessage + '</Message>\n')
			f.write('    </PostBuildEvent>\n')

		f.write('  </ItemDefinitionGroup>\n')

	# source files
	project['files'] = []
	for cfg in project['configurations']:	# grab across all configurations
		cfg['files'] = make.get('files', cfg['ctx'])
		if cfg['files']:
			cfg['files'] = [getSolutionFileName(file, output_path) for file in cfg['files']]
			project['files'].extend(cfg['files'])

	project['files'] = list(set(project['files']))
	project['files'] = [{'name': file, 'skip_cfg': [], 'bigobj_cfg': [], 'nopch_cfg': []} for file in project['files']]

	if len(project['files']) == 0:
		api.warning("No files added to project '" + project['name'] + "' in context " + str(project_ctx), 1)

	# skipped configurations per file
	def getProjectFile(name):
		for file in project['files']:
			if file['name'] == name:
				return file
		return None

	for cfg in project['configurations']:
		skips = make.get('skip_files', cfg['ctx'])
		if skips:
			for skip in skips:
				file = getProjectFile(getSolutionFileName(skip, output_path))
				if file:
					file['skip_cfg'].append(cfg)

	for file in project['files']:
		for cfg in project['configurations']:
			if file['name'] not in cfg['files']:
				file['skip_cfg'].append(cfg)

	# PCH creation per configuration
	for cfg in project['configurations']:
		create_pch = make.get('create_pch', cfg['ctx'])
		cfg['create_pch'] = api.getRelativePath(create_pch[0], output_path, 'windows') if create_pch != None else ''

	# big obj per file
	for cfg in project['configurations']:
		nopchs = make.get('big_obj', cfg['ctx'])
		if nopchs:
			for nopch in nopchs:
				file = getProjectFile(getSolutionFileName(nopch, output_path))
				if file:
					file['bigobj_cfg'].append(cfg)

	for file in project['files']:
		for cfg in project['configurations']:
			if file['name'] not in cfg['files']:
				file['bigobj_cfg'].append(cfg)
	
	# no pch per file
	for cfg in project['configurations']:
		nopchs = make.get('no_pch', cfg['ctx'])
		if nopchs:
			for nopch in nopchs:
				file = getProjectFile(getSolutionFileName(nopch, output_path))
				if file:
					file['nopch_cfg'].append(cfg)

	for file in project['files']:
		for cfg in project['configurations']:
			if file['name'] not in cfg['files']:
				file['nopch_cfg'].append(cfg)

	# distribute over file categories	
	distributeProjectFiles(make, project, output_path)

	# output include files
	f.write('  <ItemGroup>\n')
	for file in project['include_files']:
		openIncludeFileClDirective(f, project, file, output_path)
		outputIncludeFileClDirective(f, make, project, file, output_path)
		closeIncludeFileClDirective(f, project, file, output_path)
	f.write('  </ItemGroup>\n')

	# output compilation units
	f.write('  <ItemGroup>\n')
	for file in project['source_files']:
		openCompileFileClDirective(f, project, file, output_path)
		outputCompileFileClDirective(f, make, project, file, output_path)
		outputPCHDirective(f, project, file)
		outputBigObjDirective(f, project, file)
		outputNoPchDirective(f, file)
		outputExcludeFileFromBuildDirective(f, file)
		closeCompileFileClDirective(f, project, file, output_path)
	f.write('  </ItemGroup>\n')

	# output resource compilation
	f.write('  <ItemGroup>\n')
	for file in project['resource_files']:
		f.write('    <ResourceCompile Include=\"' + file['name'] + '\" />\n')
	f.write('  </ItemGroup>\n')

	# output custom units
	f.write('  <ItemGroup>\n')
	for file in project['custom_files']:
		openCustomFileClDirective(f, project, file, output_path)
		outputCustomFileClDirective(f, make, project, file, output_path)
		outputPCHDirective(f, project, file)
		outputBigObjDirective(f, project, file)
		outputNoPchDirective(f, file)
		outputExcludeFileFromBuildDirective(f, file)
		closeCustomFileClDirective(f, project, file, output_path)
	f.write('  </ItemGroup>\n')

	# project dependencies
	common_links = copy.deepcopy(project['all_link'])	# links common to all configurations
	for cfg in project['configurations']:
		if cfg['links'] != None:
			common_links = [link for link in common_links if link in cfg['links']]

	for cfg in project['configurations']:				# links specific to this configuration
		if cfg['links'] != None:
			cfg['cfg_links'] = [link for link in cfg['links'] if link not in common_links]

	if common_links and len(common_links) > 0:
		f.write('  <ItemGroup>\n')
		for link in common_links:
			prj = getProject(projects, link)
			if prj != None:
				f.write('    <ProjectReference Include="' + prj['name'] +'.vcxproj">\n')
				f.write('      <Project>{' + prj['guid'] +'}</Project>\n')
				f.write('    </ProjectReference>\n')
		f.write('  </ItemGroup>\n')

	for cfg in project['configurations']:
		if 'cfg_links' in cfg and len(cfg['cfg_links']) > 0:
			f.write('  <ItemGroup ' + getCondition(cfg) + '>\n')
			for link in cfg['cfg_links']:
				prj = getProject(projects, link)
				if prj != None:
					f.write('    <ProjectReference Include="' + prj['name'] +'.vcxproj">\n')
					f.write('      <Project>{' + prj['guid'] +'}</Project>\n')
					f.write('    </ProjectReference>\n')
			f.write('  </ItemGroup>\n')

	# extensions
	f.write('  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\n')
	f.write('  <ImportGroup Label="ExtensionTargets">\n')
	f.write('  </ImportGroup>\n')

	f.write('  <ProjectExtensions>\n')
	outputProjectExtensionTag(f, make, project)
	f.write('  </ProjectExtensions>\n')

	# project done, next!
	f.write('</Project>\n')