private static void AddDependency(CPPProject.Profile Profile, string Dependency) { SourceBuilder builder = BuildSystem.GetSourceBuilder(Dependency); if (builder == null) { return; } Profile.AddIncludeDirectories(FileSystemUtilites.GetParentDirectory(builder.sourcePathRoot)); Profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(builder.sourcePathRoot)); if (builder.SelectedRule.GenerateReflection) { Profile.AddIncludeDirectories(builder.generatedFilesPath); AddDependency(Profile, BuildSystemHelper.ReflectionModuleName); } if (builder.SelectedRule.IncludesPath != null) { foreach (string includePath in builder.SelectedRule.IncludesPath) { Profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(builder.sourcePathRoot + includePath)); } } if (builder.SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.UseOnly) { string[] temp = builder.SelectedRule.LibrariesPath; if (temp != null) { foreach (string file in temp) { Profile.AddIncludeLibraries(builder.sourcePathRoot + FileSystemUtilites.PathSeperatorCorrection(file)); } } } //else //{ // profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(builder.SelectedRule.TargetName, BuildSystemHelper.APIPreprocessorValues.Import)); // string[] libFiles = FileSystemUtilites.GetAllFiles(builder.BinariesPath, "*" + EnvironmentHelper.StaticLibraryExtentions); // if (libFiles != null) // foreach (string libFile in libFiles) // profile.AddIncludeLibraries(libFile); //} AddAllInclusionsFromDependencies(Profile, builder); }
private static void AddAllInclusionsFromDependencies(CPPProject.Profile Profile, SourceBuilder Builder) { if (Builder == null) { return; } if (Builder.SelectedRule.LibraryUseType != BuildRules.LibraryUseTypes.UseOnly) { Profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(Builder.BuildRule.ModuleName, (Builder.SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.DynamicLibrary ? BuildSystemHelper.APIPreprocessorTypes.Import : BuildSystemHelper.APIPreprocessorTypes.Empty))); Profile.AddPreprocessorDefinition(BuildSystemHelper.GetExternPreprocessor(Builder.BuildRule.ModuleName, BuildSystemHelper.ExternPreprocessorTypes.Empty)); string[] libFiles = FileSystemUtilites.GetAllFiles(Builder.BinariesPath, "*" + EnvironmentHelper.StaticLibraryExtentions); if (libFiles != null) { foreach (string libFile in libFiles) { Profile.AddIncludeLibraries(libFile); } } } if (Builder.SelectedRule.DependencyModulesName == null) { return; } foreach (string dep in Builder.SelectedRule.DependencyModulesName) { SourceBuilder builder = BuildSystem.GetSourceBuilder(dep); AddAllInclusionsFromDependencies(Profile, builder); } }
private void GenerateAndBuildProjectFile(bool ForceToRebuild) { LogCurrentInfo(); if (!ForceToRebuild && !MustCompile()) { state = States.AlreadyUpdated; return; } CPPProject cppProj = new CPPProject(); CPPProject.Profile profile = (CPPProject.Profile)cppProj.CreateProfile(); profile.AssemblyName = SelectedRule.TargetName; profile.OutputType = BuildSystemHelper.LibraryUseTypesToOutputType(SelectedRule.LibraryUseType); profile.OutputPath = BinariesPath; profile.Optimization = CPPProject.Profile.Optimizations.Disabled; profile.MinimalRebuild = true; profile.PlatformType = BuildSystem.PlatformType; profile.BuildConfiguration = BuildSystem.BuildConfiguration; if (profile.BuildConfiguration == ProjectBase.ProfileBase.BuildConfigurations.Debug) { profile.GenerateDebugInformation = true; //if (SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.Executable) // profile.RuntimeLibrary = CPPProject.Profile.RuntimeLibraries.MultiThreadedDebug; //else profile.RuntimeLibrary = CPPProject.Profile.RuntimeLibraries.MultiThreadedDebugDLL; } else if (profile.BuildConfiguration == ProjectBase.ProfileBase.BuildConfigurations.Release) { profile.GenerateDebugInformation = false; //if (SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.Executable) // profile.RuntimeLibrary = CPPProject.Profile.RuntimeLibraries.MultiThreaded; //else profile.RuntimeLibrary = CPPProject.Profile.RuntimeLibraries.MultiThreadedDLL; } profile.AddIncludeDirectories(EnvironmentHelper.ProcessDirectory); profile.AddIncludeDirectories(sourcePathRoot); profile.AddIncludeDirectories(generatedFilesPath); if (SelectedRule.DependencyModulesName != null) { foreach (string dep in SelectedRule.DependencyModulesName) { AddDependency(profile, dep); } } if (SelectedRule.GenerateReflection) { AddDependency(profile, BuildSystemHelper.ReflectionModuleName); } profile.AddPreprocessorDefinition(BuildSystemHelper.GetModuleNamePreprocessor(BuildRule.ModuleName)); profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(BuildRule.ModuleName, BuildSystemHelper.APIPreprocessorTypes.Export)); profile.AddPreprocessorDefinition(BuildSystemHelper.GetExternPreprocessor(BuildRule.ModuleName, BuildSystemHelper.ExternPreprocessorTypes.Fill)); if (SelectedRule.PreprocessorDefinitions != null) { foreach (string def in SelectedRule.PreprocessorDefinitions) { profile.AddPreprocessorDefinition(def); } } profile.AddPreprocessorDefinition(BuildSystemHelper.GetConfigurationModePreprocessor(BuildSystem.BuildConfiguration)); profile.AddPreprocessorDefinition(BuildSystemHelper.GetPlatformPreprocessor(EnvironmentHelper.Platform)); profile.AddPreprocessorDefinition(BuildSystemHelper.GetPlatformTypesPreprocessor(BuildSystem.PlatformType)); if (SelectedRule.DependencyStaticLibraries != null) { foreach (string lib in SelectedRule.DependencyStaticLibraries) { profile.AddIncludeLibraries(lib); } } string[] files = FileSystemUtilites.GetAllFiles(sourcePathRoot, EnvironmentHelper.HeaderFileExtensions); foreach (string file in files) { cppProj.AddIncludeFile(file); string outputBasePath = generatedFilesPath + Path.GetFileNameWithoutExtension(file); if (SelectedRule.GenerateReflection) { string outputBaseFileName = outputBasePath + ".Reflection"; if (ParseForReflection(file, outputBaseFileName)) { cppProj.AddIncludeFile(outputBaseFileName + ".h"); cppProj.AddCompileFile(outputBaseFileName + ".cpp"); } } if (SelectedRule.GenerateWrapper) { string outputBaseFileName = outputBasePath + ".Wrapper"; if (ParseForWrapper(file, outputBaseFileName)) { cppProj.AddIncludeFile(outputBaseFileName + ".h"); cppProj.AddCompileFile(outputBaseFileName + ".cpp"); wrapperCSFiles.Add(outputBaseFileName + ".cs"); } } } if (SelectedRule.IncludeModulesName != null) { foreach (string moduleName in SelectedRule.IncludeModulesName) { SourceBuilder builder = BuildSystem.GetSourceBuilder(moduleName); if (builder == null) { continue; } profile.AddIncludeDirectories(builder.sourcePathRoot); profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(builder.BuildRule.ModuleName, BuildSystemHelper.APIPreprocessorTypes.Empty)); profile.AddPreprocessorDefinition(BuildSystemHelper.GetExternPreprocessor(builder.BuildRule.ModuleName, BuildSystemHelper.ExternPreprocessorTypes.Empty)); } } if (SelectedRule.AdditionalIncludeDirectory != null) { foreach (string dir in SelectedRule.AdditionalIncludeDirectory) { string dirInfo = FileSystemUtilites.PathSeperatorCorrection(dir); if (dirInfo.StartsWith("" + EnvironmentHelper.PathSeparator)) { dirInfo = dirInfo.Substring(1); } profile.AddIncludeLibraryDirectories(sourcePathRoot + dirInfo); } } files = FileSystemUtilites.GetAllFiles(sourcePathRoot, EnvironmentHelper.CompileFileExtensions); foreach (string file in files) { cppProj.AddCompileFile(file); } if (SelectedRule.AdditionalCompileFile != null) { foreach (string file in SelectedRule.AdditionalCompileFile) { cppProj.AddCompileFile(EnvironmentHelper.ProcessDirectory + file); } } profile.IntermediatePath = intermediateModulePath; BuildProjectFile(profile); }
public override string Generate(ProjectBase Project, bool WithBeutyConfigurationName) { CPPProject project = (CPPProject)Project; XmlElement projectElement = CreateProjectElement(); { if (ToolsVersion >= ToolsVersions.v14_1) { XmlElement winSDKVersion = CreateElement("WindowsTargetPlatformVersion", CreateElement("PropertyGroup", projectElement)); winSDKVersion.InnerText = InstalledWindowsKitVersion; } projectElement.SetAttribute("ToolsVersion", ToolsVersion.ToString().Substring(1).Replace('_', '.')); XmlElement itemGroup = CreateElement("ItemGroup", projectElement); { for (int i = 0; i < project.Profiles.Length; ++i) { XmlElement projectConfiguration = CreateElement("ProjectConfiguration", itemGroup); { CPPProject.Profile profile = (CPPProject.Profile)project.Profiles[i]; projectConfiguration.SetAttribute("Include", GetConfigurationAndPlatform(profile, WithBeutyConfigurationName)); XmlElement configuration = CreateElement("Configuration", projectConfiguration); configuration.InnerText = GetConfiguration(profile, WithBeutyConfigurationName); XmlElement platform = CreateElement("Platform", projectConfiguration); platform.InnerText = GetPlatformType(profile); } } } XmlElement includeFiles = CreateElement("ItemGroup", projectElement); AddStringListToEllementAsAttribute(includeFiles, "ClInclude", "Include", project.IncludeFiles); XmlElement compileFiles = CreateElement("ItemGroup", projectElement); AddStringListToEllementAsAttribute(includeFiles, "ClCompile", "Include", project.CompileFiles); XmlElement noneFiles = CreateElement("ItemGroup", projectElement); AddStringListToEllementAsAttribute(noneFiles, "None", "Include", project.ExtraFiles); XmlElement import = CreateElement("Import", projectElement); import.SetAttribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"); for (int i = 0; i < project.Profiles.Length; ++i) { CPPProject.Profile profile = (CPPProject.Profile)project.Profiles[i]; XmlElement popertyGroup = CreateElement("PropertyGroup", projectElement); { popertyGroup.SetAttribute("Condition", "'$(Configuration)|$(Platform)'=='" + GetConfigurationAndPlatform(profile, WithBeutyConfigurationName) + "'"); XmlElement configurationType = CreateElement("ConfigurationType", popertyGroup); configurationType.InnerText = GetOutputType(profile); XmlElement platformToolset = CreateElement("PlatformToolset", popertyGroup); platformToolset.InnerText = ToolsVersion.ToString().Replace("_", ""); } popertyGroup = CreateElement("PropertyGroup", projectElement); { popertyGroup.SetAttribute("Condition", "'$(Configuration)|$(Platform)'=='" + GetConfigurationAndPlatform(profile, WithBeutyConfigurationName) + "'"); if (profile.OutputType == ProjectBase.ProfileBase.OutputTypes.Makefile) { XmlElement nmakeBuildCommandLine = CreateElement("NMakeBuildCommandLine", popertyGroup); nmakeBuildCommandLine.InnerText = profile.NMakeBuildCommandLine; XmlElement nmakeRebuildCommandLine = CreateElement("NMakeReBuildCommandLine", popertyGroup); nmakeRebuildCommandLine.InnerText = profile.NMakeReBuildCommandLine; XmlElement nmakeCleanCommandLine = CreateElement("NMakeCleanCommandLine", popertyGroup); nmakeCleanCommandLine.InnerText = profile.NMakeCleanCommandLine; XmlElement nmakeIncludeSearchPath = CreateElement("NMakeIncludeSearchPath", popertyGroup); nmakeIncludeSearchPath.InnerText = GetFlattenStringList(profile.IncludeDirectories); XmlElement nmakeOutput = CreateElement("NMakeOutput", popertyGroup); nmakeOutput.InnerText = profile.OutputPath; XmlElement nmakePreprocessorDefinitions = CreateElement("NMakePreprocessorDefinitions", popertyGroup); nmakePreprocessorDefinitions.InnerText = GetFlattenStringList(profile.PreprocessorDefinitions); } else { XmlElement outDir = CreateElement("OutDir", popertyGroup); outDir.InnerText = profile.OutputPath; XmlElement targetName = CreateElement("TargetName", popertyGroup); targetName.InnerText = profile.AssemblyName; } XmlElement intDir = CreateElement("IntDir", popertyGroup); intDir.InnerText = profile.IntermediatePath; } } import = CreateElement("Import", projectElement); import.SetAttribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props"); for (int i = 0; i < project.Profiles.Length; ++i) { CPPProject.Profile profile = (CPPProject.Profile)project.Profiles[i]; if (profile.OutputType == ProjectBase.ProfileBase.OutputTypes.Makefile) { continue; } XmlElement itemDefinitionGroup = CreateElement("ItemDefinitionGroup", projectElement); { itemDefinitionGroup.SetAttribute("Condition", "'$(Configuration)|$(Platform)'=='" + GetConfigurationAndPlatform(profile, WithBeutyConfigurationName) + "'"); XmlElement clCompile = CreateElement("ClCompile", itemDefinitionGroup); { XmlElement runtimeLibrary = CreateElement("RuntimeLibrary", clCompile); runtimeLibrary.InnerText = profile.RuntimeLibrary.ToString(); XmlElement additionalIncludeDirectories = CreateElement("AdditionalIncludeDirectories", clCompile); if (Array.IndexOf(profile.IncludeDirectories, "%(AdditionalIncludeDirectories)") == -1) { profile.AddIncludeDirectories("%(AdditionalIncludeDirectories)"); } additionalIncludeDirectories.InnerText = GetFlattenStringList(profile.IncludeDirectories); additionalIncludeDirectories.InnerText += GetFlattenStringList(profile.IncludeLibraryDirectories); XmlElement preprocessorDefinitions = CreateElement("PreprocessorDefinitions", clCompile); if (Array.IndexOf(profile.PreprocessorDefinitions, "%(PreprocessorDefinitions)") == -1) { profile.AddPreprocessorDefinition("%(PreprocessorDefinitions)"); } preprocessorDefinitions.InnerText = GetFlattenStringList(profile.PreprocessorDefinitions); XmlElement optimization = CreateElement("Optimization", clCompile); optimization.InnerText = profile.Optimization.ToString(); XmlElement minimalRebuild = CreateElement("MinimalRebuild", clCompile); minimalRebuild.InnerText = profile.MinimalRebuild.ToString(); } XmlElement importTargets = CreateElement("Import", projectElement); importTargets.SetAttribute("Project", "$(VCTargetsPath)/Microsoft.Cpp.props"); XmlElement link = CreateElement("Link", itemDefinitionGroup); { XmlElement generateDebugInformation = CreateElement("GenerateDebugInformation", link); generateDebugInformation.InnerText = profile.GenerateDebugInformation.ToString(); XmlElement additionalLibraryDirectories = CreateElement("AdditionalLibraryDirectories", link); if (Array.IndexOf(profile.IncludeLibraryDirectories, "%(AdditionalLibraryDirectories)") == -1) { profile.AddIncludeLibraryDirectories("%(AdditionalLibraryDirectories)"); } additionalLibraryDirectories.InnerText = GetFlattenStringList(profile.AdditionalLibraryDirectories); XmlElement additionalLibraries = CreateElement("AdditionalDependencies", link); if (Array.IndexOf(profile.IncludeLibraries, "%(AdditionalDependencies)") == -1) { profile.AddIncludeLibraries("%(AdditionalDependencies)"); } additionalLibraries.InnerText = GetFlattenStringList(profile.IncludeLibraries); } } } import = CreateElement("Import", projectElement); import.SetAttribute("Project", "$(VCTargetsPath)/Microsoft.Cpp.targets"); } return(projectElement.OwnerDocument.OuterXml); }