Compare commits

..

2 commits

Author SHA1 Message Date
Joey
273429b5c9 Set theme jekyll-theme-slate 2020-04-26 15:18:07 -06:00
Joey Yakimowich-Payne
5d757b3170 Add docs 2020-04-26 15:16:19 -06:00
13 changed files with 245 additions and 580 deletions

4
.gitignore vendored
View file

@ -3,8 +3,6 @@
!*.* !*.*
build build
generated/
*.out *.out
*.exe .DS_Store
.DS_Store

View file

@ -1,61 +1,37 @@
# nim-sdl2 ## Welcome to GitHub Pages
NOTE: This project is not in a ready to use state yet. Working on adding support for Windows & Linux. You can use the [editor on GitHub](https://github.com/jyapayne/nim-sdl2/edit/gh-pages/README.md) to maintain and preview the content for your website in Markdown files.
Autogenerated Nim bindings around SDL2. These bindings should be complete. Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files.
Bindings are autogenerated at compile time and all related libraries are downloaded and built for you as well. You can specify the version of each SDL2 lib using the information in the Configuration section below. ### Markdown
## Installation Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for
``` ```markdown
nimble install nim_sdl2 Syntax highlighted code block
# Header 1
## Header 2
### Header 3
- Bulleted
- List
1. Numbered
2. List
**Bold** and _Italic_ and `Code` text
[Link](url) and ![Image](src)
``` ```
## Usage For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/).
Examples are coming. To import (and use all libs except sdl2_gpu), use ### Jekyll Themes
```nim Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/jyapayne/nim-sdl2/settings). The name of this theme is saved in the Jekyll `_config.yml` configuration file.
import sdl2
import sdl2 / sdl2_gpu
```
If you want to only use specific libs, import individually: ### Support or Contact
```nim Having trouble with Pages? Check out our [documentation](https://help.github.com/categories/github-pages-basics/) or [contact support](https://github.com/contact) and we’ll help you sort it out.
import sdl2 / sdl2
import sdl2 / sdl2_image
import sdl2 / sdl2_ttf
import sdl2 / sdl2_net
import sdl2 / sdl2_mixer
import sdl2 / sdl2_gfx
import sdl2 / sdl2_gpu
```
## Configuration
This project uses [nimterop](https://github.com/nimterop/nimterop) to generate it's bindings and documentation.
As such, nimterop provides a nice configuration for choosing which versions of libraries get installed. To do so, create a `nim.cfg` file in your project's root directory (if one doesn't exist), and add the following:
```cfg
-d:SDL_SetVer="2.0.12" -d:SDL_DL -d:SDL_Static
-d:SDL_ImageSetVer="2.0.5" -d:SDL_Image_DL -d:SDL_Image_Static
-d:SDL_NetSetVer="2.0.1" -d:SDL_Net_DL -d:SDL_Net_Static
-d:SDL_MixerSetVer="2.0.4" -d:SDL_Mixer_DL -d:SDL_Mixer_Static
-d:SDL_ttf_SetVer="2.0.15" -d:SDL_TTF_DL -d:SDL_ttf_Static
-d:SDL_GpuSetVer="def5ea1" -d:SDL_GPU_Git -d:SDL_Gpu_Static
-d:SDL2_GFXPrimitivesSetVer="1.0.4" -d:SDL2_GFXPrimitives_DL -d:SDL2_GFXPrimitives_Static -d:SDL2_GFX_Static
```
Change the versions as needed above. `sdl-gpu` is in a git repo, so the version it uses is the commit hash. `SDL2_GFXPrimitives` is `sdl2-gfx`, just the naming is a bit weird. If you want to build a dynamically linked library, remove the `_Static` options above.
## Documentation
View autogenerated documentation [here](https://jyapayne.github.io/nim-sdl2).
All symbols and procedure definitions should be in line with their C counterparts, except with the prefixes removed (GPU_, SDL_, etc).
See the [SDL2 docs](https://wiki.libsdl.org/) for more information.

1
_config.yml Normal file
View file

@ -0,0 +1 @@
theme: jekyll-theme-slate

View file

@ -0,0 +1,7 @@
-d:SDL_SetVer="2.0.12" -d:SDL_DL -d:SDL_Static
-d:SDL_ImageSetVer="2.0.5" -d:SDL_Image_DL -d:SDL_Image_Static
-d:SDL_NetSetVer="2.0.1" -d:SDL_Net_DL -d:SDL_Net_Static
-d:SDL_MixerSetVer="2.0.4" -d:SDL_Mixer_DL -d:SDL_Mixer_Static
-d:SDL_ttf_SetVer="2.0.15" -d:SDL_TTF_DL -d:SDL_ttf_Static
-d:SDL_GpuSetVer="def5ea1" -d:SDL_GPU_Git -d:SDL_Gpu_Static
-d:SDL2_GFXPrimitivesSetVer="1.0.4" -d:SDL2_GFXPrimitives_DL -d:SDL2_GFXPrimitives_Static -d:SDL2_GFX_Static

View file

@ -1,6 +1,6 @@
# Package # Package
version = "0.3.0" version = "0.1.0"
author = "Joey Yakimowich-Payne" author = "Joey Yakimowich-Payne"
description = "SDL2 Autogenerated wrapper" description = "SDL2 Autogenerated wrapper"
license = "MIT" license = "MIT"
@ -8,7 +8,7 @@ srcDir = "src"
skipDirs = @["build"] skipDirs = @["build"]
# Dependencies # Dependencies
requires "nim >= 1.0.6", "https://github.com/jyapayne/nimterop#head" requires "nim >= 1.0.6", "nimterop#head", "regex"
when gorgeEx("nimble path nimterop").exitCode == 0: when gorgeEx("nimble path nimterop").exitCode == 0:
import nimterop/docs import nimterop/docs
@ -20,11 +20,4 @@ else:
task docs, "Do nothing": discard task docs, "Do nothing": discard
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()

View file

@ -1,41 +1,28 @@
import macros, nimterop / plugin import macros, nimterop / plugin
import strutils import strutils, regex
import sets import sets
template camelCase(str: string): string = proc firstLetterLower(m: RegexMatch, s: string): string =
var res = newStringOfCap(str.len) if m.groupsCount > 0 and m.group(0).len > 0:
var i = 0 return s[m.group(0)[0]].toLowerAscii
while i < str.len:
if str[i] == '_' and i < str.len - 1:
res.add(str[i+1].toUpperAscii)
i += 1
else:
res.add(str[i])
i += 1
res
template lowerFirstLetter(str, rep: string): string = proc camelCase(m: RegexMatch, s: string): string =
if str.startsWith(rep): if m.groupsCount > 0 and m.group(0).len > 0:
var res = str[rep.len .. ^1] return s[m.group(0)[0]].toUpperAscii
res[0] = res[0].toLowerAscii
res
else:
str
template removeBeginning(str, rep: string): string = proc nothing(m: RegexMatch, s: string): string =
if str.startsWith(rep): if m.groupsCount > 0 and m.group(0).len > 0:
str[rep.len .. ^1] return s[m.group(0)[0]]
else:
str
const replacements = [ const replacements = [
"GPU_", re"^GPU_(.)",
"SDL_", re"^SDL_(.)",
"TTF_", re"^TTF_(.)",
"SDLNet_", re"^SDLNet_(.)",
"Mix_", re"^Mix_(.)",
"IMG_" re"^IMG_(.)"
] ]
const underscoreReg = re"_(.)"
const EVENT_TYPES = toHashSet([ const EVENT_TYPES = toHashSet([
"FIRSTEVENT", "FIRSTEVENT",
@ -122,10 +109,15 @@ proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
for rep in replacements: for rep in replacements:
if sym.kind == nskProc: if sym.kind == nskProc:
sym.name = lowerFirstLetter(sym.name, rep) try:
sym.name = sym.name.replace(rep, firstLetterLower)
except:
discard
else: else:
sym.name = removeBeginning(sym.name, rep) try:
sym.name = sym.name.replace(rep, nothing)
except:
discard
if sym.name.startsWith("SDLK_"): if sym.name.startsWith("SDLK_"):
sym.name = sym.name.replace("SDLK_", "KEYCODE_") sym.name = sym.name.replace("SDLK_", "KEYCODE_")
@ -147,10 +139,10 @@ proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
sym.name = "SDLPRIX64" sym.name = "SDLPRIX64"
if sym.kind == nskField: if sym.kind == nskField:
sym.name = camelCase(sym.name) sym.name = sym.name.replace(underscoreReg, camelCase)
if sym.name == "type": if sym.name == "type":
sym.name = "kind" sym.name = "kind"
# if INT_TYPES.contains(sym.name): # if INT_TYPES.contains(sym.name):
# sym.name = sym.name.replace("S", "") # sym.name = sym.name.replace("S", "")
# sym.name = sym.name.toLowerAscii() & "_ty" # sym.name = sym.name.toLowerAscii() & "_ty"

View file

@ -1,104 +1,26 @@
import macros
import os, strutils, strformat import os, strutils, strformat
import nimterop/[cimport, build, globals] import nimterop/[cimport, build]
const const
SDLCacheDir* = getProjectCacheDir("nimsdl2") SDLCacheDir* = currentSourcePath.parentDir().parentDir() / "build" #getProjectCacheDir("nimsdl2")
baseDir = SDLCacheDir baseDir = SDLCacheDir
srcDir = (baseDir / "sdl2").sanitizePath srcDir = baseDir / "sdl2"
buildDir = (srcDir / "build" / ".libs").sanitizePath buildDir = srcDir / "buildcache"
includeDir = (srcDir / "include").sanitizePath symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
currentPath = getProjectPath().parentDir().sanitizePath
generatedPath = (currentPath / "generated" / "sdl2").replace("\\", "/")
symbolPluginPath = (currentSourcePath.parentDir() / "cleansymbols.nim").sanitizePath
defs = """
SDLSetVer=2.0.12
SDLDL
SDLStatic
"""
setDefines(defs.splitLines())
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):
const winBDir = buildDir.replace("C:\\", "/c/").replace("\\", "/")
const winIDir = includeDir.replace("C:\\", "/c/").replace("\\", "/")
when defined(amd64):
const flags = &"--libdir={winBDir} --includedir={winIDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC\""
else:
const flags = &"--libdir={buildDir} --includedir={includeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC\""
elif defined(macosx):
const flags = &"--libdir={buildDir} --includedir={includeDir} CFLAGS=\"-fPIC\""
else:
const flags = &"CFLAGS=\"-fPIC\""
getHeader( getHeader(
"SDL.h", "SDL.h",
dlurl = dlurl, dlurl = "https://www.libsdl.org/release/SDL2-$1.tar.gz",
outdir = srcDir, outdir = srcDir,
conFlags = flags, cmakeFlags = "-DSDL_STATIC_PIC=ON"
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*(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(dir)
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(buildDir)
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 @[
"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", "NULL" "assert_data",
# "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()
@ -176,69 +98,33 @@ cOverride:
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
proc unixizePath*(path: string, noQuote = false, sep = $DirSep): string =
result = path.multiReplace([("C:\\", "/c/"), (sep, "/")])
if not noQuote:
result = result.quoteShell
static: static:
proc getLibOutput(output: string): string = when SDL_Static:
for line in output.split('\l'): const conf = staticExec(&"cd {srcDir}; ./sdl2-config --static-libs || (./configure --silent; ./sdl2-config --static-libs)").replace("-lSDL2 ", "").split('\n')[^1]
if "lSDL2" in line:
return line.strip()#.replace("-lSDL2 ", "").replace("-lSDL2main ", "")
when isDefined(SDLStatic):
when defined(windows):
#TODO: Find a way to automate this on Windows reliably
const conf = &"-lmingw32 {SDLStaticLib} {SDLMainLib} -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.replace("-lSDL2", SDLStaticLib)
else: else:
when defined(windows): const conf = staticExec(&"cd {srcDir}; ./sdl2-config --libs || (./configure --silent; ./sdl2-config --libs)").split('\n')[^1]
#TODO: Find a way to automate this on Windows reliably {.passL: conf.}
const conf = &"-L{buildDir} -lmingw32 -lSDL2main -lSDL2 -mwindows"
else:
const cmd = &"cd {srcDir} && bash ./sdl2-config --libs"
const conf = execAction(cmd).output.getLibOutput
when defined(linux): when defined(SDL_Static):
{.passL: &"{conf} -Wl,--no-as-needed -ldl -lsndio".} cImport(SDL_Path, recurse = true, flags = "-f=ast2 -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_")
else:
{.passL: &"{conf}".}
echo conf
# let pathenv = getEnv("PATH")
# when defined(windows):
# putEnv("PATH", buildDir & ";" & pathenv)
# else:
# putEnv("PATH", buildDir & ":" & pathenv)
let cflags = getEnv("CFLAGS")
putEnv("CFLAGS", &"-I{includeDir} -fPIC {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("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(macosx):
{.passC: "-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk".}
else: else:
{.passC: "-fPIC".} cImport(SDL_Path, recurse = true, dynlib = "SDL_LPath", flags = "-f=ast2 -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_")
when isDefined(SDLStatic): proc getDynlibExt(): string =
cImport(srcDir/"include"/"SDL.h", recurse = true, flags = "-f=ast2 -H -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_", nimFile = generatedPath / "sdl2.nim") when defined(windows):
else: result = ".dll"
cImport(srcDir/"include"/"SDL.h", recurse = true, dynlib = "SDL_LPath", flags = "-f=ast2 -H -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_", nimFile = generatedPath / "sdl2.nim") 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)
const SDLDyLibPath* = findDynlib()
const SDLMainLib* = buildDir / "libSDL2main.a"
const SDLStaticLib* = buildDir / "libSDL2.a"
const const
WINDOWPOS_UNDEFINED* = WINDOWPOS_UNDEFINED_DISPLAY(0) WINDOWPOS_UNDEFINED* = WINDOWPOS_UNDEFINED_DISPLAY(0)
@ -250,4 +136,4 @@ const
BUTTON_MMASK* = sdl_button(BUTTON_MIDDLE) BUTTON_MMASK* = sdl_button(BUTTON_MIDDLE)
BUTTON_RMASK* = sdl_button(BUTTON_RIGHT) BUTTON_RMASK* = sdl_button(BUTTON_RIGHT)
BUTTON_X1MASK* = sdl_button(BUTTON_X1) BUTTON_X1MASK* = sdl_button(BUTTON_X1)
BUTTON_X2MASK* = sdl_button(BUTTON_X2) BUTTON_X2MASK* = sdl_button(BUTTON_X2)

View file

@ -1,55 +1,33 @@
import macros
import os, strutils, strformat import os, strutils, strformat
import sdl2 import sdl2
import nimterop/[cimport, build, globals] import nimterop/[cimport, build]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlIncludeDir = baseDir / "sdl2" / "include"
srcDir = baseDir / "sdl2_gfx" srcDir = baseDir / "sdl2_gfx"
buildDir = srcDir / ".libs"
currentPath = getProjectPath().parentDir().sanitizePath
generatedPath = (currentPath / "generated" / "sdl2_gfx").replace("\\", "/")
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
defs = """ getHeader(
SDL2gfxPrimitivesSetVer=1.0.4 "SDL2_gfxPrimitives.h",
SDL2gfxPrimitivesDL dlurl = "http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$1.tar.gz",
SDL2gfxPrimitivesStatic outdir = srcDir,
SDL2gfxStatic altNames = "SDL2_gfx,SDL_gfx"
""" )
setDefines(defs.splitLines()) # static:
# cDebug()
static: # cDisableCaching()
let ver = getDefine("SDL2gfxPrimitivesSetVer")
downloadUrl(fmt"http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-{ver}.tar.gz", outdir=srcDir)
# getHeader(
# "SDL2_gfxPrimitives.h",
# dlurl = "http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$1.tar.gz",
# outdir = srcDir,
# altNames = "SDL2_gfx,SDL_gfx",
# conFlags = flags,
# buildTypes = [btAutoConf]
# )
const ver = getDefine("SDL2gfxPrimitivesSetVer")
const newSrcDir = srcDir / fmt"SDL2_gfx-{ver}"
cIncludeDir(newSrcDir)
cCompile(newSrcDir / "SDL2_gfxPrimitives.c")
cCompile(newSrcDir / "SDL2_rotozoom.c")
cCompile(newSrcDir / "SDL2_framerate.c")
cCompile(newSrcDir / "SDL2_imageFilter.c")
static:
discard
# cDebug()
# cDisableCaching()
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
cImport( when defined(SDL2_GfxPrimitives_Static):
@[newSrcDir / "SDL2_gfxPrimitives.h", newSrcDir / "SDL2_rotozoom.h", cImport(srcDir / "SDL2_gfxPrimitives.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
newSrcDir / "SDL2_framerate.h", newSrcDir / "SDL2_imageFilter.h"], cImport(srcDir / "SDL2_rotozoom.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_gfx.nim" cImport(srcDir / "SDL2_framerate.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
) cImport(srcDir / "SDL2_imageFilter.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
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")

View file

@ -1,46 +1,24 @@
import macros
import os, strformat, strutils import os, strformat, strutils
import sdl2 import sdl2
import glew import nimterop/[build, cimport]
import nimterop/[build, cimport, globals]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlDir = (baseDir / "sdl2").sanitizePath sdlDir = baseDir / "sdl2"
srcDir = (baseDir / "sdl2_gpu").sanitizePath sdlIncludeDir = sdlDir / "include"
currentProjectPath = getProjectPath().parentDir().sanitizePath srcDir = baseDir / "sdl2_gpu"
currentPath = currentSourcePath.parentDir().parentDir().sanitizePath currentPath = currentSourcePath().parentDir().parentDir()
generatedPath = (currentProjectPath / "generated" / "sdl2_gpu").replace("\\", "/") cmakeModPath = currentPath / "cmake" / "sdl2"
cmakeModPath = (currentPath / "cmake" / "sdl2").replace("\\", "/") symbolPluginPath = currentPath / "sdl2" / "cleansymbols.nim"
symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath
defs = """ getHeader(
SDLgpuSetVer=def5ea1 "SDL_gpu.h",
SDLgpuGit giturl = "https://github.com/grimfang4/sdl-gpu",
SDLgpuStatic outdir = srcDir,
""" altNames = "SDL2_gpu",
cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} -DSDL2_LIBRARY={SDLDyLibPath} " &
setDefines(defs.splitLines()) &"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_PATH={sdlDir} -DSDL2_INCLUDE_DIR={sdlIncludeDir} -DSDL_gpu_BUILD_DEMOS=OFF"
)
cIncludeDir(SDLIncludeDir)
cDefine("SDL_GPU_DISABLE_GLES", "1")
static:
gitPull(
"https://github.com/grimfang4/sdl-gpu",
outdir=srcDir,
checkout="f15d33ccef7f6e063ada7c435e864b7d4b663f88"
)
# getHeader(
# "SDL_gpu.h",
# 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"
# )
static: static:
cSkipSymbol @["Log"] cSkipSymbol @["Log"]
@ -48,72 +26,6 @@ static:
# cDisableCaching() # cDisableCaching()
cOverride: cOverride:
const
RENDERER_UNKNOWN* = 0.uint32
RENDERER_OPENGL_1_BASE* = 1.uint32
RENDERER_OPENGL_1* = 2.uint32
RENDERER_OPENGL_2* = 3.uint32
RENDERER_OPENGL_3* = 4.uint32
RENDERER_OPENGL_4* = 5.uint32
RENDERER_GLES_1* = 11.uint32
RENDERER_GLES_2* = 12.uint32
RENDERER_GLES_3* = 13.uint32
RENDERER_D3D9* = 21.uint32
RENDERER_D3D10* = 22.uint32
RENDERER_D3D11* = 23.uint32
NONE* = 0.uint32
FEATURE_NON_POWER_OF_TWO* = 0x1.uint32
FEATURE_RENDER_TARGETS* = 0x2.uint32
FEATURE_BLEND_EQUATIONS* = 0x4.uint32
FEATURE_BLEND_FUNC_SEPARATE* = 0x8.uint32
FEATURE_BLEND_EQUATIONS_SEPARATE* = 0x10.uint32
FEATURE_GL_BGR* = 0x20.uint32
FEATURE_GL_BGRA* = 0x40.uint32
FEATURE_GL_ABGR* = 0x80.uint32
FEATURE_VERTEX_SHADER* = 0x100.uint32
FEATURE_FRAGMENT_SHADER* = 0x200.uint32
FEATURE_PIXEL_SHADER* = 0x200.uint32
FEATURE_GEOMETRY_SHADER* = 0x400.uint32
FEATURE_WRAP_REPEAT_MIRRORED* = 0x800.uint32
FEATURE_CORE_FRAMEBUFFER_OBJECTS* = 0x1000.uint32
INIT_ENABLE_VSYNC* = 0x1.uint32
INIT_DISABLE_VSYNC* = 0x2.uint32
INIT_DISABLE_DOUBLE_BUFFER* = 0x4.uint32
INIT_DISABLE_AUTO_VIRTUAL_RESOLUTION* = 0x8.uint32
INIT_REQUEST_COMPATIBILITY_PROFILE* = 0x10.uint32
INIT_USE_ROW_BY_ROW_TEXTURE_UPLOAD_FALLBACK* = 0x20.uint32
INIT_USE_COPY_TEXTURE_UPLOAD_FALLBACK* = 0x40.uint32
POINTS* = 0x0.uint32
LINES* = 0x1.uint32
LINE_LOOP* = 0x2.uint32
LINE_STRIP* = 0x3.uint32
TRIANGLES* = 0x4.uint32
TRIANGLE_STRIP* = 0x5.uint32
TRIANGLE_FAN* = 0x6.uint32
BATCH_XY* = 0x1.uint32
BATCH_XYZ* = 0x2.uint32
BATCH_ST* = 0x4.uint32
BATCH_RGB* = 0x8.uint32
BATCH_RGBA* = 0x10.uint32
BATCH_RGB8* = 0x20.uint32
BATCH_RGBA8* = 0x40.uint32
FLIP_NONE* = 0x0.uint32
FLIP_HORIZONTAL* = 0x1.uint32
FLIP_VERTICAL* = 0x2.uint32
TYPE_BYTE* = 0x1400.uint32
TYPE_UNSIGNED_BYTE* = 0x1401.uint32
TYPE_SHORT* = 0x1402.uint32
TYPE_UNSIGNED_SHORT* = 0x1403.uint32
TYPE_INT* = 0x1404.uint32
TYPE_UNSIGNED_INT* = 0x1405.uint32
TYPE_FLOAT* = 0x1406.uint32
TYPE_DOUBLE* = 0x140A.uint32
type type
WindowFlagEnum* = WindowFlags WindowFlagEnum* = WindowFlags
LogLevelEnum* = enum LogLevelEnum* = enum
@ -121,42 +33,52 @@ cOverride:
LOG_LEVEL_WARNING LOG_LEVEL_WARNING
LOG_LEVEL_ERROR LOG_LEVEL_ERROR
cIncludeDir(srcDir/"include") const
cIncludeDir(srcDir/"src") NONE* = 0.uint32
cIncludeDir(srcDir/"src"/"externals"/"stb_image") FEATURE_NON_POWER_OF_TWO* = 0x1.uint32
cIncludeDir(srcDir/"src"/"externals"/"glew"/"GL") FEATURE_RENDER_TARGETS* = 0x2.uint32
cIncludeDir(srcDir/"src"/"externals"/"stb_image_write") FEATURE_BLEND_EQUATIONS* = 0x4.uint32
FEATURE_BLEND_FUNC_SEPARATE* = 0x8.uint32
cCompile(srcDir/"src"/"externals"/"stb_image_write"/"stb_image_write.c") FEATURE_BLEND_EQUATIONS_SEPARATE* = 0x10.uint32
cCompile(srcDir/"src"/"SDL_gpu.c") FEATURE_GL_BGR* = 0x20.uint32
cCompile(srcDir/"src"/"SDL_gpu_matrix.c") FEATURE_GL_BGRA* = 0x40.uint32
cCompile(srcDir/"src"/"SDL_gpu_renderer.c") FEATURE_GL_ABGR* = 0x80.uint32
cCompile(srcDir/"src"/"SDL_gpu_shapes.c") FEATURE_VERTEX_SHADER* = 0x100.uint32
# cCompile(srcDir/"src"/"renderer_GLES_1.c") FEATURE_FRAGMENT_SHADER* = 0x200.uint32
# cCompile(srcDir/"src"/"renderer_GLES_2.c") FEATURE_PIXEL_SHADER* = 0x200.uint32
# cCompile(srcDir/"src"/"renderer_GLES_3.c") FEATURE_GEOMETRY_SHADER* = 0x400.uint32
cCompile(srcDir/"src"/"renderer_OpenGL_1.c") FEATURE_WRAP_REPEAT_MIRRORED* = 0x800.uint32
cCompile(srcDir/"src"/"renderer_OpenGL_1_BASE.c") FEATURE_CORE_FRAMEBUFFER_OBJECTS* = 0x1000.uint32
cCompile(srcDir/"src"/"renderer_OpenGL_2.c") FEATURE_ALL_BASE* = FEATURE_RENDER_TARGETS
cCompile(srcDir/"src"/"renderer_OpenGL_3.c")
cCompile(srcDir/"src"/"renderer_OpenGL_4.c")
#cCompile(srcDir/"src"/"externals"/"stb_image"/"stb_image.c")
#cCompile(srcDir/"src"/"externals"/"stb_image_write"/"stb_image_write.c")
cPluginPath(symbolPluginPath)
when isDefined(SDLgpuStatic):
cImport(srcDir/"include"/"SDL_gpu.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_gpu.nim")
else:
cImport(srcDir/"include"/"SDL_gpu.h", recurse = false, dynlib = "SDL_gpuLPath", flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_gpu.nim")
let
FEATURE_ALL_BLEND_PRESETS* = (FEATURE_BLEND_EQUATIONS or FEATURE_BLEND_FUNC_SEPARATE) FEATURE_ALL_BLEND_PRESETS* = (FEATURE_BLEND_EQUATIONS or FEATURE_BLEND_FUNC_SEPARATE)
FEATURE_ALL_GL_FORMATS* = (FEATURE_GL_BGR or FEATURE_GL_BGRA or FEATURE_GL_ABGR) FEATURE_ALL_GL_FORMATS* = (FEATURE_GL_BGR or FEATURE_GL_BGRA or FEATURE_GL_ABGR)
FEATURE_BASIC_SHADERS* = (FEATURE_FRAGMENT_SHADER or FEATURE_VERTEX_SHADER) FEATURE_BASIC_SHADERS* = (FEATURE_FRAGMENT_SHADER or FEATURE_VERTEX_SHADER)
FEATURE_ALL_SHADERS* = (FEATURE_FRAGMENT_SHADER or FEATURE_VERTEX_SHADER or FEATURE_GEOMETRY_SHADER) FEATURE_ALL_SHADERS* = (FEATURE_FRAGMENT_SHADER or FEATURE_VERTEX_SHADER or FEATURE_GEOMETRY_SHADER)
INIT_ENABLE_VSYNC* = 0x1.uint32
INIT_DISABLE_VSYNC* = 0x2.uint32
INIT_DISABLE_DOUBLE_BUFFER* = 0x4.uint32
INIT_DISABLE_AUTO_VIRTUAL_RESOLUTION* = 0x8.uint32
INIT_REQUEST_COMPATIBILITY_PROFILE* = 0x10.uint32
INIT_USE_ROW_BY_ROW_TEXTURE_UPLOAD_FALLBACK* = 0x20.uint32
INIT_USE_COPY_TEXTURE_UPLOAD_FALLBACK* = 0x40.uint32
POINTS* = 0x0.uint32
LINES* = 0x1.uint32
LINE_LOOP* = 0x2.uint32
LINE_STRIP* = 0x3.uint32
TRIANGLES* = 0x4.uint32
TRIANGLE_STRIP* = 0x5.uint32
TRIANGLE_FAN* = 0x6.uint32
BATCH_XY* = 0x1.uint32
BATCH_XYZ* = 0x2.uint32
BATCH_ST* = 0x4.uint32
BATCH_RGB* = 0x8.uint32
BATCH_RGBA* = 0x10.uint32
BATCH_RGB8* = 0x20.uint32
BATCH_RGBA8* = 0x40.uint32
BATCH_XY_ST* = (BATCH_XY or BATCH_ST) BATCH_XY_ST* = (BATCH_XY or BATCH_ST)
BATCH_XYZ_ST* = (BATCH_XYZ or BATCH_ST) BATCH_XYZ_ST* = (BATCH_XYZ or BATCH_ST)
BATCH_XY_RGB* = (BATCH_XY or BATCH_RGB) BATCH_XY_RGB* = (BATCH_XY or BATCH_RGB)
@ -172,3 +94,35 @@ let
BATCH_XY_ST_RGBA8* = (BATCH_XY or BATCH_ST or BATCH_RGBA8) BATCH_XY_ST_RGBA8* = (BATCH_XY or BATCH_ST or BATCH_RGBA8)
BATCH_XYZ_ST_RGBA8* = (BATCH_XYZ or BATCH_ST or BATCH_RGBA8) BATCH_XYZ_ST_RGBA8* = (BATCH_XYZ or BATCH_ST or BATCH_RGBA8)
FLIP_NONE* = 0x0.uint32
FLIP_HORIZONTAL* = 0x1.uint32
FLIP_VERTICAL* = 0x2.uint32
TYPE_BYTE* = 0x1400.uint32
TYPE_UNSIGNED_BYTE* = 0x1401.uint32
TYPE_SHORT* = 0x1402.uint32
TYPE_UNSIGNED_SHORT* = 0x1403.uint32
TYPE_INT* = 0x1404.uint32
TYPE_UNSIGNED_INT* = 0x1405.uint32
TYPE_FLOAT* = 0x1406.uint32
TYPE_DOUBLE* = 0x140A.uint32
RENDERER_UNKNOWN* = 0.uint32
RENDERER_OPENGL_1_BASE* = 1.uint32
RENDERER_OPENGL_1* = 2.uint32
RENDERER_OPENGL_2* = 3.uint32
RENDERER_OPENGL_3* = 4.uint32
RENDERER_OPENGL_4* = 5.uint32
RENDERER_GLES_1* = 11.uint32
RENDERER_GLES_2* = 12.uint32
RENDERER_GLES_3* = 13.uint32
RENDERER_D3D9* = 21.uint32
RENDERER_D3D10* = 22.uint32
RENDERER_D3D11* = 23.uint32
cPluginPath(symbolPluginPath)
when defined(SDL_gpu_Static):
cImport(SDL_gpuPath, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
else:
cImport(SDL_gpuPath, recurse = false, dynlib = "SDL_gpuLPath", flags = &"-I={sdlIncludeDir} -f=ast2")

View file

@ -1,57 +1,21 @@
import macros
import os, strutils, strformat import os, strutils, strformat
import sdl2 import sdl2
import nimterop/[cimport, build, globals] import nimterop/[cimport, build]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlIncludeDir = baseDir / "sdl2" / "include"
srcDir = baseDir / "sdl2_image" srcDir = baseDir / "sdl2_image"
buildDir = srcDir / ".libs"
currentPath = getProjectPath().parentDir().sanitizePath
generatedPath = (currentPath / "generated" / "sdl2_image").replace("\\", "/")
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
defs = """
SDLimageSetVer=2.0.5
SDLimageDL
SDLimageStatic
"""
setDefines(defs.splitLines())
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"
when defined(windows):
const winBDir = SDLBuildDir.replace("C:\\", "/c/").replace("\\", "/")
const winIDir = SDLIncludeDir.replace("C:\\", "/c/").replace("\\", "/")
when defined(amd64):
const flags = &"--libdir={winBDir} --includedir={winIDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC -I{winIDir}\""
else:
const flags = &"--libdir={winBDir} --includedir={winIDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC -I{winIDir}\""
else:
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --with-pic CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
when defined(macosx):
{.passC: "-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -fPIC".}
else:
{.passC: "-fPIC -I{SDLIncludeDir}".}
getHeader( getHeader(
"SDL_image.h", "SDL_image.h",
dlurl = dlurl, dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$1.tar.gz",
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_image", altNames = "SDL2_image"
conFlags = flags,
buildTypes = [btAutoConf]
) )
static: # static:
when defined(macosx):
fixStaticFile(buildDir)
# cDebug() # cDebug()
# cDisableCaching() # cDisableCaching()
@ -62,11 +26,8 @@ cOverride:
ClearError* = "" ClearError* = ""
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
cIncludeDir(SDLIncludeDir)
{.passL: "-lwebp -lpng -ltiff -ljpeg".} when defined(SDL_image_Static):
cImport(SDL_image_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
when isDefined(SDLimageStatic):
cImport(srcDir/"SDL_image.h", recurse = false, flags = &"-f=ast2 -H", nimFile = generatedPath / "sdl2_image.nim")
else: else:
cImport(srcDir/"SDL_image.h", recurse = false, dynlib = "SDL_image_LPath", flags = &"-f=ast2 -H", nimFile = generatedPath / "sdl2_image.nim") cImport(SDL_image_Path, recurse = false, dynlib = "SDL_image_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")

View file

@ -1,49 +1,21 @@
import macros
import os, strutils, strformat import os, strutils, strformat
import sdl2 import sdl2
import nimterop/[cimport, build, globals] import nimterop/[cimport, build]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlIncludeDir = baseDir / "sdl2" / "include"
srcDir = baseDir / "sdl2_mixer" srcDir = baseDir / "sdl2_mixer"
buildDir = srcDir / "build" / ".libs"
currentPath = getProjectPath().parentDir().sanitizePath
generatedPath = (currentPath / "generated" / "sdl2_mixer").replace("\\", "/")
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
defs = """
SDLmixerSetVer=2.0.4
SDLmixerDL
SDLmixerStatic
"""
setDefines(defs.splitLines())
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"
when defined(windows):
when defined(amd64):
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
else:
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
else:
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
getHeader( getHeader(
"SDL_mixer.h", "SDL_mixer.h",
dlurl = dlurl, dlurl = "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-$1.tar.gz",
outdir = srcDir, outdir = srcDir,
conFlags = flags, altNames = "SDL2_mixer"
altNames = "SDL2_mixer",
buildTypes = [btAutoConf]
) )
static: # static:
when defined(macosx):
fixStaticFile(buildDir)
# cDebug() # cDebug()
# cDisableCaching() # cDisableCaching()
@ -55,7 +27,7 @@ cOverride:
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
when isDefined(SDLmixerStatic): when defined(SDL_mixer_Static):
cImport(srcDir/"SDL_mixer.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_mixer.nim") cImport(SDL_mixer_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
else: else:
cImport(srcDir/"SDL_mixer.h", recurse = false, dynlib = "SDL_mixer_LPath", flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_mixer.nim") cImport(SDL_mixer_Path, recurse = false, dynlib = "SDL_mixer_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")

View file

@ -1,49 +1,21 @@
import macros
import os, strutils, strformat import os, strutils, strformat
import sdl2 import sdl2
import nimterop/[cimport, build, globals] import nimterop/[cimport, build]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlIncludeDir = baseDir / "sdl2" / "include"
srcDir = baseDir / "sdl2_net" srcDir = baseDir / "sdl2_net"
buildDir = srcDir / ".libs"
currentPath = getProjectPath().parentDir().sanitizePath
generatedPath = (currentPath / "generated" / "sdl2_net").replace("\\", "/")
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
defs = """
SDLnetSetVer=2.0.1
SDLnetDL
SDLnetStatic
"""
setDefines(defs.splitLines())
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"
when defined(windows):
when defined(amd64):
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
else:
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
else:
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
getHeader( getHeader(
"SDL_net.h", "SDL_net.h",
dlurl = dlurl, dlurl = "https://www.libsdl.org/projects/SDL_net/release/SDL2_net-$1.tar.gz",
outdir = srcDir, outdir = srcDir,
conFlags = flags, altNames = "SDL2_net"
altNames = "SDL2_net",
buildTypes = [btAutoConf]
) )
static: # static:
when defined(macosx):
fixStaticFile(buildDir)
# cDebug() # cDebug()
# cDisableCaching() # cDisableCaching()
@ -53,9 +25,9 @@ cOverride:
cPluginPath(symbolPluginPath) cPluginPath(symbolPluginPath)
when isDefined(SDLnetStatic): when defined(SDL_net_Static):
cImport(srcDir / "SDL_net.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_net.nim") cImport(SDL_net_Path, recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_netsys.nim") cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")
else: else:
cImport(srcDir / "SDL_net.h", recurse = false, dynlib = "SDL_net_LPath", flags = &"-I={sdlIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_net.nim") cImport(SDL_net_Path, recurse = false, dynlib = "SDL_net_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")
cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_netsys.nim") cImport(srcDir / "SDLnetsys.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2")

View file

@ -1,51 +1,26 @@
import macros
import os, strutils, strformat import os, strutils, strformat
import sdl2 import sdl2
import nimterop/[cimport, build, globals] import nimterop/[cimport, build]
const const
baseDir = SDLCacheDir baseDir = SDLCacheDir
sdlDir = (baseDir / "sdl2").sanitizePath sdlDir = baseDir / "sdl2"
srcDir = (baseDir / "sdl2_ttf").sanitizePath sdlIncludeDir = sdlDir / "include"
buildDir = srcDir / ".libs" srcDir = baseDir / "sdl2_ttf"
currentPath = getProjectPath().parentDir().sanitizePath currentPath = currentSourcePath().parentDir().parentDir()
generatedPath = (currentPath / "generated" / "sdl2_ttf").replace("\\", "/") cmakeModPath = currentPath / "cmake" / "sdl2"
symbolPluginPath = (currentPath / "sdl2" / "cleansymbols.nim").sanitizePath symbolPluginPath = currentPath / "sdl2" / "cleansymbols.nim"
defs = """
SDLttfSetVer=2.0.15
SDLttfDL
SDLttfStatic
"""
setDefines(defs.splitLines())
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"
when defined(windows):
when defined(amd64):
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=x86_64-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
else:
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} --host=i686-w64-mingw32 CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
else:
const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir} CFLAGS=\"-fPIC -I{SDLIncludeDir}\""
getHeader( getHeader(
"SDL_ttf.h", "SDL_ttf.h",
dlurl = dlurl, dlurl = "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-$1.tar.gz",
outdir = srcDir, outdir = srcDir,
altNames = "SDL2_ttf", altNames = "SDL2_ttf",
conFlags = flags, cmakeFlags = &"-DCMAKE_C_FLAGS=-I{sdlIncludeDir} -DCMAKE_MODULE_PATH={cmakeModPath} " &
buildTypes = [btAutoConf] &"-DSDL2MAIN_LIBRARY={SDLMainLib} -DSDL2_LIBRARY={SDLDyLibPath} -DSDL2_PATH={sdlDir}"
) )
static: # static:
when defined(macosx):
fixStaticFile(buildDir)
# cDebug() # cDebug()
# cDisableCaching() # cDisableCaching()
@ -56,7 +31,7 @@ cOverride:
GetError* = "" GetError* = ""
SetError* = "" SetError* = ""
when isDefined(SDLttfStatic): when defined(SDL_ttf_Static):
cImport(srcDir / "SDL_ttf.h", recurse = false, flags = &"-I={SDLIncludeDir} -f=ast2 -H", nimFile = generatedPath / "sdl2_ttf.nim") cImport(SDL_ttf_Path, 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 -H", nimFile = generatedPath / "sdl2_ttf.nim") cImport(SDL_ttf_Path, recurse = false, dynlib = "SDL_ttf_LPath", flags = &"-I={sdlIncludeDir} -f=ast2")