static void GenOutputConfigs(XmlOutputGen output, string projFileVersion, List <ProjectConfiguration> projConfigs) { void GenOutputElem(string elemName, string condition, string textValue) { //NESTED method output.BeginElem(elemName); output.AddAttribute("Condition", condition); output.AppendTextNode(textValue); output.EndElem(); } //7. output.BeginElem(PROPERTY_GROUP); output.AppendSimpleElem("_ProjectFileVersion", projFileVersion); foreach (ProjectConfiguration conf in projConfigs) { ConditionConfig condConf = conf.Config.ConditionConfig; GenOutputElem(nameof(condConf.OutDir), condConf.Condition, condConf.OutDir); GenOutputElem(nameof(condConf.IntDir), condConf.Condition, condConf.IntDir); GenOutputElem(nameof(condConf.TargetName), condConf.Condition, condConf.TargetName); GenOutputElem(nameof(condConf.TargetExt), condConf.Condition, condConf.TargetExt); GenOutputElem(nameof(condConf.LinkIncremental), condConf.Condition, condConf.LinkIncremental); GenOutputElem(nameof(condConf.GenerateManifest), condConf.Condition, condConf.GenerateManifest); } output.EndElem();//property group }
static void GenPropertySheet(XmlOutputGen output, PropertySheets propertySheet) { output.BeginElem(IMPORT_GROUP); output.AddAttribute("Label", nameof(PropertySheets)); GenImport(output, propertySheet.Import); output.EndElem(); }
static void GenGlobalsProp(XmlOutputGen output, GlobalsPropertyGroup globalsProp) { output.BeginElem(PROPERTY_GROUP); output.AddAttribute(LABEL, "Globals"); output.AppendSimpleElem(nameof(globalsProp.ProjectGuid), "{6481C558-B7F1-3FA1-BA6E-AD764749B15C}"); output.AppendSimpleElem(nameof(globalsProp.WindowsTargetPlatformVersion), globalsProp.WindowsTargetPlatformVersion); output.AppendSimpleElem(nameof(globalsProp.Keyword), globalsProp.Keyword); output.AppendSimpleElem(nameof(globalsProp.Platform), globalsProp.Platform); output.AppendSimpleElem(nameof(globalsProp.ProjectName), globalsProp.ProjectName); output.AppendSimpleElem(nameof(globalsProp.VCProjectUpgraderObjectName), globalsProp.VCProjectUpgraderObjectName); output.EndElem(); }
static void GenImport(XmlOutputGen output, Import import) { output.BeginElem("Import"); output.AddAttribute(nameof(import.Project), import.Project); if (import.Label != null) { output.AddAttribute(nameof(import.Label), import.Label); } if (!string.IsNullOrEmpty(import.Condition)) { output.AddAttribute(nameof(import.Condition), import.Condition); } output.EndElem(); }
static void GenPropertyConfigs2(XmlOutputGen output, List <ProjectConfiguration> projConfigs) { foreach (ProjectConfiguration projConfig in projConfigs) { ConfigurationPropertyGroup config = projConfig.Config; output.BeginElem(PROPERTY_GROUP); output.AddAttribute(nameof(config.Condition), config.Condition); output.AddAttribute("Label", "Configuration"); output.AppendSimpleElem(nameof(config.ConfigurationType), config.ConfigurationType); output.AppendSimpleElem(nameof(config.CharacterSet), config.CharacterSet); output.AppendSimpleElem(nameof(config.PlatformToolset), config.PlatformToolset); output.EndElem(); } }
static void GenPropertyConfigs(XmlOutputGen output, List <ProjectConfiguration> projConfigs) { output.BeginElem(ITEM_GROUP); output.AddAttribute(LABEL, "ProjectConfigurations"); foreach (ProjectConfiguration projConfig in projConfigs) { output.BeginElem(nameof(ProjectConfiguration)); output.AddAttribute(nameof(projConfig.Include), projConfig.Include); output.AppendSimpleElem(nameof(projConfig.Configuration), projConfig.Configuration); output.AppendSimpleElem(nameof(projConfig.Platform), projConfig.Platform); output.EndElem(); } output.EndElem(); }
static void GenerateItemGroupDef(XmlOutputGen output, List <ProjectConfiguration> projConfigs) { foreach (ProjectConfiguration conf in projConfigs) { ItemDefinitionGroup itemDefGroup = conf.ItemDefinitionGroup; output.BeginElem(nameof(ItemDefinitionGroup)); { output.AddAttribute("Condition", conf.Config.Condition); ClCompile clcompile = itemDefGroup.ClCompile; output.BeginElem(nameof(ClCompile)); { output.AppendSimpleElem(nameof(clcompile.AdditionalIncludeDirectories), clcompile.AdditionalIncludeDirectories); output.AppendSimpleElem(nameof(clcompile.AssemblerListingLocation), clcompile.AssemblerListingLocation); output.AppendSimpleElem(nameof(clcompile.BasicRuntimeChecks), clcompile.BasicRuntimeChecks); output.AppendSimpleElem(nameof(clcompile.CompileAs), clcompile.CompileAs); output.AppendSimpleElem(nameof(clcompile.DebugInformationFormat), clcompile.DebugInformationFormat); output.AppendSimpleElem(nameof(clcompile.ExceptionHandling), clcompile.ExceptionHandling); output.AppendSimpleElem(nameof(clcompile.FloatingPointModel), clcompile.FloatingPointModel); output.AppendSimpleElem(nameof(clcompile.InlineFunctionExpansion), clcompile.InlineFunctionExpansion); output.AppendSimpleElem(nameof(clcompile.IntrinsicFunctions), clcompile.IntrinsicFunctions); output.AppendSimpleElem(nameof(clcompile.Optimization), clcompile.Optimization); output.AppendSimpleElem(nameof(clcompile.PrecompiledHeader), clcompile.PrecompiledHeader); output.AppendSimpleElem(nameof(clcompile.RuntimeLibrary), clcompile.RuntimeLibrary); output.AppendSimpleElem(nameof(clcompile.RuntimeTypeInfo), clcompile.RuntimeTypeInfo); output.AppendSimpleElem(nameof(clcompile.UseFullPaths), clcompile.UseFullPaths); output.AppendSimpleElem(nameof(clcompile.WarningLevel), clcompile.WarningLevel); output.AppendSimpleElem(nameof(clcompile.PreprocessorDefinitions), clcompile.PreprocessorDefinitions); output.AppendSimpleElem(nameof(clcompile.ObjectFileName), clcompile.ObjectFileName); } output.EndElem(); //----- ResourceCompile resCompile = itemDefGroup.ResourceCompile; output.BeginElem(nameof(ResourceCompile)); { output.AppendSimpleElem(nameof(resCompile.PreprocessorDefinitions), resCompile.PreprocessorDefinitions); output.AppendSimpleElem(nameof(resCompile.AdditionalIncludeDirectories), resCompile.AdditionalIncludeDirectories); } output.EndElem(); //----- Midl midl = itemDefGroup.Midl; output.BeginElem(nameof(Midl)); { output.AppendSimpleElem(nameof(midl.AdditionalIncludeDirectories), midl.AdditionalIncludeDirectories); output.AppendSimpleElem(nameof(midl.OutputDirectory), midl.OutputDirectory); output.AppendSimpleElem(nameof(midl.HeaderFileName), midl.HeaderFileName); output.AppendSimpleElem(nameof(midl.TypeLibraryName), midl.TypeLibraryName); output.AppendSimpleElem(nameof(midl.InterfaceIdentifierFileName), midl.InterfaceIdentifierFileName); output.AppendSimpleElem(nameof(midl.ProxyFileName), midl.ProxyFileName); } output.EndElem(); //----- Link link = itemDefGroup.Link; output.BeginElem(nameof(Link)); { output.AppendSimpleElem(nameof(link.AdditionalDependencies), link.AdditionalDependencies); output.AppendSimpleElem(nameof(link.AdditionalLibraryDirectories), link.AdditionalLibraryDirectories); output.AppendSimpleElem(nameof(link.AdditionalOptions), link.AdditionalOptions); output.AppendSimpleElem(nameof(link.GenerateDebugInformation), link.GenerateDebugInformation); output.AppendSimpleElem(nameof(link.IgnoreSpecificDefaultLibraries), link.IgnoreSpecificDefaultLibraries); output.AppendSimpleElem(nameof(link.ImportLibrary), link.ImportLibrary); output.AppendSimpleElem(nameof(link.ProgramDataBaseFile), link.ProgramDataBaseFile); output.AppendSimpleElem(nameof(link.SubSystem), link.SubSystem); } output.EndElem(); //----- output.BeginElem(nameof(ProjectReference)); { ProjectReference projRef = itemDefGroup.ProjectReference; output.AppendSimpleElem(nameof(projRef.LinkLibraryDependencies), projRef.LinkLibraryDependencies); } output.EndElem(); } output.EndElem(); } }
public static void GenerateOutput(this VcxProject proj, XmlOutputGen output) { output.AddXmlHeader(); output.BeginElem("Project"); { //---- output.AddAttribute(nameof(proj.DefaultTargets), proj.DefaultTargets); output.AddAttribute(nameof(proj.ToolVersion), proj.ToolVersion); output.AddAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003"); //---- output.BeginElem(PROPERTY_GROUP); output.AppendSimpleElem(nameof(proj.PreferredToolArchitecture), proj.PreferredToolArchitecture); output.EndElem(); } //---- //1. GenPropertyConfigs(output, proj.Configurations); //2. global prop GenGlobalsProp(output, proj.GlobalsPropertyGroup); //3. GenImport(output, proj.CppDefaultProp); //4. gen property groups's condition config GenPropertyConfigs2(output, proj.Configurations); //5. import GenImport(output, proj.CppProp); //6. GenPropertySheet(output, proj.PropertySheets); //7. GenOutputConfigs(output, proj.ProjectFileVersion, proj.Configurations); //8. GenerateItemGroupDef(output, proj.Configurations); //9. output.BeginElem(ITEM_GROUP); { foreach (InputItem inputItem in proj.InputItems) { string elem_name = ""; switch (inputItem.InputKind) { default: throw new NotSupportedException(); case InputKind.ClCompile: elem_name = nameof(InputKind.ClCompile); break; case InputKind.ClInclude: elem_name = nameof(InputKind.ClInclude); break; case InputKind.Object: elem_name = nameof(InputKind.Object); break; } output.BeginElem(elem_name); output.AddAttribute(nameof(inputItem.Include), inputItem.Include); output.EndElem(); } } output.EndElem();//item group //----- //10. GenImport(output, new Import { Project = @"$(VCTargetsPath)\Microsoft.Cpp.targets" }); output.BeginElem(IMPORT_GROUP); output.AddAttribute("Label", "ExtensionTargets"); output.EndElem(); // //<ImportGroup Label="ExtensionTargets"> output.EndElem(); //Project }
public void RebuildLibraryAndAPI() { UpdateMsBuildPath(); ProjectConfigKind configKind = ProjectConfigKind; SimpleVcxProjGen gen = new SimpleVcxProjGen(); //set some proprties //eg. IspcFilename=> simple.ispc string onlyProjectName = ProjectName; gen.ProjectName = onlyProjectName; //project name and output string current_dir = Directory.GetCurrentDirectory(); string tmp_dir = current_dir + "/temp"; gen.FullProjSrcPath = current_dir; gen.FullProjBuildPath = tmp_dir; string finalProductName = gen.GetFinalProductName(configKind); //build ispc if (!Directory.Exists(tmp_dir)) { Directory.CreateDirectory(tmp_dir); } //------------- //save primary source and header string prim_src_filename = tmp_dir + "/main_src.cpp"; string prim_header_filename = tmp_dir + "/main_src.h"; File.WriteAllText(prim_src_filename, PrimarySource); File.WriteAllText(prim_header_filename, PrimaryHeader); gen.AddCompileFile(prim_src_filename); gen.AddIncludeFile(prim_header_filename); //string c_interface_filename = gen.FullProjSrcPath + "/" + onlyProjectName + ".cpp"; //CodeCompilationUnit cu = ParseAutoGenHeaderFromFile(ispc_header); //GenerateCBinder(cu, ispc_header, c_interface_filename); //string cs_method_invoke_filename = onlyProjectName + ".cs"; //save to //GenerateCsBinder(cu, ispc_header, cs_method_invoke_filename, Path.GetFileName(finalProductName)); ////move cs code to src folder //if (AutoCsTargetFile != null) //{ // MoveFileOrReplaceIfExists(cs_method_invoke_filename, AutoCsTargetFile); //} //------------- if (AdditionalInputItems != null) { foreach (string s in AdditionalInputItems) { switch (Path.GetExtension(s)) { default: throw new NotSupportedException(); case ".c": case ".cpp": gen.AddCompileFile(s); break; case ".h": case ".hpp": gen.AddIncludeFile(s); break; case ".obj": gen.AddObjectFile(s); break; } } } VcxProject project = gen.CreateVcxTemplate(); XmlOutputGen xmlOutput = new XmlOutputGen(); project.GenerateOutput(xmlOutput); string vxs_projOutputFilename = "myvcx_autogen.xml.vcxproj"; File.WriteAllText(vxs_projOutputFilename, xmlOutput.Output.ToString()); //debug build or release build string p_config = ""; switch (configKind) { default: throw new NotSupportedException(); case ProjectConfigKind.Debug: p_config = " /p:configuration=debug"; break; case ProjectConfigKind.Release: p_config = " /p:configuration=release"; break; } System.Diagnostics.Process proc1 = System.Diagnostics.Process.Start(s_MsBuildPath, vxs_projOutputFilename + p_config); proc1.WaitForExit(); int exit_code1 = proc1.ExitCode; if (exit_code1 != 0) { throw new NotSupportedException(); } //build pass, then copy the result dll back MoveFileOrReplaceIfExists(finalProductName, Path.GetFileName(finalProductName)); }