From e289dd47bf538e6c43a3254467c80befca6f0f1c Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 20 May 2016 02:40:53 +0300 Subject: [PATCH] Extended the class for modules with include and library dirs, and defines. Signed-off-by: Dimitar Dobrev --- examples/SDL/SDL.cs | 2 +- src/CppParser/Bindings/ParserGen.cs | 4 +-- src/CppParser/Bootstrap/Bootstrap.cs | 12 +++---- src/Generator.Tests/ASTTestFixture.cs | 4 ++- src/Generator.Tests/GeneratorTest.cs | 2 +- .../ReadNativeDependenciesTest.cs | 35 +++++++++---------- src/Generator/Driver.cs | 13 +++++++ src/Generator/Module.cs | 8 +++++ 8 files changed, 51 insertions(+), 29 deletions(-) diff --git a/examples/SDL/SDL.cs b/examples/SDL/SDL.cs index d044577e..4b4968cc 100644 --- a/examples/SDL/SDL.cs +++ b/examples/SDL/SDL.cs @@ -13,7 +13,7 @@ namespace CppSharp options.LibraryName = "SDL"; options.Headers.Add("SDL.h"); var sdlPath = Path.Combine(GetExamplesDirectory("SDL"), "SDL-2.0/include"); - options.addIncludeDirs(sdlPath); + options.Module.IncludeDirs.Add(sdlPath); options.OutputDir = "SDL"; } diff --git a/src/CppParser/Bindings/ParserGen.cs b/src/CppParser/Bindings/ParserGen.cs index 766c1e0c..e31b2dba 100644 --- a/src/CppParser/Bindings/ParserGen.cs +++ b/src/CppParser/Bindings/ParserGen.cs @@ -71,8 +71,8 @@ namespace CppSharp SetupLinuxOptions(options); var basePath = Path.Combine(GetSourceDirectory("src"), "CppParser"); - options.addIncludeDirs(basePath); - options.addLibraryDirs("."); + options.Module.IncludeDirs.Add(basePath); + options.Module.LibraryDirs.Add("."); options.OutputDir = Path.Combine(GetSourceDirectory("src"), "CppParser", "Bindings", Kind.ToString()); diff --git a/src/CppParser/Bootstrap/Bootstrap.cs b/src/CppParser/Bootstrap/Bootstrap.cs index 4198d277..2deba5c8 100644 --- a/src/CppParser/Bootstrap/Bootstrap.cs +++ b/src/CppParser/Bootstrap/Bootstrap.cs @@ -42,16 +42,16 @@ namespace CppSharp options.MicrosoftMode = false; options.TargetTriple = "i686-apple-darwin12.4.0"; - options.addDefines ("__STDC_LIMIT_MACROS"); - options.addDefines ("__STDC_CONSTANT_MACROS"); + options.Module.Defines.Add("__STDC_LIMIT_MACROS"); + options.Module.Defines.Add("__STDC_CONSTANT_MACROS"); var llvmPath = Path.Combine (GetSourceDirectory ("deps"), "llvm"); var clangPath = Path.Combine(llvmPath, "tools", "clang"); - options.addIncludeDirs(Path.Combine(llvmPath, "include")); - options.addIncludeDirs(Path.Combine(llvmPath, "build", "include")); - options.addIncludeDirs (Path.Combine (llvmPath, "build", "tools", "clang", "include")); - options.addIncludeDirs(Path.Combine(clangPath, "include")); + options.Module.IncludeDirs.Add(Path.Combine(llvmPath, "include")); + options.Module.IncludeDirs.Add(Path.Combine(llvmPath, "build", "include")); + options.Module.IncludeDirs.Add(Path.Combine (llvmPath, "build", "tools", "clang", "include")); + options.Module.IncludeDirs.Add(Path.Combine(clangPath, "include")); } public void SetupPasses(Driver driver) diff --git a/src/Generator.Tests/ASTTestFixture.cs b/src/Generator.Tests/ASTTestFixture.cs index 43ea5862..da810401 100644 --- a/src/Generator.Tests/ASTTestFixture.cs +++ b/src/Generator.Tests/ASTTestFixture.cs @@ -15,11 +15,13 @@ namespace CppSharp.Generator.Tests Options = new DriverOptions(); var testsPath = GeneratorTest.GetTestsDirectory("Native"); - Options.addIncludeDirs(testsPath); + Options.Module.IncludeDirs.Add(testsPath); Options.Headers.AddRange(files); Driver = new Driver(Options, new TextDiagnosticPrinter()); + foreach (var includeDir in Options.Module.IncludeDirs) + Options.addIncludeDirs(includeDir); Driver.SetupIncludes(); Driver.BuildParseOptions(); if (!Driver.ParseCode()) diff --git a/src/Generator.Tests/GeneratorTest.cs b/src/Generator.Tests/GeneratorTest.cs index 62f4e499..5509fede 100644 --- a/src/Generator.Tests/GeneratorTest.cs +++ b/src/Generator.Tests/GeneratorTest.cs @@ -46,7 +46,7 @@ namespace CppSharp.Utils options.TargetTriple = Environment.Is64BitProcess ? "x86_64-apple-darwin" : "i686-apple-darwin"; var path = Path.GetFullPath(GetTestsDirectory(name)); - options.addIncludeDirs(path); + options.Module.IncludeDirs.Add(path); // Remove this hardcoded path once we update our LLVM binary packages to bundle // the built-in Clang includes. diff --git a/src/Generator.Tests/ReadNativeDependenciesTest.cs b/src/Generator.Tests/ReadNativeDependenciesTest.cs index 9ea51908..84629eef 100644 --- a/src/Generator.Tests/ReadNativeDependenciesTest.cs +++ b/src/Generator.Tests/ReadNativeDependenciesTest.cs @@ -1,4 +1,5 @@ -using CppSharp.Utils; +using System.Collections.Generic; +using CppSharp.Utils; using NUnit.Framework; namespace CppSharp.Generator.Tests @@ -9,12 +10,7 @@ namespace CppSharp.Generator.Tests [Test] public void TestReadDependenciesWindows() { - var driverOptions = new DriverOptions(); - driverOptions.addLibraryDirs(GeneratorTest.GetTestsDirectory("Native")); - driverOptions.Libraries.Add("ls-windows"); - var driver = new Driver(driverOptions, new TextDiagnosticPrinter()); - Assert.IsTrue(driver.ParseLibraries()); - var dependencies = driver.Symbols.Libraries[0].Dependencies; + var dependencies = GetDependencies("ls-windows"); Assert.AreEqual("msys-intl-8.dll", dependencies[0]); Assert.AreEqual("msys-2.0.dll", dependencies[1]); Assert.AreEqual("KERNEL32.dll", dependencies[2]); @@ -23,12 +19,7 @@ namespace CppSharp.Generator.Tests [Test] public void TestReadDependenciesLinux() { - var driverOptions = new DriverOptions(); - driverOptions.addLibraryDirs(GeneratorTest.GetTestsDirectory("Native")); - driverOptions.Libraries.Add("ls-linux"); - var driver = new Driver(driverOptions, new TextDiagnosticPrinter()); - Assert.IsTrue(driver.ParseLibraries()); - var dependencies = driver.Symbols.Libraries[0].Dependencies; + var dependencies = GetDependencies("ls-linux"); Assert.AreEqual("libselinux.so.1", dependencies[0]); Assert.AreEqual("librt.so.1", dependencies[1]); Assert.AreEqual("libacl.so.1", dependencies[2]); @@ -37,16 +28,24 @@ namespace CppSharp.Generator.Tests [Test] public void TestReadDependenciesOSX() + { + var dependencies = GetDependencies("ls-osx"); + Assert.AreEqual("libutil.dylib", dependencies[0]); + Assert.AreEqual("libncurses.5.4.dylib", dependencies[1]); + Assert.AreEqual("libSystem.B.dylib", dependencies[2]); + } + + private static IList GetDependencies(string library) { var driverOptions = new DriverOptions(); - driverOptions.addLibraryDirs(GeneratorTest.GetTestsDirectory("Native")); - driverOptions.Libraries.Add("ls-osx"); + driverOptions.Module.LibraryDirs.Add(GeneratorTest.GetTestsDirectory("Native")); + driverOptions.Libraries.Add(library); var driver = new Driver(driverOptions, new TextDiagnosticPrinter()); + foreach (var libraryDir in driverOptions.Module.LibraryDirs) + driverOptions.addLibraryDirs(libraryDir); Assert.IsTrue(driver.ParseLibraries()); var dependencies = driver.Symbols.Libraries[0].Dependencies; - Assert.AreEqual("libutil.dylib", dependencies[0]); - Assert.AreEqual("libncurses.5.4.dylib", dependencies[1]); - Assert.AreEqual("libSystem.B.dylib", dependencies[2]); + return dependencies; } } } diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 2fb83d13..5ad4bea2 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -458,6 +458,19 @@ namespace CppSharp var driver = new Driver(options, Log); library.Setup(driver); + + foreach (var includeDir in options.Module.IncludeDirs) + options.addIncludeDirs(includeDir); + + foreach (var libraryDir in options.Module.LibraryDirs) + options.addLibraryDirs(libraryDir); + + foreach (var define in options.Module.Defines) + options.addDefines(define); + + foreach (var undefine in options.Module.Undefines) + options.addUndefines(undefine); + driver.Setup(); if(driver.Options.Verbose) diff --git a/src/Generator/Module.cs b/src/Generator/Module.cs index dd766117..8b345c5c 100644 --- a/src/Generator/Module.cs +++ b/src/Generator/Module.cs @@ -6,12 +6,20 @@ namespace CppSharp { public Module() { + IncludeDirs = new List(); Headers = new List(); + LibraryDirs = new List(); Libraries = new List(); + Defines = new List(); + Undefines = new List(); } + public List IncludeDirs { get; private set; } public List Headers { get; private set; } + public List LibraryDirs { get; set; } public List Libraries { get; private set; } + public List Defines { get; set; } + public List Undefines { get; set; } public string OutputNamespace { get; set; } public string SharedLibraryName