Exemple #1
0
        public override bool VisitLibrary(ASTContext library)
        {
            bool          result     = base.VisitLibrary(library);
            string        pro        = string.Format("{0}.pro", this.Driver.Options.InlinesLibraryName);
            string        path       = Path.Combine(this.Driver.Options.OutputDir, pro);
            StringBuilder proBuilder = new StringBuilder();

            proBuilder.Append("QMAKE_CXXFLAGS += -fkeep-inline-functions -std=c++0x\n");
            proBuilder.AppendFormat("TARGET = {0}\n", this.Driver.Options.InlinesLibraryName);
            proBuilder.Append("TEMPLATE = lib\n");
            proBuilder.AppendFormat("SOURCES += {0}\n", Path.ChangeExtension(pro, "cpp"));
            File.WriteAllText(path, proBuilder.ToString());
            string error;

            ProcessHelper.Run(this.qmake, string.Format("\"{0}\"", path), out error, this.Driver.Options.OutputDir);
            if (!string.IsNullOrEmpty(error))
            {
                Console.WriteLine(error);
                return(false);
            }
            ProcessHelper.Run(this.make, "-f Makefile.Release", out error, this.Driver.Options.OutputDir);
            if (!string.IsNullOrEmpty(error))
            {
                Console.WriteLine(error);
                return(false);
            }
            var parserOptions = new ParserOptions();

            parserOptions.addLibraryDirs(Path.Combine(this.Driver.Options.OutputDir, "release"));
            parserOptions.FileName = Path.GetFileName(string.Format("lib{0}.a", Path.GetFileNameWithoutExtension(pro)));
            var parserResult = ClangParser.ParseLibrary(parserOptions);

            if (parserResult.Kind == ParserResultKind.Success)
            {
                var nativeLibrary = CppSharp.ClangParser.ConvertLibrary(parserResult.Library);
                this.Driver.Symbols.Libraries.Add(nativeLibrary);
                this.Driver.Symbols.IndexSymbols();
            }
            return(result);
        }
        private static IList <string> GetDependencies(string library)
        {
            var parserOptions = new ParserOptions();

            parserOptions.addLibraryDirs(GeneratorTest.GetTestsDirectory("Native"));
            var driverOptions = new DriverOptions();

            driverOptions.Libraries.Add(library);
            var driver = new Driver(driverOptions, new TextDiagnosticPrinter())
            {
                ParserOptions = parserOptions
            };

            foreach (var module in driver.Options.Modules)
            {
                module.LibraryName = "Test";
            }
            driver.Setup();
            Assert.IsTrue(driver.ParseLibraries());
            var dependencies = driver.Context.Symbols.Libraries[0].Dependencies;

            return(dependencies);
        }
Exemple #3
0
        public void Setup(Driver driver)
        {
            string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (string.IsNullOrEmpty(this.make))
            {
                var parserOptions = new ParserOptions();
                parserOptions.addLibraryDirs(Path.GetDirectoryName(this.libraryFile));
                parserOptions.FileName = Path.GetFileName(this.libraryFile);
                var parserResult = ClangParser.ParseLibrary(parserOptions);
                if (parserResult.Kind == ParserResultKind.Success)
                {
                    var nativeLibrary = CppSharp.ClangParser.ConvertLibrary(parserResult.Library);
                    driver.Options.TargetTriple = nativeLibrary.ArchType == ArchType.x86 ? "i386-pc-windows" : "amd64-pc-windows";
                }
                driver.Options.addDefines("_XKEYCHECK_H");
                driver.Options.CodeFiles.Add(Path.Combine(dir, "_iobuf_VC++2013.cs"));
            }
            else
            {
                string error;
                string output = ProcessHelper.Run(Path.Combine(Path.GetDirectoryName(this.make), "gcc"), "-v", out error);
                if (string.IsNullOrEmpty(output))
                {
                    output = error;
                }
                string target          = Regex.Match(output, @"Target:\s*(?<target>[^\r\n]+)").Groups["target"].Value;
                string compilerVersion = Regex.Match(output, @"gcc\s+version\s+(?<version>\S+)").Groups["version"].Value;

                driver.Options.addDefines("_CRTIMP=");
                driver.Options.NoBuiltinIncludes = true;
                driver.Options.MicrosoftMode     = false;
                driver.Options.TargetTriple      = target;
                driver.Options.Abi = CppAbi.Itanium;

                string gccPath = Path.GetDirectoryName(Path.GetDirectoryName(this.make));
                driver.Options.addSystemIncludeDirs(Path.Combine(gccPath, "include", "c++", compilerVersion));
                driver.Options.addSystemIncludeDirs(Path.Combine(gccPath, "include", "c++", compilerVersion, target));
                driver.Options.addSystemIncludeDirs(Path.Combine(gccPath, target, "include"));
                driver.Options.addSystemIncludeDirs(Path.Combine(gccPath, target, "include", "c++"));
                driver.Options.addSystemIncludeDirs(Path.Combine(gccPath, target, "include", "c++", target));
                driver.Options.addSystemIncludeDirs(Path.Combine(gccPath, "lib", "gcc", target, compilerVersion, "include"));
                driver.Options.CodeFiles.Add(Path.Combine(dir, "_iobuf.cs"));
            }
            driver.Options.addDefines("HAVE_CONFIG_H");
            driver.Options.GeneratorKind       = GeneratorKind.CSharp;
            driver.Options.LibraryName         = "LibGDSharp";
            driver.Options.OutputNamespace     = "LibGD";
            driver.Options.Verbose             = true;
            driver.Options.IgnoreParseWarnings = true;
            driver.Options.CompileCode         = true;
            driver.Options.CheckSymbols        = true;
            driver.Options.GenerateDefaultValuesForArguments = true;
            driver.Options.MarshalCharAsManagedChar          = true;
            driver.Options.StripLibPrefix           = false;
            driver.Options.GenerateSingleCSharpFile = true;
            driver.Options.Headers.AddRange(Directory.EnumerateFiles(this.includeDir, "*.h"));
            driver.Options.addIncludeDirs(includeDir);
            driver.Options.addLibraryDirs(Path.GetDirectoryName(this.libraryFile));
            driver.Options.Libraries.Add(Path.GetFileName(this.libraryFile));
            driver.Options.CodeFiles.Add(Path.Combine(dir, "LibGDExtensions.cs"));
        }