WIP Windows support

This commit is contained in:
Joey Yakimowich-Payne 2020-04-28 19:19:34 -06:00
commit 90c4554c7e
6 changed files with 126 additions and 28 deletions

1
.gitignore vendored
View file

@ -5,4 +5,5 @@
build build
*.out *.out
*.exe
.DS_Store .DS_Store

View file

@ -6,13 +6,20 @@ const
baseDir = SDLCacheDir baseDir = SDLCacheDir
srcDir = baseDir / "sdl2" srcDir = baseDir / "sdl2"
buildDir = srcDir / "buildcache" buildDir = srcDir / "buildcache"
includeDir = srcDir / "include"
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
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"
getHeader( getHeader(
"SDL.h", "SDL.h",
dlurl = "https://www.libsdl.org/release/SDL2-$1.tar.gz", dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
cmakeFlags = "-DSDL_STATIC_PIC=ON" cmakeFlags = "-DSDL_STATIC_PIC=ON",
altNames = "SDL2"
) )
# {.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".}
@ -20,7 +27,7 @@ static:
cSkipSymbol @[ cSkipSymbol @[
"bool", "compile_time_assert_SDL_Event", "INLINE", "FUNCTION", "bool", "compile_time_assert_SDL_Event", "INLINE", "FUNCTION",
"FILE", "LINE", "PRIu64", "PRIx64", "SDLPRIX64", "assert_state", "FILE", "LINE", "PRIu64", "PRIx64", "SDLPRIX64", "assert_state",
"assert_data", "assert_data", "NULL"
# "SDL_AssertState", "SDL_AssertData", "SDL_threadID", "SDL_Keycode", "SDL_HapticConstant", "SDL_HapticRamp", "SDL_HapticLeftRight", "SDL_HapticCustom", "SDL_HapticPause", "SDL_Log" # "SDL_AssertState", "SDL_AssertData", "SDL_threadID", "SDL_Keycode", "SDL_HapticConstant", "SDL_HapticRamp", "SDL_HapticLeftRight", "SDL_HapticCustom", "SDL_HapticPause", "SDL_Log"
] ]
# cDebug() # cDebug()
@ -99,16 +106,59 @@ cOverride:
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
static: static:
when SDL_Static: # when SDL_Static:
const conf = staticExec(&"cd {srcDir}; ./sdl2-config --static-libs || (./configure --silent; ./sdl2-config --static-libs)").replace("-lSDL2 ", "").split('\n')[^1] # 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: else:
const conf = staticExec(&"cd {srcDir}; ./sdl2-config --libs || (./configure --silent; ./sdl2-config --libs)").split('\n')[^1] const flags = ""
{.passL: conf.} configure(srcDir.sanitizePath, "sdl2-config", flags)
proc unixizePath*(path: string, noQuote = false, sep = $DirSep): string =
result = path.multiReplace([("C:\\", "/c/"), (sep, "/")])
if not noQuote:
result = result.quoteShell
static:
proc getLibOutput(output: string): string =
for line in output.split('\l'):
if "lSDL2" in line:
return line.strip()#.replace("-lSDL2 ", "").replace("-lSDL2main ", "")
when defined(SDL_Static):
when defined(windows):
#TODO: Find a way to automate this on Windows reliably
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
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 conf = execAction(cmd).output.getLibOutput
echo conf
echo buildDir.unixizePath
{.passL: &"-L{buildDir.sanitizePath} -L{buildDir.unixizePath} {conf}".}
when defined(SDL_Static): when defined(SDL_Static):
cImport(SDL_Path, 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(SDL_Path, 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 = proc getDynlibExt(): string =
when defined(windows): when defined(windows):
@ -122,9 +172,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 =
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 SDLDyLibPath* = findDynlib()
const SDLMainLib* = buildDir / "libSDL2main.a" const SDLMainLib* = buildDir / findStaticMainlib()
const SDLStaticLib* = buildDir / "libSDL2.a" const SDLStaticLib* = buildDir / findStaticlib()
const SDL2ConfigPath* = srcDir / "sdl2-config"
const SDLSrcDir* = srcDir
static:
let pathenv = getEnv("PATH")
when defined(windows):
putEnv("PATH", buildDir.sanitizePath & ";" & pathenv)
else:
putEnv("PATH", buildDir.sanitizePath & ":" & pathenv)
echo pathenv
echo includeDir
putEnv("CFLAGS", "-I" & includeDir.sanitizePath)
putEnv("LDFLAGS", &"-L{buildDir.sanitizePath} -L{buildDir.unixizePath}") # & " " & buildDir/"libSDL2main.a")
putEnv("SDL2_CONFIG", (srcDir/"sdl2-config").sanitizePath)
putEnv("LIBS", &"-L{buildDir.sanitizePath} -L{buildDir.unixizePath}")
putEnv("SDL_CFLAGS", "-I" & includeDir.sanitizePath)
putEnv("LD_LIBRARY_PATH", &"{buildDir.sanitizePath}:{buildDir.unixizePath}")
putEnv("SDL2_PATH", srcDir.sanitizePath)
const const
WINDOWPOS_UNDEFINED* = WINDOWPOS_UNDEFINED_DISPLAY(0) WINDOWPOS_UNDEFINED* = WINDOWPOS_UNDEFINED_DISPLAY(0)

View file

@ -8,9 +8,14 @@ const
srcDir = baseDir / "sdl2_image" srcDir = baseDir / "sdl2_image"
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
when defined(windows):
const dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$1.zip"
else:
const dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$1.tar.gz"
getHeader( getHeader(
"SDL_image.h", "SDL_image.h",
dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$1.tar.gz", dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_image" altNames = "SDL2_image"
) )
@ -28,6 +33,6 @@ cOverride:
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
when defined(SDL_image_Static): when defined(SDL_image_Static):
cImport(SDL_image_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2") cImport(srcDir/"SDL_image.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
else: else:
cImport(SDL_image_Path, recurse = false, dynlib = "SDL_image_LPath", flags = &"-I={sdlIncludeDir} -f=ast2") cImport(srcDir/"SDL_image.h", recurse = false, dynlib = "SDL_image_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")

View file

@ -5,14 +5,20 @@ 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"
when defined(windows):
const dlurl = "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-$1.zip"
else:
const dlurl = "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-$1.tar.gz"
getHeader( getHeader(
"SDL_mixer.h", "SDL_mixer.h",
dlurl = "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-$1.tar.gz", dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_mixer" altNames = "SDL2_mixer",
) )
# static: # static:
@ -27,7 +33,7 @@ cOverride:
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
when defined(SDL_mixer_Static): when defined(SDL_Mixer_Static):
cImport(SDL_mixer_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2") cImport(srcDir/"SDL_mixer.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
else: else:
cImport(SDL_mixer_Path, recurse = false, dynlib = "SDL_mixer_LPath", flags = &"-I={sdlIncludeDir} -f=ast2") cImport(srcDir/"SDL_mixer.h", recurse = false, dynlib = "SDL_mixer_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")

View file

@ -8,9 +8,14 @@ const
srcDir = baseDir / "sdl2_net" srcDir = baseDir / "sdl2_net"
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
when defined(windows):
const dlurl = "https://www.libsdl.org/projects/SDL_net/release/SDL2_net-$1.zip"
else:
const dlurl = "https://www.libsdl.org/projects/SDL_net/release/SDL2_net-$1.tar.gz"
getHeader( getHeader(
"SDL_net.h", "SDL_net.h",
dlurl = "https://www.libsdl.org/projects/SDL_net/release/SDL2_net-$1.tar.gz", dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_net" altNames = "SDL2_net"
) )
@ -26,8 +31,8 @@ cOverride:
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
when defined(SDL_net_Static): when defined(SDL_net_Static):
cImport(SDL_net_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2") cImport(srcDir / "SDL_net.h", recurse = false, 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")
else: else:
cImport(SDL_net_Path, recurse = false, dynlib = "SDL_net_LPath", flags = &"-I={sdlIncludeDir} -f=ast2") 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

@ -8,16 +8,21 @@ const
sdlIncludeDir = sdlDir / "include" sdlIncludeDir = sdlDir / "include"
srcDir = baseDir / "sdl2_ttf" srcDir = baseDir / "sdl2_ttf"
currentPath = currentSourcePath().parentDir().parentDir() currentPath = currentSourcePath().parentDir().parentDir()
cmakeModPath = currentPath / "cmake" / "sdl2" cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/")
symbolPluginPath = currentPath / "sdl2" / "cleansymbols.nim" symbolPluginPath = currentPath / "sdl2" / "cleansymbols.nim"
when defined(windows):
const dlurl = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-$1.zip"
else:
const dlurl = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-$1.tar.gz"
getHeader( getHeader(
"SDL_ttf.h", "SDL_ttf.h",
dlurl = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-$1.tar.gz", dlurl = dlurl,
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_ttf", altNames = "SDL2_ttf",
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} " & cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir.sanitizePath} -DCMAKE_MODULE_PATH={cmakeModPath} " &
&"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_LIBRARY={SDLDyLibPath} -DSDL2_PATH={sdlDir}" &"-DSDL2MAIN_LIBRARY={SDLMainLib.sanitizePath} -DSDL2_LIBRARY={SDLDyLibPath.sanitizePath} -DSDL2_PATH={sdlDir.sanitizePath}"
) )
# static: # static:
@ -32,6 +37,6 @@ cOverride:
SetError* = "" SetError* = ""
when defined(SDL_ttf_Static): when defined(SDL_ttf_Static):
cImport(SDL_ttf_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2 -d") cImport(srcDir / "SDL_ttf.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2 -d")
else: else:
cImport(SDL_ttf_Path, 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")