Beispiel #1
0
        private IEnumerable <String> GenerateLines(String CMakeListsPath)
        {
            yield return(@"cmake_minimum_required(VERSION 3.0.2)");

            yield return($@"project({SolutionName})");

            foreach (var p in ProjectReferences)
            {
                yield return(@"add_subdirectory(" + FileNameHandling.GetRelativePath(p.FilePath, OutputDirectory).Replace('\\', '/') + ")");
            }
            yield return("");
        }
Beispiel #2
0
        public void Execute()
        {
            var Projects = new List <KeyValuePair <ProjectReference, List <ProjectReference> > >();

            foreach (var ModulePath in Directory.EnumerateDirectories(Path.Combine(SourceDirectory, "modules"), "*", SearchOption.TopDirectoryOnly))
            {
                var ModuleName = Path.GetFileName(ModulePath);
                Projects.Add(GenerateModuleProject(ModuleName, ModulePath));
                if (!((TargetOperationSystem == OperatingSystemType.Android) || (TargetOperationSystem == OperatingSystemType.iOS)))
                {
                    foreach (var TestFile in GetFilesInDirectory(Path.Combine(ModulePath, "test")))
                    {
                        if (TestFile.Type != FileType.CppSource)
                        {
                            continue;
                        }
                        var TestName = ModuleName + "_" + Path.GetFileNameWithoutExtension(Regex.Replace(FileNameHandling.GetRelativePath(TestFile.Path, ModulePath), @"[\\/]", "_"));
                        Projects.Add(GenerateTestProject(ModuleName, ModulePath, TestName, TestFile));
                    }
                }
            }
            foreach (var SamplePath in Directory.EnumerateDirectories(Path.Combine(SourceDirectory, "samples"), "*", SearchOption.TopDirectoryOnly))
            {
                var SampleName = Path.GetFileName(SamplePath);
                var Extension  = Path.GetExtension(SampleName).TrimStart('.');
                if (Extension.Equals("android", StringComparison.OrdinalIgnoreCase))
                {
                    if (TargetOperationSystem == OperatingSystemType.Android)
                    {
                        //TODO
                    }
                }
                else if (Extension.Equals("ios", StringComparison.OrdinalIgnoreCase))
                {
                    if (TargetOperationSystem == OperatingSystemType.iOS)
                    {
                        Projects.Add(GenerateSampleProject(SampleName, SamplePath));
                    }
                }
                else
                {
                    Projects.Add(GenerateSampleProject(SampleName, SamplePath));
                }
            }
            if (Toolchain == ToolchainType.Windows_VisualC)
            {
                var SlnTemplateText = Resource.GetResourceText(@"Templates\vc15\Default.sln");
                var g = new SlnGenerator(SolutionName, GetIdForProject(SolutionName + ".solution"), Projects.Select(p => p.Key).ToList(), BuildDirectory, SlnTemplateText);
                g.Generate(EnableRebuild);
            }
            else if (Toolchain == ToolchainType.Mac_XCode)
            {
                var PbxprojTemplateText = Resource.GetResourceText(@"Templates\xcode9\Default.xcodeproj\project.pbxproj");
                var g = new PbxprojSolutionGenerator(SolutionName, Projects.Select(p => p.Key).ToList(), BuildDirectory, PbxprojTemplateText);
                g.Generate(EnableRebuild);
            }
            else if (Toolchain == ToolchainType.CMake)
            {
                var ProjectDict         = Projects.ToDictionary(p => p.Key.Name, p => p.Key);
                var ProjectDependencies = Projects.ToDictionary(p => ProjectDict[p.Key.Name], p => p.Value.Select(n => ProjectDict[n.Name]).ToList());
                var SortedProjects      = Projects.Select(p => p.Key).PartialOrderBy(p => ProjectDependencies.ContainsKey(p) ? ProjectDependencies[p] : null).ToList();
                var g = new CMakeSolutionGenerator(SolutionName, SortedProjects, BuildDirectory);
                g.Generate(EnableRebuild);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
        private static bool AddProject(Dictionary <String, Value> Objects, String GroupOrFileKey, LinkedList <String> Stack, LinkedList <String> RelativePathStack, ProjectReference Project, String BaseDirPath, Dictionary <String, String> RelativePathToFileObjectKey, bool Top = true)
        {
            var GroupOrFile = Objects[GroupOrFileKey].Dict;
            var Type        = GroupOrFile["isa"].String;

            if (Type != "PBXGroup")
            {
                return(false);
            }
            var Path  = GroupOrFile.ContainsKey("path") ? GroupOrFile["path"].String : GroupOrFile.ContainsKey("name") ? GroupOrFile["name"].String : "";
            var Parts = GetPathParts(Path).Where(p => p != "").ToArray();

            if (Parts.Length > RelativePathStack.Count)
            {
                return(false);
            }
            if (!Parts.SequenceEqual(RelativePathStack.Take(Parts.Length)))
            {
                return(false);
            }
            foreach (var Part in Parts)
            {
                Stack.AddLast(Part);
            }
            for (int k = 0; k < Parts.Length; k += 1)
            {
                RelativePathStack.RemoveFirst();
            }
            var Children = GroupOrFile["children"];
            var Added    = false;

            foreach (var Child in Children.Array)
            {
                Added = AddProject(Objects, Child.String, Stack, RelativePathStack, Project, BaseDirPath, RelativePathToFileObjectKey, false);
                if (Added)
                {
                    break;
                }
            }
            foreach (var Part in Parts.Reverse())
            {
                RelativePathStack.AddFirst(Part);
            }
            for (int k = 0; k < Parts.Length; k += 1)
            {
                Stack.RemoveLast();
            }
            if (Added)
            {
                return(true);
            }

            if (!Top && (Parts.Length == 0))
            {
                return(false);
            }

            String ChildHash;

            {
                var RelativePath = String.Join("/", Stack.Concat(RelativePathStack).Where(p => p != ""));
                var FileName     = RelativePathStack.Last.Value;
                var Hash         = GetHashOfPath(RelativePath);

                var FileObject = new Dictionary <string, Value>();
                FileObject.Add("fileEncoding", Value.CreateInteger(4));
                FileObject.Add("isa", Value.CreateString("PBXFileReference"));
                FileObject.Add("lastKnownFileType", Value.CreateString("wrapper.pb-project"));
                FileObject.Add("name", Value.CreateString(FileName));
                FileObject.Add("path", Value.CreateString(FileNameHandling.GetRelativePath(Project.FilePath, BaseDirPath).Replace('\\', '/')));
                FileObject.Add("sourceTree", Value.CreateString("<group>"));
                Objects.Add(Hash, Value.CreateDict(FileObject));
                RelativePathToFileObjectKey.Add(RelativePath, Hash);

                ChildHash = Hash;
            }

            for (int k = RelativePathStack.Count - 1; k >= Parts.Length + 1; k -= 1)
            {
                var RelativePath = String.Join("/", Stack.Concat(RelativePathStack.Take(k)).Where(p => p != ""));
                var DirName      = System.IO.Path.GetFileName(RelativePath);
                var Hash         = GetHashOfPath(RelativePath);

                var FileObject = new Dictionary <string, Value>();
                FileObject.Add("children", Value.CreateArray(new List <Value> {
                    Value.CreateString(ChildHash)
                }));
                FileObject.Add("isa", Value.CreateString("PBXGroup"));
                FileObject.Add("name", Value.CreateString(DirName));
                FileObject.Add("sourceTree", Value.CreateString("<group>"));
                Objects.Add(Hash, Value.CreateDict(FileObject));

                ChildHash = Hash;
            }

            Children.Array.Add(Value.CreateString(ChildHash));

            return(true);
        }
Beispiel #4
0
        public void Generate(bool EnableRebuild)
        {
            var s = new SlnFile();

            s.FullPath = Path.GetFullPath(Path.Combine(OutputDirectory, SolutionName + ".sln"));
            using (var sr = new StringReader(SlnTemplateText))
            {
                s.Read(sr);
            }

            s.Projects.Clear();
            s.ProjectConfigurationsSection.Clear();
            SlnSection NestedProjects = null;

            foreach (var Section in s.Sections.Where(Section => Section.Id == "NestedProjects"))
            {
                Section.Clear();
                NestedProjects = Section;
            }

            if (NestedProjects == null)
            {
                NestedProjects = new SlnSection
                {
                    Id = "NestedProjects"
                };
                s.Sections.Add(NestedProjects);
            }

            var Filters = new Dictionary <String, String>(StringComparer.OrdinalIgnoreCase);

            foreach (var Project in ProjectReferences)
            {
                var Dir = Project.VirtualDir.Replace('/', '\\');
                if (!Filters.ContainsKey(Dir))
                {
                    var CurrentDir = Dir;
                    while ((CurrentDir != "") && !Filters.ContainsKey(CurrentDir))
                    {
                        var g = Guid.ParseExact(Hash.GetHashForPath(CurrentDir, 32), "N").ToString().ToUpper();
                        Filters.Add(CurrentDir, g);
                        CurrentDir = Path.GetDirectoryName(CurrentDir);
                        if (CurrentDir != "")
                        {
                            var gUpper = Guid.ParseExact(Hash.GetHashForPath(CurrentDir, 32), "N").ToString().ToUpper();
                            NestedProjects.Properties.SetValue("{" + g + "}", "{" + gUpper + "}");
                        }
                    }
                }

                s.Projects.Add(new SlnProject
                {
                    TypeGuid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}",
                    Name     = Project.Name,
                    FilePath = FileNameHandling.GetRelativePath(Project.FilePath, OutputDirectory),
                    Id       = "{" + Project.Id + "}"
                });

                var conf = new SlnPropertySet("{" + Project.Id + "}");
                foreach (var c in s.SolutionConfigurationsSection)
                {
                    var Value = c.Value.Replace("|x86", "|Win32");
                    conf.SetValue(c.Key + ".ActiveCfg", Value);
                    conf.SetValue(c.Key + ".Build.0", Value);
                }
                s.ProjectConfigurationsSection.Add(conf);

                NestedProjects.Properties.SetValue("{" + Project.Id + "}", "{" + Filters[Dir] + "}");
            }

            foreach (var f in Filters)
            {
                s.Projects.Add(new SlnProject
                {
                    TypeGuid = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}",
                    Name     = Path.GetFileName(f.Key),
                    FilePath = Path.GetFileName(f.Key),
                    Id       = "{" + f.Value + "}"
                });
            }

            foreach (var Section in s.Sections.Where(Section => Section.Id == "ExtensibilityGlobals"))
            {
                Section.Properties.SetValue("SolutionGuid", "{" + SolutionId.ToUpper() + "}");
            }

            String Text;

            using (var sw = new StringWriter())
            {
                s.Write(sw);
                Text = sw.ToString();
            }
            TextFile.WriteToFile(s.FullPath, Text, Encoding.UTF8, !EnableRebuild);
        }