Fix some build issues

This commit is contained in:
Joey Yakimowich-Payne 2020-05-05 08:02:29 -06:00
commit 5fcccc9e8f
8 changed files with 131 additions and 80 deletions

View file

@ -8,7 +8,7 @@ srcDir = "src"
skipDirs = @["build"] skipDirs = @["build"]
# Dependencies # 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: when gorgeEx("nimble path nimterop").exitCode == 0:
import nimterop/docs import nimterop/docs

View file

@ -4,24 +4,62 @@ import nimterop/[cimport, build]
const const
SDLCacheDir* = currentSourcePath.parentDir().parentDir() / "build" #getProjectCacheDir("nimsdl2") SDLCacheDir* = currentSourcePath.parentDir().parentDir() / "build" #getProjectCacheDir("nimsdl2")
baseDir = SDLCacheDir baseDir = SDLCacheDir
srcDir = baseDir / "sdl2" srcDir = (baseDir / "sdl2").sanitizePath
buildDir = srcDir / "buildcache" buildDir = (srcDir / "build" / ".libs").sanitizePath
includeDir = srcDir / "include" includeDir = (srcDir / "include").sanitizePath
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = (currentSourcePath.parentDir() / "cleansymbols.nim").sanitizePath
when defined(windows): when defined(windows):
const dlurl = "https://www.libsdl.org/release/SDL2-$1.zip" const dlurl = "https://www.libsdl.org/release/SDL2-$1.zip"
else: 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(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( getHeader(
"SDL.h", "SDL.h",
dlurl = dlurl, dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
cmakeFlags = "-DSDL_STATIC_PIC=ON", conFlags = flags,
altNames = "SDL2" 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".} # {.passL: "-framework GLUT -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -framework Carbon -framework CoreAudio -lm".}
static: static:
cSkipSymbol @[ cSkipSymbol @[
@ -105,27 +143,6 @@ cOverride:
cPluginPath(symbolPluginPath) 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 = proc unixizePath*(path: string, noQuote = false, sep = $DirSep): string =
result = path.multiReplace([("C:\\", "/c/"), (sep, "/")]) result = path.multiReplace([("C:\\", "/c/"), (sep, "/")])
if not noQuote: 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" 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: else:
const cmd = &"cd {srcDir.sanitizePath} && bash ./sdl2-config --static-libs" 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: else:
when defined(windows): when defined(windows):
#TODO: Find a way to automate this on Windows reliably #TODO: Find a way to automate this on Windows reliably
const conf = "-lmingw32 -lSDL2main -lSDL2 -mwindows" const conf = "-lmingw32 -lSDL2main -lSDL2 -mwindows"
else: else:
const cmd = &"cd {srcDir.sanitizePath} && bash ./sdl2-config --libs" const cmd = &"cd {srcDir} && bash ./sdl2-config --libs"
const conf = execAction(cmd).output.getLibOutput 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(linux):
when defined(windows): {.passL: &"-L{buildDir} -L{buildDir.unixizePath} {conf} -Wl,--no-as-needed -ldl -lsndio".}
putEnv("PATH", buildDir.sanitizePath & ";" & pathenv)
else: else:
putEnv("PATH", buildDir.sanitizePath & ":" & pathenv) {.passL: &"{conf}".}
putEnv("CFLAGS", "-I" & includeDir.sanitizePath)
putEnv("LDFLAGS", &"-L{buildDir.sanitizePath} -L{buildDir.unixizePath} {conf} -Wl,--no-as-needed -lsndio -ldl") # & " " & buildDir/"libSDL2main.a") 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("SDL2_CONFIG", (srcDir/"sdl2-config").sanitizePath)
putEnv("SDL_CONFIG", (srcDir/"sdl2-config").sanitizePath) putEnv("SDL_CONFIG", (srcDir/"sdl2-config").sanitizePath)
putEnv("LIBS", &"-L{buildDir.sanitizePath} -L{buildDir.unixizePath}") putEnv("SDL_LIBS", &"-L{buildDir} -L{buildDir.unixizePath} {conf}")
putEnv("SDL_CFLAGS", "-I" & includeDir.sanitizePath) # let ldpath = getEnv("LD_LIBRARY_PATH")
let ldpath = getEnv("LD_LIBRARY_PATH") # putEnv("LD_LIBRARY_PATH", &"{buildDir}:{buildDir.unixizePath}:{ldpath}")
putEnv("LD_LIBRARY_PATH", &"{buildDir.sanitizePath}:{buildDir.unixizePath}:{ldpath}") # when defined(macosx):
putEnv("SDL2_PATH", srcDir.sanitizePath) # let dyldpath = getEnv("DYLD_LIBRARY_PATH")
# putEnv("DYLD_LIBRARY_PATH", &"{buildDir}:{buildDir.unixizePath}:{dyldpath}")
# putEnv("SDL2_PATH", srcDir)
when defined(SDL_Static): when defined(SDL_Static):
cImport(srcDir/"include"/"SDL.h", recurse = true, flags = "-f=ast2 -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_") cImport(srcDir/"include"/"SDL.h", recurse = true, flags = "-f=ast2 -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_")
else: else:
cImport(srcDir/"include"/"SDL.h", recurse = true, dynlib = "SDL_LPath", flags = "-f=ast2 -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_") 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 const
WINDOWPOS_UNDEFINED* = WINDOWPOS_UNDEFINED_DISPLAY(0) WINDOWPOS_UNDEFINED* = WINDOWPOS_UNDEFINED_DISPLAY(0)
WINDOWPOS_CENTERED* = WINDOWPOS_CENTERED_DISPLAY(0) WINDOWPOS_CENTERED* = WINDOWPOS_CENTERED_DISPLAY(0)

View file

@ -8,11 +8,21 @@ const
srcDir = baseDir / "sdl2_gfx" srcDir = baseDir / "sdl2_gfx"
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" 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( 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,
buildTypes = [btAutoConf]
) )
# static: # static:

View file

@ -5,7 +5,6 @@ import nimterop/[build, cimport]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlDir = (baseDir / "sdl2").sanitizePath sdlDir = (baseDir / "sdl2").sanitizePath
sdlIncludeDir = (sdlDir / "include").sanitizePath
srcDir = (baseDir / "sdl2_gpu").sanitizePath srcDir = (baseDir / "sdl2_gpu").sanitizePath
currentPath = currentSourcePath().parentDir().parentDir().sanitizePath currentPath = currentSourcePath().parentDir().parentDir().sanitizePath
cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/") cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/")
@ -16,8 +15,8 @@ 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",
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"
) )
static: static:
@ -123,6 +122,6 @@ const
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
when defined(SDL_gpu_Static): 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: else:
cImport(srcDir/"include"/"SDL_gpu.h", recurse = false, dynlib = "SDL_gpuLPath", flags = &"-I={sdlIncludeDir} -f=ast2") cImport(srcDir/"include"/"SDL_gpu.h", recurse = false, dynlib = "SDL_gpuLPath", flags = &"-I={SDLIncludeDir} -f=ast2")

View file

@ -13,11 +13,21 @@ when defined(windows):
else: 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(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( getHeader(
"SDL_image.h", "SDL_image.h",
dlurl = dlurl, dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_image" altNames = "SDL2_image",
conFlags = flags,
buildTypes = [btAutoConf]
) )
# static: # static:

View file

@ -5,7 +5,6 @@ import nimterop/[cimport, build]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlIncludeDir = baseDir / "sdl2" / "include" sdlIncludeDir = baseDir / "sdl2" / "include"
sdlBuildDir = baseDir / "sdl2" / "buildcache"
srcDir = baseDir / "sdl2_mixer" srcDir = baseDir / "sdl2_mixer"
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
@ -14,11 +13,21 @@ when defined(windows):
else: else:
const dlurl = "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-$1.tar.gz" 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( getHeader(
"SDL_mixer.h", "SDL_mixer.h",
dlurl = dlurl, dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
conFlags = flags,
altNames = "SDL2_mixer", altNames = "SDL2_mixer",
buildTypes = [btAutoConf]
) )
# static: # static:

View file

@ -13,11 +13,21 @@ when defined(windows):
else: else:
const dlurl = "https://www.libsdl.org/projects/SDL_net/release/SDL2_net-$1.tar.gz" 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( getHeader(
"SDL_net.h", "SDL_net.h",
dlurl = dlurl, dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_net" conFlags = flags,
altNames = "SDL2_net",
buildTypes = [btAutoConf]
) )
# static: # static:

View file

@ -8,7 +8,6 @@ const
sdlIncludeDir = (sdlDir / "include").sanitizePath sdlIncludeDir = (sdlDir / "include").sanitizePath
srcDir = (baseDir / "sdl2_ttf").sanitizePath srcDir = (baseDir / "sdl2_ttf").sanitizePath
currentPath = currentSourcePath().parentDir().parentDir().sanitizePath currentPath = currentSourcePath().parentDir().parentDir().sanitizePath
cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/")
symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath
when defined(windows): when defined(windows):
@ -16,13 +15,22 @@ when defined(windows):
else: else:
const dlurl = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-$1.tar.gz" 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( getHeader(
"SDL_ttf.h", "SDL_ttf.h",
dlurl = dlurl, dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_ttf", altNames = "SDL2_ttf",
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} " & conFlags = flags,
&"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_LIBRARY={SDLDyLibPath} -DSDL2_PATH={sdlDir}" buildTypes = [btAutoConf]
) )
# static: # static: