Add static compilation for sdl_gpu and sdl_gfx

This commit is contained in:
Joey Yakimowich-Payne 2020-09-12 13:07:34 -06:00
commit c2626726a5
5 changed files with 78 additions and 42 deletions

1
.gitignore vendored
View file

@ -3,6 +3,7 @@
!*.* !*.*
build build
generated/
*.out *.out
*.exe *.exe

View file

@ -26,8 +26,10 @@ else:
const dlurl = "https://www.libsdl.org/release/SDL2-$1.tar.gz" const dlurl = "https://www.libsdl.org/release/SDL2-$1.tar.gz"
when defined(windows): when defined(windows):
const winBDir = buildDir.replace("C:\\", "/c/").replace("\\", "/")
const winIDir = includeDir.replace("C:\\", "/c/").replace("\\", "/")
when defined(amd64): 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: else:
const flags = &"--libdir={buildDir} --includedir={includeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC\"" const flags = &"--libdir={buildDir} --includedir={includeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC\""
elif defined(macosx): elif defined(macosx):

View file

@ -20,38 +20,36 @@ const
setDefines(defs.splitLines()) setDefines(defs.splitLines())
when defined(windows): static:
when defined(amd64): let ver = getDefine("SDL2gfxPrimitivesSetVer")
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\"" downloadUrl(fmt"http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-{ver}.tar.gz", outdir=srcDir)
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}\""
getHeader( # getHeader(
"SDL2_gfxPrimitives.h", # "SDL2_gfxPrimitives.h",
dlurl = "http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$1.tar.gz", # dlurl = "http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$1.tar.gz",
outdir = srcDir, # outdir = srcDir,
altNames = "SDL2_gfx,SDL_gfx", # altNames = "SDL2_gfx,SDL_gfx",
conFlags = flags, # conFlags = flags,
buildTypes = [btAutoConf] # 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: static:
when defined(macosx): discard
fixStaticFile(buildDir)
# cDebug() # cDebug()
# cDisableCaching() # cDisableCaching()
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
when isDefined(SDL2gfxPrimitivesStatic): cImport(
cImport(srcDir / "SDL2_gfxPrimitives.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_gfxprimitives.nim") @[newSrcDir / "SDL2_gfxPrimitives.h", newSrcDir / "SDL2_rotozoom.h",
cImport(srcDir / "SDL2_rotozoom.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_rotozoom.nim") newSrcDir / "SDL2_framerate.h", newSrcDir / "SDL2_imageFilter.h"],
cImport(srcDir / "SDL2_framerate.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_framerate.nim") recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_gfx.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")

View file

@ -1,14 +1,16 @@
import macros import macros
import os, strformat, strutils import os, strformat, strutils
import sdl2 import sdl2
import glew
import nimterop/[build, cimport, globals] import nimterop/[build, cimport, globals]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlDir = (baseDir / "sdl2").sanitizePath sdlDir = (baseDir / "sdl2").sanitizePath
srcDir = (baseDir / "sdl2_gpu").sanitizePath srcDir = (baseDir / "sdl2_gpu").sanitizePath
currentPath = getProjectPath().parentDir().sanitizePath currentProjectPath = getProjectPath().parentDir().sanitizePath
generatedPath = (currentPath / "generated" / "sdl2_gpu").replace("\\", "/") currentPath = currentSourcePath.parentDir().parentDir().sanitizePath
generatedPath = (currentProjectPath / "generated" / "sdl2_gpu").replace("\\", "/")
cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/") cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/")
symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath
@ -20,15 +22,25 @@ const
setDefines(defs.splitLines()) setDefines(defs.splitLines())
getHeader( cIncludeDir(SDLIncludeDir)
"SDL_gpu.h", cDefine("SDL_GPU_DISABLE_GLES", "1")
giturl = "https://github.com/grimfang4/sdl-gpu",
outdir = srcDir, static:
altNames = "SDL2_gpu,SDL2_gpu_s", gitPull(
buildTypes = [btCmake], "https://github.com/grimfang4/sdl-gpu",
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{SDLIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} -DSDL2_LIBRARY={SDLDyLibPath} " & outdir=srcDir,
&"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_PATH={sdlDir} -DSDL2_INCLUDE_DIR={SDLIncludeDir} -DSDL_gpu_BUILD_DEMOS=OFF" 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: static:
cSkipSymbol @["Log"] cSkipSymbol @["Log"]
@ -109,6 +121,27 @@ cOverride:
LOG_LEVEL_WARNING LOG_LEVEL_WARNING
LOG_LEVEL_ERROR 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) cPluginPath(symbolPluginPath)

View file

@ -26,10 +26,12 @@ else:
const dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$1.tar.gz" const dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$1.tar.gz"
when defined(windows): when defined(windows):
const winBDir = SDLBuildDir.replace("C:\\", "/c/").replace("\\", "/")
const winIDir = SDLIncludeDir.replace("C:\\", "/c/").replace("\\", "/")
when defined(amd64): 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: 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: else:
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --with-pic CFLAGS=\"-fPIC -I{SDLIncludeDir}\"" const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --with-pic CFLAGS=\"-fPIC -I{SDLIncludeDir}\""