Better way of including Gtk libs

This commit is contained in:
cra0zy 2019-11-07 21:32:32 +01:00
parent 5a179531bb
commit a32bcb35c7
35 changed files with 35 additions and 189 deletions

View file

@ -10,12 +10,15 @@
<Description>GtkSharp is a C# wrapper for the Gtk library.</Description>
<PackageTags>gtk;gtksharp;gtk-sharp;wrapper</PackageTags>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>..\..\..\BuildOutput\Debug</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\..\..\BuildOutput\Release</OutputPath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GLibSharp\GLibSharp.csproj">
<Name>GLibSharp</Name>
@ -36,173 +39,15 @@
<Name>PangoSharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\*.cs">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<None Remove="windows-x64\atk-1.dll" />
<None Remove="windows-x64\bz2.dll" />
<None Remove="windows-x64\cairo-gobject.dll" />
<None Remove="windows-x64\cairo.dll" />
<None Remove="windows-x64\epoxy-0.dll" />
<None Remove="windows-x64\expat.dll" />
<None Remove="windows-x64\fontconfig.dll" />
<None Remove="windows-x64\freetype.dll" />
<None Remove="windows-x64\gailutil-3.dll" />
<None Remove="windows-x64\gdk-3.dll" />
<None Remove="windows-x64\gdk_pixbuf-2.dll" />
<None Remove="windows-x64\gio-2.dll" />
<None Remove="windows-x64\glib-2.dll" />
<None Remove="windows-x64\gmodule-2.dll" />
<None Remove="windows-x64\gobject-2.dll" />
<None Remove="windows-x64\gthread-2.dll" />
<None Remove="windows-x64\gtk-3.dll" />
<None Remove="windows-x64\harfbuzz.dll" />
<None Remove="windows-x64\libcharset.dll" />
<None Remove="windows-x64\libiconv.dll" />
<None Remove="windows-x64\libintl.dll" />
<None Remove="windows-x64\libpng16.dll" />
<None Remove="windows-x64\pango-1.dll" />
<None Remove="windows-x64\pangocairo-1.dll" />
<None Remove="windows-x64\pangoft2-1.dll" />
<None Remove="windows-x64\pangowin32-1.dll" />
<None Remove="windows-x64\pcre.dll" />
<None Remove="windows-x64\pcre16.dll" />
<None Remove="windows-x64\pcre32.dll" />
<None Remove="windows-x64\pcrecpp.dll" />
<None Remove="windows-x64\pcreposix.dll" />
<None Remove="windows-x64\zlib1.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="windows-x64\atk-1.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\bz2.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\cairo-gobject.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\cairo.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\epoxy-0.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\expat.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\fontconfig.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\freetype.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\gailutil-3.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\gdk-3.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\gdk_pixbuf-2.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\gio-2.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\glib-2.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\gmodule-2.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\gobject-2.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\gthread-2.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\gtk-3.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\harfbuzz.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\libcharset.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\libiconv.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\libintl.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\libpng16.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pango-1.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pangocairo-1.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pangoft2-1.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pangowin32-1.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pcre.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pcre16.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pcre32.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pcrecpp.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\pcreposix.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="windows-x64\zlib1.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="GtkSharp.targets" PackagePath="build\GtkSharp.targets" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,16 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<GtkUrl Condition=" '$(GtkUrl)' == '' ">https://github.com/GtkSharp/Dependencies/raw/master/gtk-3.24.zip</GtkUrl>
<GtkDir Condition=" '$(GtkDir)' == '' ">$(LOCALAPPDATA)\Gtk\3.24</GtkDir>
</PropertyGroup>
<Target Name="InstallGtk" BeforeTargets="Build" Condition=" '$(SkipGtkInstall)' != 'True' and !Exists('$(GtkDir)/libgtk-3-0.dll') ">
<Message Importance="High" Text="Gtk has not been detected, downloading and installing it, set SkipGtkInstall to True to skip theese steps."/>
<Message Importance="High" Text="Ignore Gtk extract errors, bug msbuild/issues/3884"/>
<MakeDir Directories="$(GtkDir)"/>
<DownloadFile SourceUrl="$(GtkUrl)" DestinationFolder="$(GtkDir)" DestinationFileName="gtk.zip" />
<Unzip ContinueOnError="true" SourceFiles="$(GtkDir)/gtk.zip" DestinationFolder="$(GtkDir)" />
</Target>
</Project>

View file

@ -36,17 +36,25 @@ class GLibrary
return ret;
if (FuncLoader.IsWindows)
ret = LoadLibrary(_libraryDefinitions[library][0]);
{
ret = FuncLoader.LoadLibrary(_libraryDefinitions[library][0]);
if (ret == IntPtr.Zero)
{
SetDllDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Gtk", "3.24"));
ret = FuncLoader.LoadLibrary(_libraryDefinitions[library][0]);
}
}
else if (FuncLoader.IsOSX)
ret = LoadLibrary(_libraryDefinitions[library][2]);
ret = FuncLoader.LoadLibrary(_libraryDefinitions[library][2]);
else
ret = LoadLibrary(_libraryDefinitions[library][1]);
ret = FuncLoader.LoadLibrary(_libraryDefinitions[library][1]);
if (ret == IntPtr.Zero)
{
for (int i = 0; i < _libraryDefinitions[library].Length; i++)
{
ret = LoadLibrary(_libraryDefinitions[library][i]);
ret = FuncLoader.LoadLibrary(_libraryDefinitions[library][i]);
if (ret != IntPtr.Zero)
break;
@ -62,27 +70,4 @@ class GLibrary
_libraries[library] = ret;
return ret;
}
private static IntPtr LoadLibrary(string libname)
{
var ret = FuncLoader.LoadLibrary(libname);
if (ret != IntPtr.Zero)
return ret;
// Hacky solution to load libraries on Windows
if (FuncLoader.IsWindows)
{
var assemblyLocation = Path.GetDirectoryName(typeof(GLibrary).Assembly.Location);
var assemblyVersionDir = Path.GetDirectoryName(Path.GetDirectoryName(assemblyLocation));
var version = Path.GetFileName(assemblyVersionDir);
var gtkdir = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(assemblyVersionDir)), "gtksharp");
var nativeLibDir = Path.Combine(gtkdir, version, "runtimes", "win-x64", "native");
SetDllDirectory(nativeLibDir);
ret = FuncLoader.LoadLibrary(Path.Combine(nativeLibDir, libname));
}
return ret;
}
}