Compare commits
7 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79409d27b2 | ||
|
|
96e0eea609 | ||
|
|
9ee4fe2dac | ||
|
|
a7fd97b59b | ||
|
|
a97cd56a32 | ||
|
|
a18ab8fd1d | ||
|
|
66fe786cf0 |
5 changed files with 99 additions and 14 deletions
|
|
@ -63,6 +63,12 @@ Detailed documentation is still forthcoming.
|
||||||
|
|
||||||
`cImport("header.h", recurse=true)` - import all supported definitions from header file and #includes
|
`cImport("header.h", recurse=true)` - import all supported definitions from header file and #includes
|
||||||
|
|
||||||
|
`cCompile("file.c")` - compile C/C++ implementation into binary
|
||||||
|
|
||||||
|
`cCompile("path/to/*.c")` - compile in all files matching wildcard
|
||||||
|
|
||||||
|
`cCompile("path/to/dir", "cpp")` - compile in all C++ files found recursively
|
||||||
|
|
||||||
`cAddSearchDir("XXX")` - add directory XXX to search path in calls to `cSearchPath()`
|
`cAddSearchDir("XXX")` - add directory XXX to search path in calls to `cSearchPath()`
|
||||||
|
|
||||||
`cAddStdDir("XXX")` - add standard "c" [default] or "cpp" include paths to search path
|
`cAddStdDir("XXX")` - add standard "c" [default] or "cpp" include paths to search path
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,14 @@ installDirs = @["nimterop"]
|
||||||
|
|
||||||
requires "nim >= 0.19.0", "regex >= 0.10.0", "cligen >= 0.9.17"
|
requires "nim >= 0.19.0", "regex >= 0.10.0", "cligen >= 0.9.17"
|
||||||
|
|
||||||
proc execCmd(cmd:string)=
|
proc execCmd(cmd: string) =
|
||||||
echo cmd
|
echo cmd
|
||||||
exec cmd
|
exec cmd
|
||||||
|
|
||||||
|
proc tsoloud() =
|
||||||
|
execCmd "nim c -r tests/tsoloud.nim"
|
||||||
|
execCmd "nim cpp -r tests/tsoloud.nim"
|
||||||
|
|
||||||
task test, "Test":
|
task test, "Test":
|
||||||
execCmd "nim c -r tests/tnimterop_c.nim"
|
execCmd "nim c -r tests/tnimterop_c.nim"
|
||||||
execCmd "nim cpp -r tests/tnimterop_c.nim"
|
execCmd "nim cpp -r tests/tnimterop_c.nim"
|
||||||
|
|
@ -23,3 +27,9 @@ task test, "Test":
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
execCmd "nim c -r tests/tmath.nim"
|
execCmd "nim c -r tests/tmath.nim"
|
||||||
execCmd "nim cpp -r tests/tmath.nim"
|
execCmd "nim cpp -r tests/tmath.nim"
|
||||||
|
when not defined(OSX):
|
||||||
|
when defined(Windows):
|
||||||
|
tsoloud()
|
||||||
|
else:
|
||||||
|
if not existsEnv("TRAVIS"):
|
||||||
|
tsoloud()
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import macros, os, strformat, strutils
|
import macros, os, strformat, strutils
|
||||||
|
|
||||||
const CIMPORT = 1
|
const CIMPORT {.used.} = 1
|
||||||
|
|
||||||
include "."/globals
|
include "."/globals
|
||||||
|
|
||||||
|
|
@ -23,6 +23,36 @@ proc findPath(path: string, fail = true): string =
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
proc walkDirImpl(indir, inext: string, file=true): seq[string] =
|
||||||
|
let
|
||||||
|
dir = joinPathIfRel(getProjectPath(), indir)
|
||||||
|
ext =
|
||||||
|
if inext.len != 0:
|
||||||
|
when not defined(Windows):
|
||||||
|
"-name " & inext
|
||||||
|
else:
|
||||||
|
"\\" & inext
|
||||||
|
else:
|
||||||
|
""
|
||||||
|
|
||||||
|
let
|
||||||
|
cmd =
|
||||||
|
when defined(Windows):
|
||||||
|
if file:
|
||||||
|
"cmd /c dir /s/b/a-d " & dir.replace("/", "\\") & ext
|
||||||
|
else:
|
||||||
|
"cmd /c dir /s/b/ad " & dir.replace("/", "\\")
|
||||||
|
else:
|
||||||
|
if file:
|
||||||
|
"find $1 -type f $2" % [dir, ext]
|
||||||
|
else:
|
||||||
|
"find $1 -type d" % dir
|
||||||
|
|
||||||
|
(output, ret) = gorgeEx(cmd)
|
||||||
|
|
||||||
|
if ret == 0:
|
||||||
|
result = output.splitLines()
|
||||||
|
|
||||||
proc getToast(fullpath: string, recurse: bool = false): string =
|
proc getToast(fullpath: string, recurse: bool = false): string =
|
||||||
var
|
var
|
||||||
cmd = when defined(Windows): "cmd /c " else: ""
|
cmd = when defined(Windows): "cmd /c " else: ""
|
||||||
|
|
@ -125,12 +155,11 @@ macro cAddStdDir*(mode = "c"): untyped =
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
cAddSearchDir(`sline`)
|
cAddSearchDir(`sline`)
|
||||||
|
|
||||||
macro cCompile*(path: static string): untyped =
|
macro cCompile*(path: static string, mode = "c"): untyped =
|
||||||
result = newNimNode(nnkStmtList)
|
result = newNimNode(nnkStmtList)
|
||||||
|
|
||||||
var
|
var
|
||||||
stmt = ""
|
stmt = ""
|
||||||
flags = ""
|
|
||||||
|
|
||||||
proc fcompile(file: string): string =
|
proc fcompile(file: string): string =
|
||||||
let fn = file.splitFile().name
|
let fn = file.splitFile().name
|
||||||
|
|
@ -147,22 +176,26 @@ macro cCompile*(path: static string): untyped =
|
||||||
else:
|
else:
|
||||||
return "{.compile: (\"../$#\", \"$#.o\").}" % [file.replace("\\", "/"), ufn]
|
return "{.compile: (\"../$#\", \"$#.o\").}" % [file.replace("\\", "/"), ufn]
|
||||||
|
|
||||||
proc dcompile(dir: string) =
|
proc dcompile(dir: string, ext=""): string =
|
||||||
for f in walkFiles(dir):
|
let
|
||||||
stmt &= fcompile(f) & "\n"
|
files = walkDirImpl(dir, ext)
|
||||||
|
|
||||||
|
for f in files:
|
||||||
|
if f.len != 0:
|
||||||
|
result &= fcompile(f) & "\n"
|
||||||
|
|
||||||
if path.contains("*") or path.contains("?"):
|
if path.contains("*") or path.contains("?"):
|
||||||
dcompile(path)
|
stmt &= dcompile(path)
|
||||||
else:
|
else:
|
||||||
let fpath = findPath(path)
|
let fpath = findPath(path)
|
||||||
if fileExists(fpath):
|
if fileExists(fpath):
|
||||||
stmt &= fcompile(fpath) & "\n"
|
stmt &= fcompile(fpath) & "\n"
|
||||||
elif dirExists(fpath):
|
elif dirExists(fpath):
|
||||||
if flags.contains("cpp"):
|
if mode.strVal().contains("cpp"):
|
||||||
for i in @["*.C", "*.cpp", "*.c++", "*.cc", "*.cxx"]:
|
for i in @["*.C", "*.cpp", "*.c++", "*.cc", "*.cxx"]:
|
||||||
dcompile(fpath / i)
|
stmt &= dcompile(fpath, i)
|
||||||
else:
|
else:
|
||||||
dcompile(fpath / "*.c")
|
stmt &= dcompile(fpath, "*.c")
|
||||||
|
|
||||||
result.add stmt.parseStmt()
|
result.add stmt.parseStmt()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,7 @@ proc initGrammar() =
|
||||||
pname = "a" & $count
|
pname = "a" & $count
|
||||||
count += 1
|
count += 1
|
||||||
i += 1
|
i += 1
|
||||||
if ptyp != "object":
|
pout &= &"{pname}: {getPtrType(pptr&ptyp)},"
|
||||||
pout &= &"{pname}: {getPtrType(pptr&ptyp)},"
|
|
||||||
|
|
||||||
# typedef int X
|
# typedef int X
|
||||||
# typedef X Y
|
# typedef X Y
|
||||||
|
|
@ -149,7 +148,7 @@ proc initGrammar() =
|
||||||
flen = gStateRT.data[i].val.getIdentifier()
|
flen = gStateRT.data[i].val.getIdentifier()
|
||||||
gStateRT.typeStr &= &" {name}* = {aptr}array[{flen}, {getPtrType(tptr&typ)}]\n"
|
gStateRT.typeStr &= &" {name}* = {aptr}array[{flen}, {getPtrType(tptr&typ)}]\n"
|
||||||
else:
|
else:
|
||||||
if name == typ or typ == "object":
|
if name == typ:
|
||||||
gStateRT.typeStr &= &" {name}* = object\n"
|
gStateRT.typeStr &= &" {name}* = object\n"
|
||||||
else:
|
else:
|
||||||
gStateRT.typeStr &= &" {name}* = {getPtrType(tptr&typ)}\n"
|
gStateRT.typeStr &= &" {name}* = {getPtrType(tptr&typ)}\n"
|
||||||
|
|
|
||||||
37
tests/tsoloud.nim
Normal file
37
tests/tsoloud.nim
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
import os, nimterop/[cimport, git]
|
||||||
|
|
||||||
|
gitPull("https://github.com/jarikomppa/soloud", "soloud", "include/*\nsrc/*\n")
|
||||||
|
|
||||||
|
cDebug()
|
||||||
|
|
||||||
|
const
|
||||||
|
inc = "soloud/include"
|
||||||
|
src = "soloud/src"
|
||||||
|
|
||||||
|
cIncludeDir(inc)
|
||||||
|
|
||||||
|
when defined(Linux):
|
||||||
|
{.passL: "-lpthread".}
|
||||||
|
cDefine("WITH_OSS")
|
||||||
|
cCompile(src/"backend/oss/*.cpp")
|
||||||
|
|
||||||
|
when defined(Windows):
|
||||||
|
{.passC: "-msse".}
|
||||||
|
{.passL: "-lwinmm".}
|
||||||
|
cDefine("WITH_WINMM")
|
||||||
|
cCompile(src/"backend/winmm/*.cpp")
|
||||||
|
|
||||||
|
cCompile(src/"c_api/soloud_c.cpp")
|
||||||
|
cCompile(src/"core/*.cpp")
|
||||||
|
cCompile(src/"audiosource", "cpp")
|
||||||
|
cCompile(src/"audiosource", "c")
|
||||||
|
cCompile(src/"filter/*.cpp")
|
||||||
|
|
||||||
|
cImport(inc/"soloud_c.h")
|
||||||
|
|
||||||
|
var
|
||||||
|
s = Soloud_create()
|
||||||
|
|
||||||
|
echo s.Soloud_init()
|
||||||
|
|
||||||
|
s.Soloud_destroy()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue