From 6fd6649bb58dcf0921807be6ec2afc3712b3d4b9 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sat, 9 Apr 2016 14:24:53 +0300 Subject: [PATCH] P/Invoked OS X frameworks instead of just libs when applicable. --- .../Generators/CSharp/CSharpTextTemplate.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 6b663836..51282c50 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2991,7 +2991,8 @@ namespace CppSharp.Generators.CSharp if (library != null) libName = Path.GetFileNameWithoutExtension(library.FileName); } - if (Options.StripLibPrefix && libName != null && libName.Length > 3 && libName.StartsWith("lib")) + if (Options.StripLibPrefix && libName != null && libName.Length > 3 && + libName.StartsWith("lib", StringComparison.Ordinal)) { libName = libName.Substring(3); } @@ -3001,6 +3002,20 @@ namespace CppSharp.Generators.CSharp if (Options.GenerateInternalImports) libName = "__Internal"; + if (Platform.IsMacOS) + { + var framework = libName + ".framework"; + for (uint i = 0; i < Driver.Options.LibraryDirsCount; i++) + { + var libDir = Driver.Options.getLibraryDirs(i); + if (Path.GetFileName(libDir) == framework && File.Exists(Path.Combine(libDir, libName))) + { + libName = string.Format("@executable_path/../Frameworks/{0}/{1}", framework, libName); + break; + } + } + } + Write("[DllImport(\"{0}\", ", libName); var callConv = function.CallingConvention.ToInteropCallConv();