From c2626726a5a46b1e89ad3f45c0044da01fd3dea7 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sat, 12 Sep 2020 13:07:34 -0600 Subject: [PATCH] Add static compilation for sdl_gpu and sdl_gfx --- .gitignore | 3 ++- src/sdl2/sdl2.nim | 4 ++- src/sdl2/sdl2_gfx.nim | 52 +++++++++++++++++++------------------- src/sdl2/sdl2_gpu.nim | 55 ++++++++++++++++++++++++++++++++--------- src/sdl2/sdl2_image.nim | 6 +++-- 5 files changed, 78 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 8baf078..e0d8776 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,8 @@ !*.* build +generated/ *.out *.exe -.DS_Store \ No newline at end of file +.DS_Store diff --git a/src/sdl2/sdl2.nim b/src/sdl2/sdl2.nim index 6d28356..1c916bb 100644 --- a/src/sdl2/sdl2.nim +++ b/src/sdl2/sdl2.nim @@ -26,8 +26,10 @@ else: const dlurl = "https://www.libsdl.org/release/SDL2-$1.tar.gz" when defined(windows): + const winBDir = buildDir.replace("C:\\", "/c/").replace("\\", "/") + const winIDir = includeDir.replace("C:\\", "/c/").replace("\\", "/") when defined(amd64): - const flags = &"--libdir={buildDir} --includedir={includeDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC\"" + const flags = &"--libdir={winBDir} --includedir={winIDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC\"" else: const flags = &"--libdir={buildDir} --includedir={includeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC\"" elif defined(macosx): diff --git a/src/sdl2/sdl2_gfx.nim b/src/sdl2/sdl2_gfx.nim index 241ec05..f37495e 100644 --- a/src/sdl2/sdl2_gfx.nim +++ b/src/sdl2/sdl2_gfx.nim @@ -20,38 +20,36 @@ const setDefines(defs.splitLines()) -when defined(windows): - when defined(amd64): - const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\"" - else: - const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\"" -else: - const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} CFLAGS=\"-fPIC -I{SDLIncludeDir}\"" +static: + let ver = getDefine("SDL2gfxPrimitivesSetVer") + downloadUrl(fmt"http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-{ver}.tar.gz", outdir=srcDir) -getHeader( - "SDL2_gfxPrimitives.h", - dlurl = "http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$1.tar.gz", - outdir = srcDir, - altNames = "SDL2_gfx,SDL_gfx", - conFlags = flags, - buildTypes = [btAutoConf] -) +# getHeader( +# "SDL2_gfxPrimitives.h", +# dlurl = "http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$1.tar.gz", +# outdir = srcDir, +# altNames = "SDL2_gfx,SDL_gfx", +# conFlags = flags, +# buildTypes = [btAutoConf] +# ) + +const ver = getDefine("SDL2gfxPrimitivesSetVer") +const newSrcDir = srcDir / fmt"SDL2_gfx-{ver}" +cIncludeDir(newSrcDir) +cCompile(newSrcDir / "SDL2_gfxPrimitives.c") +cCompile(newSrcDir / "SDL2_rotozoom.c") +cCompile(newSrcDir / "SDL2_framerate.c") +cCompile(newSrcDir / "SDL2_imageFilter.c") static: - when defined(macosx): - fixStaticFile(buildDir) + discard # cDebug() # cDisableCaching() cPluginPath(symbolPluginPath) -when isDefined(SDL2gfxPrimitivesStatic): - cImport(srcDir / "SDL2_gfxPrimitives.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_gfxprimitives.nim") - cImport(srcDir / "SDL2_rotozoom.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_rotozoom.nim") - cImport(srcDir / "SDL2_framerate.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_framerate.nim") - cImport(srcDir / "SDL2_imageFilter.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_imagefilter.nim") -else: - cImport(srcDir / "SDL2_gfxPrimitives.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_gfxprimitives.nim") - cImport(srcDir / "SDL2_rotozoom.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_rotozoom.nim") - cImport(srcDir / "SDL2_framerate.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_framerate.nim") - cImport(srcDir / "SDL2_imageFilter.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_imagefilter.nim") +cImport( + @[newSrcDir / "SDL2_gfxPrimitives.h", newSrcDir / "SDL2_rotozoom.h", + newSrcDir / "SDL2_framerate.h", newSrcDir / "SDL2_imageFilter.h"], + recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_gfx.nim" +) \ No newline at end of file diff --git a/src/sdl2/sdl2_gpu.nim b/src/sdl2/sdl2_gpu.nim index cd4d946..7778424 100644 --- a/src/sdl2/sdl2_gpu.nim +++ b/src/sdl2/sdl2_gpu.nim @@ -1,14 +1,16 @@ import macros import os, strformat, strutils import sdl2 +import glew import nimterop/[build, cimport, globals] const baseDir = SDLCacheDir sdlDir = (baseDir / "sdl2").sanitizePath srcDir = (baseDir / "sdl2_gpu").sanitizePath - currentPath = getProjectPath().parentDir().sanitizePath - generatedPath = (currentPath / "generated" / "sdl2_gpu").replace("\\", "/") + currentProjectPath = getProjectPath().parentDir().sanitizePath + currentPath = currentSourcePath.parentDir().parentDir().sanitizePath + generatedPath = (currentProjectPath / "generated" / "sdl2_gpu").replace("\\", "/") cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/") symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath @@ -20,15 +22,25 @@ const setDefines(defs.splitLines()) -getHeader( - "SDL_gpu.h", - giturl = "https://github.com/grimfang4/sdl-gpu", - outdir = srcDir, - altNames = "SDL2_gpu,SDL2_gpu_s", - buildTypes = [btCmake], - cmakeFlags = &"-DCMAKE_C_FLAGS=-I{SDLIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} -DSDL2_LIBRARY={SDLDyLibPath} " & - &"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_PATH={sdlDir} -DSDL2_INCLUDE_DIR={SDLIncludeDir} -DSDL_gpu_BUILD_DEMOS=OFF" -) +cIncludeDir(SDLIncludeDir) +cDefine("SDL_GPU_DISABLE_GLES", "1") + +static: + gitPull( + "https://github.com/grimfang4/sdl-gpu", + outdir=srcDir, + checkout="f15d33ccef7f6e063ada7c435e864b7d4b663f88" + ) + +# getHeader( +# "SDL_gpu.h", +# giturl = "https://github.com/grimfang4/sdl-gpu", +# outdir = srcDir, +# altNames = "SDL2_gpu,SDL2_gpu_s", +# buildTypes = [btCmake], +# cmakeFlags = &"-DCMAKE_C_FLAGS=-I{SDLIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} -DSDL2_LIBRARY={SDLDyLibPath} " & +# &"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_PATH={sdlDir} -DSDL2_INCLUDE_DIR={SDLIncludeDir} -DSDL_gpu_BUILD_DEMOS=OFF" +# ) static: cSkipSymbol @["Log"] @@ -109,6 +121,27 @@ cOverride: LOG_LEVEL_WARNING LOG_LEVEL_ERROR +cIncludeDir(srcDir/"include") +cIncludeDir(srcDir/"src") +cIncludeDir(srcDir/"src"/"externals"/"stb_image") +cIncludeDir(srcDir/"src"/"externals"/"glew"/"GL") +cIncludeDir(srcDir/"src"/"externals"/"stb_image_write") + +cCompile(srcDir/"src"/"externals"/"stb_image_write"/"stb_image_write.c") +cCompile(srcDir/"src"/"SDL_gpu.c") +cCompile(srcDir/"src"/"SDL_gpu_matrix.c") +cCompile(srcDir/"src"/"SDL_gpu_renderer.c") +cCompile(srcDir/"src"/"SDL_gpu_shapes.c") +# cCompile(srcDir/"src"/"renderer_GLES_1.c") +# cCompile(srcDir/"src"/"renderer_GLES_2.c") +# cCompile(srcDir/"src"/"renderer_GLES_3.c") +cCompile(srcDir/"src"/"renderer_OpenGL_1.c") +cCompile(srcDir/"src"/"renderer_OpenGL_1_BASE.c") +cCompile(srcDir/"src"/"renderer_OpenGL_2.c") +cCompile(srcDir/"src"/"renderer_OpenGL_3.c") +cCompile(srcDir/"src"/"renderer_OpenGL_4.c") +#cCompile(srcDir/"src"/"externals"/"stb_image"/"stb_image.c") +#cCompile(srcDir/"src"/"externals"/"stb_image_write"/"stb_image_write.c") cPluginPath(symbolPluginPath) diff --git a/src/sdl2/sdl2_image.nim b/src/sdl2/sdl2_image.nim index 401a140..e6c0372 100644 --- a/src/sdl2/sdl2_image.nim +++ b/src/sdl2/sdl2_image.nim @@ -26,10 +26,12 @@ else: const dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$1.tar.gz" when defined(windows): + const winBDir = SDLBuildDir.replace("C:\\", "/c/").replace("\\", "/") + const winIDir = SDLIncludeDir.replace("C:\\", "/c/").replace("\\", "/") when defined(amd64): - const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\"" + const flags = &"--libdir={winBDir} --includedir={winIDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC -I{winIDir}\"" else: - const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\"" + const flags = &"--libdir={winBDir} --includedir={winIDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC -I{winIDir}\"" else: const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --with-pic CFLAGS=\"-fPIC -I{SDLIncludeDir}\""