From d02192ed6651af1bcaa8287b0f0e97f6e65330ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Matos?= Date: Tue, 1 Mar 2016 18:48:46 +0000 Subject: [PATCH] Improved SDL sample with clone scripts and directory scanning. --- examples/SDL/SDL.cs | 23 ++++++++++++++++++++++- examples/SDL/SDL.lua | 21 +++++++++++++++++++++ examples/SDL/premake4.lua | 3 +-- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 examples/SDL/SDL.lua diff --git a/examples/SDL/SDL.cs b/examples/SDL/SDL.cs index 1e1a59aa..d044577e 100644 --- a/examples/SDL/SDL.cs +++ b/examples/SDL/SDL.cs @@ -1,5 +1,7 @@ using CppSharp.AST; using CppSharp.Passes; +using System; +using System.IO; namespace CppSharp { @@ -10,7 +12,8 @@ namespace CppSharp var options = driver.Options; options.LibraryName = "SDL"; options.Headers.Add("SDL.h"); - options.addIncludeDirs("../../../examples/SDL/SDL-2.0/include"); + var sdlPath = Path.Combine(GetExamplesDirectory("SDL"), "SDL-2.0/include"); + options.addIncludeDirs(sdlPath); options.OutputDir = "SDL"; } @@ -64,6 +67,24 @@ namespace CppSharp ctx.SetNameOfEnumWithName("LOG_CATEGORY", "LogCategory"); } + public static string GetExamplesDirectory(string name) + { + var directory = Directory.GetParent(Directory.GetCurrentDirectory()); + + while (directory != null) + { + var path = Path.Combine(directory.FullName, "examples", name); + + if (Directory.Exists(path)) + return path; + + directory = directory.Parent; + } + + throw new Exception(string.Format( + "Examples directory for project '{0}' was not found", name)); + } + static class Program { public static void Main(string[] args) diff --git a/examples/SDL/SDL.lua b/examples/SDL/SDL.lua new file mode 100644 index 00000000..39f54f4a --- /dev/null +++ b/examples/SDL/SDL.lua @@ -0,0 +1,21 @@ +package.path = package.path .. "../build/?.lua;../../build/scripts/?.lua" +require "Helpers" +require "Utils" + +function clone_sdl() + local sdl = path.getabsolute(examplesdir .. "/SDL/SDL-2.0") + local repo = "https://github.com/spurious/SDL-mirror.git" + + if os.isdir(sdl) and not os.isdir(sdl .. "/.git") then + error("SDL directory is not a git repository.") + end + + if not os.isdir(sdl) then + git.clone(sdl, repo) + end +end + +if _ACTION == "clone_sdl" then + clone_sdl() + os.exit() +end diff --git a/examples/SDL/premake4.lua b/examples/SDL/premake4.lua index bd3985c9..610b103c 100644 --- a/examples/SDL/premake4.lua +++ b/examples/SDL/premake4.lua @@ -46,5 +46,4 @@ project "SDL.Tests" libdir .. "/SDL/SDL_video.cs", "*.lua" } - -end \ No newline at end of file +end