From 5fcccc9e8f89822595aeec7597571dcb89ea9481 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Tue, 5 May 2020 08:02:29 -0600 Subject: [PATCH] Fix some build issues --- sdl2.nimble | 2 +- src/sdl2/sdl2.nim | 139 +++++++++++++++++++++------------------- src/sdl2/sdl2_gfx.nim | 12 +++- src/sdl2/sdl2_gpu.nim | 9 ++- src/sdl2/sdl2_image.nim | 12 +++- src/sdl2/sdl2_mixer.nim | 11 +++- src/sdl2/sdl2_net.nim | 12 +++- src/sdl2/sdl2_ttf.nim | 14 +++- 8 files changed, 131 insertions(+), 80 deletions(-) diff --git a/sdl2.nimble b/sdl2.nimble index 2cdc5da..6263502 100644 --- a/sdl2.nimble +++ b/sdl2.nimble @@ -8,7 +8,7 @@ srcDir = "src" skipDirs = @["build"] # Dependencies -requires "nim >= 1.0.6", "nimterop#head", "regex" +requires "nim >= 1.0.6", "nimterop#head", "regex >= 0.14.1" when gorgeEx("nimble path nimterop").exitCode == 0: import nimterop/docs diff --git a/src/sdl2/sdl2.nim b/src/sdl2/sdl2.nim index 55beff2..a2d558e 100644 --- a/src/sdl2/sdl2.nim +++ b/src/sdl2/sdl2.nim @@ -4,24 +4,62 @@ import nimterop/[cimport, build] const SDLCacheDir* = currentSourcePath.parentDir().parentDir() / "build" #getProjectCacheDir("nimsdl2") baseDir = SDLCacheDir - srcDir = baseDir / "sdl2" - buildDir = srcDir / "buildcache" - includeDir = srcDir / "include" - symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" + srcDir = (baseDir / "sdl2").sanitizePath + buildDir = (srcDir / "build" / ".libs").sanitizePath + includeDir = (srcDir / "include").sanitizePath + symbolPluginPath = (currentSourcePath.parentDir() / "cleansymbols.nim").sanitizePath when defined(windows): const dlurl = "https://www.libsdl.org/release/SDL2-$1.zip" else: const dlurl = "https://www.libsdl.org/release/SDL2-$1.tar.gz" +when defined(windows): + when defined(amd64): + const flags = &"--libdir={buildDir} --includedir={includeDir} --host=x86_64-w64-mingw32" + else: + const flags = &"--libdir={buildDir} --includedir={includeDir} --host=i686-w64-mingw32" +else: + const flags = &"--libdir={buildDir} --includedir={includeDir}" + getHeader( "SDL.h", dlurl = dlurl, outdir = srcDir, - cmakeFlags = "-DSDL_STATIC_PIC=ON", - altNames = "SDL2" + conFlags = flags, + altNames = "SDL2", + buildTypes = [btAutoConf] ) +proc getDynlibExt(): string = + when defined(windows): + result = ".dll" + elif defined(linux): + result = ".so[0-9.]*" + elif defined(macosx): + result = ".dylib[0-9.]*" + +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 findStaticMainlib(): string = + const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\main.a" + return findFile(pathRegex, buildDir, regex = true) + +const SDLDyLibPath* = findDynlib() +const SDLMainLib* = findStaticMainlib() +const SDLStaticLib* = findStaticlib() +const SDL2ConfigPath* = srcDir / "sdl2-config" +const SDLSrcDir* = srcDir +const SDLBuildDir* = buildDir +const SDLIncludeDir* = includeDir + + # {.passL: "-framework GLUT -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -framework Carbon -framework CoreAudio -lm".} static: cSkipSymbol @[ @@ -105,27 +143,6 @@ cOverride: cPluginPath(symbolPluginPath) -static: - # when SDL_Static: - # when defined(windows): - # const conf = "-lmingw32 -mwindows -Wl,--no-undefined -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid -static-libgcc" - # else: - # const conf = staticExec(&"cd {srcDir}; ./sdl2-config --static-libs").replace("-lSDL2 ", "").replace("-lSDL2main", "").split('\n')[^1] - # else: - # when defined(windows): - # const conf = "-lmingw32 -lSDL2main -lSDL2 -mwindows" - # else: - # const conf = staticExec(&"cd {srcDir}; ./sdl2-config --libs || (./configure --silent; ./sdl2-config --libs)").split('\n')[^1] - - when defined(windows): - when defined(amd64): - const flags = "--host=x86_64-w64-mingw32" - else: - const flags = "--host=i686-w64-mingw32" - else: - const flags = "" - configure(srcDir.sanitizePath, "sdl2-config", flags) - proc unixizePath*(path: string, noQuote = false, sep = $DirSep): string = result = path.multiReplace([("C:\\", "/c/"), (sep, "/")]) if not noQuote: @@ -143,62 +160,50 @@ static: const conf = "-lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--no-undefined -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid -static-libgcc" else: const cmd = &"cd {srcDir.sanitizePath} && bash ./sdl2-config --static-libs" - const conf = execAction(cmd).output.getLibOutput + const conf = execAction(cmd).output.getLibOutput.replace("-lSDL2", SDLStaticLib) else: when defined(windows): #TODO: Find a way to automate this on Windows reliably const conf = "-lmingw32 -lSDL2main -lSDL2 -mwindows" else: - const cmd = &"cd {srcDir.sanitizePath} && bash ./sdl2-config --libs" + const cmd = &"cd {srcDir} && bash ./sdl2-config --libs" const conf = execAction(cmd).output.getLibOutput - {.passL: &"-L{buildDir.sanitizePath} -L{buildDir.unixizePath} {conf} -Wl,--no-as-needed -ldl -lsndio".} - let pathenv = getEnv("PATH") - when defined(windows): - putEnv("PATH", buildDir.sanitizePath & ";" & pathenv) + when defined(linux): + {.passL: &"-L{buildDir} -L{buildDir.unixizePath} {conf} -Wl,--no-as-needed -ldl -lsndio".} else: - putEnv("PATH", buildDir.sanitizePath & ":" & pathenv) - putEnv("CFLAGS", "-I" & includeDir.sanitizePath) - putEnv("LDFLAGS", &"-L{buildDir.sanitizePath} -L{buildDir.unixizePath} {conf} -Wl,--no-as-needed -lsndio -ldl") # & " " & buildDir/"libSDL2main.a") + {.passL: &"{conf}".} + + echo conf + when defined(SDL_Static): + {.passC: "-static".} + + # let pathenv = getEnv("PATH") + # when defined(windows): + # putEnv("PATH", buildDir & ";" & pathenv) + # else: + # putEnv("PATH", buildDir & ":" & pathenv) + let cflags = getEnv("CFLAGS") + putEnv("CFLAGS", &"-I{includeDir} {cflags}") + when defined(linux): + putEnv("LDFLAGS", &"-L{buildDir} -L{buildDir.unixizePath} {conf} -Wl,--no-as-needed -lsndio -ldl") # & " " & buildDir/"libSDL2main.a") + else: + putEnv("LDFLAGS", &"-L{buildDir} -L{buildDir.unixizePath} {conf}") # & " " & buildDir/"libSDL2main.a") putEnv("SDL2_CONFIG", (srcDir/"sdl2-config").sanitizePath) putEnv("SDL_CONFIG", (srcDir/"sdl2-config").sanitizePath) - putEnv("LIBS", &"-L{buildDir.sanitizePath} -L{buildDir.unixizePath}") - putEnv("SDL_CFLAGS", "-I" & includeDir.sanitizePath) - let ldpath = getEnv("LD_LIBRARY_PATH") - putEnv("LD_LIBRARY_PATH", &"{buildDir.sanitizePath}:{buildDir.unixizePath}:{ldpath}") - putEnv("SDL2_PATH", srcDir.sanitizePath) + putEnv("SDL_LIBS", &"-L{buildDir} -L{buildDir.unixizePath} {conf}") + # let ldpath = getEnv("LD_LIBRARY_PATH") + # putEnv("LD_LIBRARY_PATH", &"{buildDir}:{buildDir.unixizePath}:{ldpath}") + # when defined(macosx): + # let dyldpath = getEnv("DYLD_LIBRARY_PATH") + # putEnv("DYLD_LIBRARY_PATH", &"{buildDir}:{buildDir.unixizePath}:{dyldpath}") + # putEnv("SDL2_PATH", srcDir) when defined(SDL_Static): cImport(srcDir/"include"/"SDL.h", recurse = true, flags = "-f=ast2 -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_") else: cImport(srcDir/"include"/"SDL.h", recurse = true, dynlib = "SDL_LPath", flags = "-f=ast2 -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_") -proc getDynlibExt(): string = - when defined(windows): - result = ".dll" - elif defined(linux): - result = ".so[0-9.]*" - elif defined(macosx): - result = ".dylib[0-9.]*" - -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 findStaticMainlib(): string = - const pathRegex = "(lib)?SDL2[_-]?(static)?[0-9.\\-]*\\main.a" - return findFile(pathRegex, buildDir, regex = true) - -const SDLDyLibPath* = findDynlib() -const SDLMainLib* = findStaticMainlib() -const SDLStaticLib* = findStaticlib() -const SDL2ConfigPath* = srcDir / "sdl2-config" -const SDLSrcDir* = srcDir - const WINDOWPOS_UNDEFINED* = WINDOWPOS_UNDEFINED_DISPLAY(0) WINDOWPOS_CENTERED* = WINDOWPOS_CENTERED_DISPLAY(0) diff --git a/src/sdl2/sdl2_gfx.nim b/src/sdl2/sdl2_gfx.nim index 7045467..30a0c24 100644 --- a/src/sdl2/sdl2_gfx.nim +++ b/src/sdl2/sdl2_gfx.nim @@ -8,11 +8,21 @@ const srcDir = baseDir / "sdl2_gfx" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" +when defined(windows): + when defined(amd64): + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32" + else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32" +else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir}" + getHeader( "SDL2_gfxPrimitives.h", dlurl = "http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$1.tar.gz", outdir = srcDir, - altNames = "SDL2_gfx,SDL_gfx" + altNames = "SDL2_gfx,SDL_gfx", + conFlags = flags, + buildTypes = [btAutoConf] ) # static: diff --git a/src/sdl2/sdl2_gpu.nim b/src/sdl2/sdl2_gpu.nim index 88dbc99..903b1c0 100644 --- a/src/sdl2/sdl2_gpu.nim +++ b/src/sdl2/sdl2_gpu.nim @@ -5,7 +5,6 @@ import nimterop/[build, cimport] const baseDir = SDLCacheDir sdlDir = (baseDir / "sdl2").sanitizePath - sdlIncludeDir = (sdlDir / "include").sanitizePath srcDir = (baseDir / "sdl2_gpu").sanitizePath currentPath = currentSourcePath().parentDir().parentDir().sanitizePath cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/") @@ -16,8 +15,8 @@ getHeader( giturl = "https://github.com/grimfang4/sdl-gpu", outdir = srcDir, altNames = "SDL2_gpu,SDL2_gpu_s", - 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" + 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: @@ -123,6 +122,6 @@ const cPluginPath(symbolPluginPath) when defined(SDL_gpu_Static): - cImport(srcDir/"include"/"SDL_gpu.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2") + cImport(srcDir/"include"/"SDL_gpu.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2") else: - cImport(srcDir/"include"/"SDL_gpu.h", recurse = false, dynlib = "SDL_gpuLPath", flags = &"-I={sdlIncludeDir} -f=ast2") \ No newline at end of file + cImport(srcDir/"include"/"SDL_gpu.h", recurse = false, dynlib = "SDL_gpuLPath", flags = &"-I={SDLIncludeDir} -f=ast2") \ No newline at end of file diff --git a/src/sdl2/sdl2_image.nim b/src/sdl2/sdl2_image.nim index 09409d8..19a841a 100644 --- a/src/sdl2/sdl2_image.nim +++ b/src/sdl2/sdl2_image.nim @@ -13,11 +13,21 @@ when defined(windows): else: const dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$1.tar.gz" +when defined(windows): + when defined(amd64): + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32" + else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32" +else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir}" + getHeader( "SDL_image.h", dlurl = dlurl, outdir = srcDir, - altNames = "SDL2_image" + altNames = "SDL2_image", + conFlags = flags, + buildTypes = [btAutoConf] ) # static: diff --git a/src/sdl2/sdl2_mixer.nim b/src/sdl2/sdl2_mixer.nim index 67e734c..f9bd24f 100644 --- a/src/sdl2/sdl2_mixer.nim +++ b/src/sdl2/sdl2_mixer.nim @@ -5,7 +5,6 @@ import nimterop/[cimport, build] const baseDir = SDLCacheDir sdlIncludeDir = baseDir / "sdl2" / "include" - sdlBuildDir = baseDir / "sdl2" / "buildcache" srcDir = baseDir / "sdl2_mixer" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" @@ -14,11 +13,21 @@ when defined(windows): else: const dlurl = "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-$1.tar.gz" +when defined(windows): + when defined(amd64): + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32" + else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32" +else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir}" + getHeader( "SDL_mixer.h", dlurl = dlurl, outdir = srcDir, + conFlags = flags, altNames = "SDL2_mixer", + buildTypes = [btAutoConf] ) # static: diff --git a/src/sdl2/sdl2_net.nim b/src/sdl2/sdl2_net.nim index 785e99c..8e49ea5 100644 --- a/src/sdl2/sdl2_net.nim +++ b/src/sdl2/sdl2_net.nim @@ -13,11 +13,21 @@ when defined(windows): else: const dlurl = "https://www.libsdl.org/projects/SDL_net/release/SDL2_net-$1.tar.gz" +when defined(windows): + when defined(amd64): + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32" + else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32" +else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir}" + getHeader( "SDL_net.h", dlurl = dlurl, outdir = srcDir, - altNames = "SDL2_net" + conFlags = flags, + altNames = "SDL2_net", + buildTypes = [btAutoConf] ) # static: diff --git a/src/sdl2/sdl2_ttf.nim b/src/sdl2/sdl2_ttf.nim index d1d7796..c332ce1 100644 --- a/src/sdl2/sdl2_ttf.nim +++ b/src/sdl2/sdl2_ttf.nim @@ -8,7 +8,6 @@ const sdlIncludeDir = (sdlDir / "include").sanitizePath srcDir = (baseDir / "sdl2_ttf").sanitizePath currentPath = currentSourcePath().parentDir().parentDir().sanitizePath - cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/") symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath when defined(windows): @@ -16,13 +15,22 @@ when defined(windows): else: const dlurl = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-$1.tar.gz" +when defined(windows): + when defined(amd64): + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32" + else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32" +else: + const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir}" + + getHeader( "SDL_ttf.h", dlurl = dlurl, outdir = srcDir, altNames = "SDL2_ttf", - cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} " & - &"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_LIBRARY={SDLDyLibPath} -DSDL2_PATH={sdlDir}" + conFlags = flags, + buildTypes = [btAutoConf] ) # static: