More flexibility in compile flag

This commit is contained in:
Ganesh Viswanathan 2018-08-15 14:41:41 -05:00
commit 1e26d3e6eb
3 changed files with 19 additions and 8 deletions

View file

@ -167,7 +167,7 @@ The following keys apply to library source code and help with generating the .ni
Multiple entries for the all following keys are possible by appending any .string to the key. E.g. dynlib.win, compile.dir
```compile``` = file or dir of files of source code to {.compile.} into generated .nim
```compile``` = file or dir of files of source code to {.compile.} into generated .nim. If directory, picks *.c if C mode and *.cxx, *.cpp, *.cc, *.c++ and *.C for cpp mode. Dir can also include wildcards. e.g. compile = """dir/A*.cxx"""
```pragma``` = pragmas to define in generated .nim file. E.g. pragma = "passL: \"-lssl\"" => {.passL: "-lssl".}

View file

@ -29,7 +29,7 @@ proc c2nim*(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
outlib = ""
outpragma = ""
passC = "import ospaths, strutils\n"
passC = "import strutils\n"
passC &= """const sourcePath = currentSourcePath().split({'\\', '/'})[0..^2].join("/")""" & "\n"
@ -102,9 +102,9 @@ proc c2nim*(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
for cpl in c2nimConfig.compile:
let fcpl = search(cpl)
if getFileInfo(fcpl).kind == pcFile:
prepend(outfile, compile(file=fcpl))
prepend(outfile, compile(c2nimConfig.flags, file=fcpl))
else:
prepend(outfile, compile(dir=fcpl))
prepend(outfile, compile(c2nimConfig.flags, dir=fcpl))
# Add any pragmas
if outpragma != "":

View file

@ -17,15 +17,26 @@ proc addEnv*(str: string): string =
return newStr
proc compile*(dir="", file=""): string =
proc compile*(flags: string, dir="", file=""): string =
var data = ""
proc fcompile(file: string): string =
return "{.compile: \"$#\".}" % file.replace("\\", "/")
var data = ""
if dir != "" and dirExists(dir):
for f in walkFiles(dir / "*.c"):
proc dcompile(dir: string) =
for f in walkFiles(dir):
data &= fcompile(f) & "\n"
if dir != "":
if dir.contains("*") or dir.contains("?"):
dcompile(dir)
elif dirExists(dir):
if flags.contains("cpp"):
for i in @["*.C", "*.cpp", "*.c++", "*.cc", "*.cxx"]:
dcompile(dir / i)
else:
dcompile(dir / "*.c")
if file != "" and fileExists(file):
data &= fcompile(file) & "\n"