Fix linking errors on mac and add a nimble test for building with nimterop

This commit is contained in:
Joey Yakimowich-Payne 2020-05-10 09:15:42 -06:00
commit e0ba50171b
8 changed files with 52 additions and 34 deletions

View file

@ -20,4 +20,11 @@ else:
task docs, "Do nothing": discard
task buildSDL2, "Build SDL2 example":
exec "nimble c -f -r src/sdl2.nim"
exec "nimble c -f -r src/sdl2.nim"
exec "nimble c -f -r src/sdl2/sdl2_gpu.nim"
task test, "Test":
buildSDL2Task()
# Doc building doesn't work on linux yet
when not defined(linux):
docsTask()

View file

@ -43,17 +43,35 @@ proc findDynlib(): string =
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\" & getDynlibExt()
return findFile(pathRegex, buildDir, regex = true)
proc findStaticlib(): string =
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\.a"
return findFile(pathRegex, buildDir, regex = true)
proc findStaticlib*(dir: string): string =
const pathRegex = "(lib)?SDL2[_-]?(static)?([a-zA-Z]+)?[0-9.\\-]*\\.a"
return findFile(pathRegex, dir, regex = true)
proc findStaticMainlib(): string =
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\main.a"
return findFile(pathRegex, buildDir, regex = true)
proc fixStaticFile*(dir: string) =
# For some reason on MacOSX Catalina, the default static
# binary is linked weird and causes the error:
# "ld: warning: ignoring file
# /path/to/sdl2_image/.libs/libSDL2_image.a,
# building for macOS-x86_64 but attempting to link
# with file built for macOS-x86_64"
#
# Simply recombining the object files into a static file seems to work
let staticFile = findStaticlib(buildDir)
rmFile(staticFile)
let res = execAction(&"ar ru {staticFile} {dir}/*.o")
if res.ret != 0:
raise newException(CatchableError, &"Error: could not build static lib {staticFile}: {res.output}")
let ranres = execAction(&"ranlib {staticFile}")
if ranres.ret != 0:
raise newException(CatchableError, &"Error: could not build static lib {staticFile}: {ranres.output}")
const SDLDyLibPath* = findDynlib()
const SDLMainLib* = findStaticMainlib()
const SDLStaticLib* = findStaticlib()
const SDLStaticLib* = findStaticlib(buildDir)
const SDL2ConfigPath* = srcDir / "sdl2-config"
const SDLSrcDir* = srcDir
const SDLBuildDir* = buildDir

View file

@ -6,6 +6,7 @@ const
baseDir = SDLCacheDir
sdlIncludeDir = baseDir / "sdl2" / "include"
srcDir = baseDir / "sdl2_gfx"
buildDir = srcDir / ".libs"
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
when defined(windows):
@ -25,7 +26,9 @@ getHeader(
buildTypes = [btAutoConf]
)
# static:
static:
when defined(macosx):
fixStaticFile(buildDir)
# cDebug()
# cDisableCaching()
@ -40,4 +43,4 @@ else:
cImport(srcDir / "SDL2_gfxPrimitives.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDL2_rotozoom.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDL2_framerate.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDL2_imageFilter.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDL2_imageFilter.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")

View file

@ -15,6 +15,7 @@ getHeader(
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"
)

View file

@ -33,28 +33,9 @@ getHeader(
buildTypes = [btAutoConf]
)
proc findStaticlib(): string =
const pathRegex = "(lib)?SDL2_image[0-9.\\-]*\\.a"
return findFile(pathRegex, buildDir, regex = true)
static:
when defined(macosx):
# For some reason on MacOSX Catalina, the default static
# binary is linked weird and causes the error:
# "ld: warning: ignoring file
# /path/to/sdl2_image/.libs/libSDL2_image.a,
# building for macOS-x86_64 but attempting to link
# with file built for macOS-x86_64"
#
# Simply recombining the object files into a static file seems to work
let staticFile = findStaticlib()
rmFile(staticFile)
let res = execAction(&"ar ru {staticFile} {buildDir}/*.o")
if res.ret != 0:
raise newException(CatchableError, &"Error: could not build static lib {staticFile}: {res.output}")
let ranres = execAction(&"ranlib {staticFile}")
if ranres.ret != 0:
raise newException(CatchableError, &"Error: could not build static lib {staticFile}: {ranres.output}")
fixStaticFile(buildDir)
# cDebug()
# cDisableCaching()

View file

@ -6,6 +6,7 @@ const
baseDir = SDLCacheDir
sdlIncludeDir = baseDir / "sdl2" / "include"
srcDir = baseDir / "sdl2_mixer"
buildDir = srcDir / "build" / ".libs"
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
when defined(windows):
@ -30,7 +31,9 @@ getHeader(
buildTypes = [btAutoConf]
)
# static:
static:
when defined(macosx):
fixStaticFile(buildDir)
# cDebug()
# cDisableCaching()

View file

@ -6,6 +6,7 @@ const
baseDir = SDLCacheDir
sdlIncludeDir = baseDir / "sdl2" / "include"
srcDir = baseDir / "sdl2_net"
buildDir = srcDir / ".libs"
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
when defined(windows):
@ -30,7 +31,9 @@ getHeader(
buildTypes = [btAutoConf]
)
# static:
static:
when defined(macosx):
fixStaticFile(buildDir)
# cDebug()
# cDisableCaching()
@ -45,4 +48,4 @@ when defined(SDL_net_Static):
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
else:
cImport(srcDir / "SDL_net.h", recurse = false, dynlib = "SDL_net_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")

View file

@ -5,8 +5,8 @@ import nimterop/[cimport, build]
const
baseDir = SDLCacheDir
sdlDir = (baseDir / "sdl2").sanitizePath
sdlIncludeDir = (sdlDir / "include").sanitizePath
srcDir = (baseDir / "sdl2_ttf").sanitizePath
buildDir = srcDir / ".libs"
currentPath = currentSourcePath().parentDir().parentDir().sanitizePath
symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath
@ -33,7 +33,9 @@ getHeader(
buildTypes = [btAutoConf]
)
# static:
static:
when defined(macosx):
fixStaticFile(buildDir)
# cDebug()
# cDisableCaching()
@ -45,6 +47,6 @@ cOverride:
SetError* = ""
when defined(SDL_ttf_Static):
cImport(srcDir / "SDL_ttf.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2 -d")
cImport(srcDir / "SDL_ttf.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -d")
else:
cImport(srcDir / "SDL_ttf.h", recurse = false, dynlib = "SDL_ttf_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDL_ttf.h", recurse = false, dynlib = "SDL_ttf_LPath", flags = &"-I={SDLIncludeDir} -f=ast2")