Fix linking errors on mac and add a nimble test for building with nimterop
This commit is contained in:
parent
8278bc5c9c
commit
e0ba50171b
8 changed files with 52 additions and 34 deletions
|
|
@ -21,3 +21,10 @@ else:
|
||||||
|
|
||||||
task buildSDL2, "Build SDL2 example":
|
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()
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,35 @@ proc findDynlib(): string =
|
||||||
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\" & getDynlibExt()
|
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\" & getDynlibExt()
|
||||||
return findFile(pathRegex, buildDir, regex = true)
|
return findFile(pathRegex, buildDir, regex = true)
|
||||||
|
|
||||||
proc findStaticlib(): string =
|
proc findStaticlib*(dir: string): string =
|
||||||
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\.a"
|
const pathRegex = "(lib)?SDL2[_-]?(static)?([a-zA-Z]+)?[0-9.\\-]*\\.a"
|
||||||
return findFile(pathRegex, buildDir, regex = true)
|
return findFile(pathRegex, dir, regex = true)
|
||||||
|
|
||||||
proc findStaticMainlib(): string =
|
proc findStaticMainlib(): string =
|
||||||
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\main.a"
|
const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\main.a"
|
||||||
return findFile(pathRegex, buildDir, regex = true)
|
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 SDLDyLibPath* = findDynlib()
|
||||||
const SDLMainLib* = findStaticMainlib()
|
const SDLMainLib* = findStaticMainlib()
|
||||||
const SDLStaticLib* = findStaticlib()
|
const SDLStaticLib* = findStaticlib(buildDir)
|
||||||
const SDL2ConfigPath* = srcDir / "sdl2-config"
|
const SDL2ConfigPath* = srcDir / "sdl2-config"
|
||||||
const SDLSrcDir* = srcDir
|
const SDLSrcDir* = srcDir
|
||||||
const SDLBuildDir* = buildDir
|
const SDLBuildDir* = buildDir
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const
|
||||||
baseDir = SDLCacheDir
|
baseDir = SDLCacheDir
|
||||||
sdlIncludeDir = baseDir / "sdl2" / "include"
|
sdlIncludeDir = baseDir / "sdl2" / "include"
|
||||||
srcDir = baseDir / "sdl2_gfx"
|
srcDir = baseDir / "sdl2_gfx"
|
||||||
|
buildDir = srcDir / ".libs"
|
||||||
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
|
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|
@ -25,7 +26,9 @@ getHeader(
|
||||||
buildTypes = [btAutoConf]
|
buildTypes = [btAutoConf]
|
||||||
)
|
)
|
||||||
|
|
||||||
# static:
|
static:
|
||||||
|
when defined(macosx):
|
||||||
|
fixStaticFile(buildDir)
|
||||||
# cDebug()
|
# cDebug()
|
||||||
# cDisableCaching()
|
# cDisableCaching()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ getHeader(
|
||||||
giturl = "https://github.com/grimfang4/sdl-gpu",
|
giturl = "https://github.com/grimfang4/sdl-gpu",
|
||||||
outdir = srcDir,
|
outdir = srcDir,
|
||||||
altNames = "SDL2_gpu,SDL2_gpu_s",
|
altNames = "SDL2_gpu,SDL2_gpu_s",
|
||||||
|
buildTypes = [btCmake],
|
||||||
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{SDLIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} -DSDL2_LIBRARY={SDLDyLibPath} " &
|
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"
|
&"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_PATH={sdlDir} -DSDL2_INCLUDE_DIR={SDLIncludeDir} -DSDL_gpu_BUILD_DEMOS=OFF"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -33,28 +33,9 @@ getHeader(
|
||||||
buildTypes = [btAutoConf]
|
buildTypes = [btAutoConf]
|
||||||
)
|
)
|
||||||
|
|
||||||
proc findStaticlib(): string =
|
|
||||||
const pathRegex = "(lib)?SDL2_image[0-9.\\-]*\\.a"
|
|
||||||
return findFile(pathRegex, buildDir, regex = true)
|
|
||||||
|
|
||||||
static:
|
static:
|
||||||
when defined(macosx):
|
when defined(macosx):
|
||||||
# For some reason on MacOSX Catalina, the default static
|
fixStaticFile(buildDir)
|
||||||
# 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}")
|
|
||||||
# cDebug()
|
# cDebug()
|
||||||
# cDisableCaching()
|
# cDisableCaching()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const
|
||||||
baseDir = SDLCacheDir
|
baseDir = SDLCacheDir
|
||||||
sdlIncludeDir = baseDir / "sdl2" / "include"
|
sdlIncludeDir = baseDir / "sdl2" / "include"
|
||||||
srcDir = baseDir / "sdl2_mixer"
|
srcDir = baseDir / "sdl2_mixer"
|
||||||
|
buildDir = srcDir / "build" / ".libs"
|
||||||
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
|
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|
@ -30,7 +31,9 @@ getHeader(
|
||||||
buildTypes = [btAutoConf]
|
buildTypes = [btAutoConf]
|
||||||
)
|
)
|
||||||
|
|
||||||
# static:
|
static:
|
||||||
|
when defined(macosx):
|
||||||
|
fixStaticFile(buildDir)
|
||||||
# cDebug()
|
# cDebug()
|
||||||
# cDisableCaching()
|
# cDisableCaching()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const
|
||||||
baseDir = SDLCacheDir
|
baseDir = SDLCacheDir
|
||||||
sdlIncludeDir = baseDir / "sdl2" / "include"
|
sdlIncludeDir = baseDir / "sdl2" / "include"
|
||||||
srcDir = baseDir / "sdl2_net"
|
srcDir = baseDir / "sdl2_net"
|
||||||
|
buildDir = srcDir / ".libs"
|
||||||
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
|
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|
@ -30,7 +31,9 @@ getHeader(
|
||||||
buildTypes = [btAutoConf]
|
buildTypes = [btAutoConf]
|
||||||
)
|
)
|
||||||
|
|
||||||
# static:
|
static:
|
||||||
|
when defined(macosx):
|
||||||
|
fixStaticFile(buildDir)
|
||||||
# cDebug()
|
# cDebug()
|
||||||
# cDisableCaching()
|
# cDisableCaching()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ import nimterop/[cimport, build]
|
||||||
const
|
const
|
||||||
baseDir = SDLCacheDir
|
baseDir = SDLCacheDir
|
||||||
sdlDir = (baseDir / "sdl2").sanitizePath
|
sdlDir = (baseDir / "sdl2").sanitizePath
|
||||||
sdlIncludeDir = (sdlDir / "include").sanitizePath
|
|
||||||
srcDir = (baseDir / "sdl2_ttf").sanitizePath
|
srcDir = (baseDir / "sdl2_ttf").sanitizePath
|
||||||
|
buildDir = srcDir / ".libs"
|
||||||
currentPath = currentSourcePath().parentDir().parentDir().sanitizePath
|
currentPath = currentSourcePath().parentDir().parentDir().sanitizePath
|
||||||
symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath
|
symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath
|
||||||
|
|
||||||
|
|
@ -33,7 +33,9 @@ getHeader(
|
||||||
buildTypes = [btAutoConf]
|
buildTypes = [btAutoConf]
|
||||||
)
|
)
|
||||||
|
|
||||||
# static:
|
static:
|
||||||
|
when defined(macosx):
|
||||||
|
fixStaticFile(buildDir)
|
||||||
# cDebug()
|
# cDebug()
|
||||||
# cDisableCaching()
|
# cDisableCaching()
|
||||||
|
|
||||||
|
|
@ -45,6 +47,6 @@ cOverride:
|
||||||
SetError* = ""
|
SetError* = ""
|
||||||
|
|
||||||
when defined(SDL_ttf_Static):
|
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:
|
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")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue