diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-08-15 14:41:41 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-08-15 14:41:41 -0500 |
| commit | 1e26d3e6eb9ab1036d4992476b71ac02616af4ed (patch) | |
| tree | c6850948c153ab15784f9d252e58d051cbe9d0fe | |
| parent | 1a29b9f0f8fc08e2d6eba283026320d1aef04cc2 (diff) | |
| download | nimgen-1e26d3e6eb9ab1036d4992476b71ac02616af4ed.tar.gz nimgen-1e26d3e6eb9ab1036d4992476b71ac02616af4ed.zip | |
More flexibility in compile flag
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | src/nimgen/c2nim.nim | 6 | ||||
| -rw-r--r-- | src/nimgen/gencore.nim | 19 |
3 files changed, 19 insertions, 8 deletions
@@ -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".} diff --git a/src/nimgen/c2nim.nim b/src/nimgen/c2nim.nim index 05954e6..e887b29 100644 --- a/src/nimgen/c2nim.nim +++ b/src/nimgen/c2nim.nim @@ -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 != "": diff --git a/src/nimgen/gencore.nim b/src/nimgen/gencore.nim index 4e79d04..42b82c0 100644 --- a/src/nimgen/gencore.nim +++ b/src/nimgen/gencore.nim @@ -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" |
