diff options
| -rw-r--r-- | nimterop/build.nim | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/nimterop/build.nim b/nimterop/build.nim index 843db42..620f83e 100644 --- a/nimterop/build.nim +++ b/nimterop/build.nim @@ -1,4 +1,4 @@ -import macros, osproc, strformat, strutils, tables +import macros, osproc, sets, strformat, strutils, tables import os except findExe, sleep @@ -322,6 +322,28 @@ proc flagBuild*(base: string, flags: openArray[string]): string = for i in flags: result &= " " & base % i +proc linkLibs*(names: openArray[string], staticLink = true): string = + ## Create linker flags for specified libraries + ## + ## Prepends `lib` to the name so you only need `ssl` for `libssl`. + var + stat = if staticLink: "--static" else: "" + resSet: OrderedSet[string] + resSet.init() + + for name in names: + let + cmd = &"pkg-config --libs --silence-errors {stat} lib{name}" + libs = gorge(cmd) + for lib in libs.split(" "): + resSet.incl lib + + if staticLink: + resSet.incl "--static" + + for res in resSet: + result &= " " & res + proc configure*(path, check: string, flags = "") = ## Run the GNU `configure` command to generate all Makefiles or other ## build scripts in the specified path @@ -737,6 +759,18 @@ macro clearDefines*(): untyped = ## Clear all defines set using `setDefines()`. gDefines.clear() +macro isDefined*(def: untyped): untyped = + ## Check if `-d:xxx` is set globally or via `setDefines()` + let + sdef = gDefines.hasKey(def.strVal()) + result = newNimNode(nnkStmtList) + result.add(quote do: + when defined(`def`) or `sdef` != 0: + true + else: + false + ) + macro getHeader*(header: static[string], giturl: static[string] = "", dlurl: static[string] = "", outdir: static[string] = "", conFlags: static[string] = "", cmakeFlags: static[string] = "", makeFlags: static[string] = "", altNames: static[string] = ""): untyped = |
