aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-10-08 15:19:36 -0500
committerGanesh Viswanathan <dev@genotrance.com>2019-10-08 15:19:36 -0500
commitf2a0d4b0c9ed29ad83f3cc87ad8f4f02bde34dee (patch)
tree7b6c70a836b770bb1cb57d2fb92a168be571458c
parentc21a334ec1800b20248eb4e32c6234df800e31e0 (diff)
downloadnimterop-f2a0d4b0c9ed29ad83f3cc87ad8f4f02bde34dee.tar.gz
nimterop-f2a0d4b0c9ed29ad83f3cc87ad8f4f02bde34dee.zip
Add linkLibs and isDefined
-rw-r--r--nimterop/build.nim36
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 =