示例#1
0
        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);
        }
示例#2
0
        public virtual string GenerateFilter(ProjectBase Project, string RootPath)
        {
            CPPProject project = (CPPProject)Project;

            XmlDocument document = new XmlDocument();

            XmlElement projectElement = document.CreateElement("Project");

            {
                document.AppendChild(projectElement);

                projectElement.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
                projectElement.SetAttribute("ToolsVersion", "4.0");

                XmlElement itemGroup = CreateElement("ItemGroup", projectElement);
                {
                    List <string> files = new List <string>();
                    files.AddRange(project.IncludeFiles);
                    files.AddRange(project.CompileFiles);
                    files.AddRange(project.ExtraFiles);

                    List <string> filtersName = new List <string>();

                    foreach (string file in files)
                    {
                        string filterName = GetFilterName(file, RootPath);

                        string[] parts = filterName.Split(EnvironmentHelper.PathSeparator);

                        string filter = string.Empty;
                        for (int i = 0; i < parts.Length; ++i)
                        {
                            if (i != 0)
                            {
                                filter += EnvironmentHelper.PathSeparator;
                            }

                            filter += parts[i];

                            if (filtersName.Contains(filter))
                            {
                                continue;
                            }

                            filtersName.Add(filter);
                        }
                    }

                    foreach (string filterName in filtersName)
                    {
                        XmlElement filter = CreateElement("Filter", itemGroup);
                        {
                            filter.SetAttribute("Include", filterName);

                            XmlElement identifier = CreateElement("UniqueIdentifier", filter);
                            identifier.InnerText = "{" + Guid.NewGuid() + "}";
                        }
                    }
                }

                XmlElement includeFiles = CreateElement("ItemGroup", projectElement);
                AddStringListToEllementAsAttributeAndFilter(includeFiles, "ClInclude", "Include", project.IncludeFiles, RootPath);

                XmlElement compileFiles = CreateElement("ItemGroup", projectElement);
                AddStringListToEllementAsAttributeAndFilter(includeFiles, "ClCompile", "Include", project.CompileFiles, RootPath);

                XmlElement noneFiles = CreateElement("ItemGroup", projectElement);
                AddStringListToEllementAsAttributeAndFilter(noneFiles, "None", "Include", project.ExtraFiles, RootPath);
            }

            return(projectElement.OwnerDocument.OuterXml);
        }
示例#3
0
        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);
        }
        public static bool Create()
        {
            RuleLibraryBuilder rulesBuilder = new RuleLibraryBuilder(EnvironmentHelper.ProcessDirectory);

            if (!rulesBuilder.Build())
            {
                return(false);
            }

            CPPProject projectFile = new CPPProject();

            foreach (ProjectBase.ProfileBase.BuildConfigurations configuration in BuildConfigurations)
            {
                foreach (ProjectBase.ProfileBase.PlatformTypes platform in PlatformTypes)
                {
                    foreach (BuildRules buildRule in rulesBuilder.Rules)
                    {
                        foreach (BuildRules.RuleBase rule in buildRule.Rules)
                        {
                            if (rule.LibraryUseType != BuildRules.LibraryUseTypes.Executable)
                            {
                                continue;
                            }

                            CPPProject.Profile profile = (CPPProject.Profile)projectFile.CreateProfile();

                            profile.Name = buildRule.ModuleName;
                            profile.BuildConfiguration = configuration;
                            profile.PlatformType       = platform;
                            profile.OutputType         = ProjectBase.ProfileBase.OutputTypes.Makefile;
                            profile.OutputPath         = EnvironmentHelper.FinalOutputDirectory + rule.TargetName + EnvironmentHelper.ExecutableExtentions;
                            profile.IntermediatePath   = EnvironmentHelper.IntermediateDirectory;

                            profile.NMakeBuildCommandLine   = string.Format("\"$(SolutionDir)Binaries/Frontend.exe\" -Action BuildEngine -Architecture {0} -Configuration {1}", platform, configuration);
                            profile.NMakeReBuildCommandLine = string.Format("\"$(SolutionDir)Binaries/Frontend.exe\" -Action RebuildEngine -Architecture {0} -Configuration {1}", platform, configuration);
                            profile.NMakeCleanCommandLine   = string.Format("\"$(SolutionDir)Binaries/Frontend.exe\" -Action CleanEngine -Architecture {0} -Configuration {1}", platform, configuration);

                            //profile.AddIncludeDirectories("$(ProjectDir)");

                            foreach (BuildRules buildRule1 in rulesBuilder.Rules)
                            {
                                foreach (BuildRules.RuleBase rule1 in buildRule1.Rules)
                                {
                                    profile.AddIncludeDirectories(FileSystemUtilites.GetParentDirectory(buildRule1.Path));
                                    profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(buildRule1.Path));
                                    profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(profile.IntermediatePath + rule1.TargetName + EnvironmentHelper.PathSeparator + BuildSystemHelper.GeneratedPathName));

                                    if (rule1.IncludesPath != null)
                                    {
                                        foreach (string includePath in rule1.IncludesPath)
                                        {
                                            profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(buildRule1.Path + includePath));
                                        }
                                    }

                                    profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(rule1.TargetName, BuildSystemHelper.APIPreprocessorTypes.Empty));
                                    profile.AddPreprocessorDefinition(BuildSystemHelper.GetExternPreprocessor(rule1.TargetName, BuildSystemHelper.ExternPreprocessorTypes.Empty));

                                    if (rule1.PreprocessorDefinitions != null)
                                    {
                                        foreach (string pd in rule1.PreprocessorDefinitions)
                                        {
                                            profile.AddPreprocessorDefinition(pd);
                                        }
                                    }
                                }
                            }

                            profile.AddPreprocessorDefinition(BuildSystemHelper.GetConfigurationModePreprocessor(configuration));
                            profile.AddPreprocessorDefinition(BuildSystemHelper.GetPlatformPreprocessor(EnvironmentHelper.Platform));
                            profile.AddPreprocessorDefinition(BuildSystemHelper.GetPlatformTypesPreprocessor(platform));
                            profile.AddPreprocessorDefinition(BuildSystemHelper.GetModuleNamePreprocessor(""));
                        }
                    }
                }
            }

            string[] files = FileSystemUtilites.GetAllFiles(WorkingDirectory, EnvironmentHelper.CSharpFileExtensions);

            foreach (string file in files)
            {
                projectFile.AddExtraFile(file);
            }

            files = FileSystemUtilites.GetAllFiles(WorkingDirectory, EnvironmentHelper.HeaderFileExtensions);
            foreach (string file in files)
            {
                projectFile.AddIncludeFile(file);
            }

            files = FileSystemUtilites.GetAllFiles(WorkingDirectory, EnvironmentHelper.CompileFileExtensions);
            foreach (string file in files)
            {
                projectFile.AddCompileFile(file);
            }

            MicrosoftVCProjectGenerator generator = new MicrosoftVCProjectGenerator();

            generator.ToolsVersion = MSBuildProcess.Info.ToolsVersion;

            File.WriteAllText(ProjectFilePath, generator.Generate(projectFile, true));
            File.WriteAllText(ProjectFilePath + ".filters", generator.GenerateFilter(projectFile, WorkingDirectory));

            return(true);
        }