diff --git a/sdl2.nimble b/sdl2.nimble index 6263502..e53902b 100644 --- a/sdl2.nimble +++ b/sdl2.nimble @@ -20,4 +20,11 @@ else: task docs, "Do nothing": discard task buildSDL2, "Build SDL2 example": - exec "nimble c -f -r src/sdl2.nim" \ No newline at end of file + 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() diff --git a/src/sdl2/sdl2.nim b/src/sdl2/sdl2.nim index ab74010..1371052 100644 --- a/src/sdl2/sdl2.nim +++ b/src/sdl2/sdl2.nim @@ -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 diff --git a/src/sdl2/sdl2_gfx.nim b/src/sdl2/sdl2_gfx.nim index 30a0c24..52886e5 100644 --- a/src/sdl2/sdl2_gfx.nim +++ b/src/sdl2/sdl2_gfx.nim @@ -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") \ No newline at end of file + cImport(srcDir / "SDL2_imageFilter.h", recurse = false, dynlib="SDL2_GfxPrimitives_LPath", flags = &"-I={sdlIncludeDir} -f=ast2") diff --git a/src/sdl2/sdl2_gpu.nim b/src/sdl2/sdl2_gpu.nim index 903b1c0..d9b55bb 100644 --- a/src/sdl2/sdl2_gpu.nim +++ b/src/sdl2/sdl2_gpu.nim @@ -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" ) diff --git a/src/sdl2/sdl2_image.nim b/src/sdl2/sdl2_image.nim index 0768ad0..9d5b4ff 100644 --- a/src/sdl2/sdl2_image.nim +++ b/src/sdl2/sdl2_image.nim @@ -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() diff --git a/src/sdl2/sdl2_mixer.nim b/src/sdl2/sdl2_mixer.nim index f9bd24f..533a6e4 100644 --- a/src/sdl2/sdl2_mixer.nim +++ b/src/sdl2/sdl2_mixer.nim @@ -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() diff --git a/src/sdl2/sdl2_net.nim b/src/sdl2/sdl2_net.nim index 8e49ea5..accd169 100644 --- a/src/sdl2/sdl2_net.nim +++ b/src/sdl2/sdl2_net.nim @@ -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") \ No newline at end of file + cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2") diff --git a/src/sdl2/sdl2_ttf.nim b/src/sdl2/sdl2_ttf.nim index c332ce1..a8c3c7d 100644 --- a/src/sdl2/sdl2_ttf.nim +++ b/src/sdl2/sdl2_ttf.nim @@ -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")