forked from stoneface86/nappgui-nim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibnappgui.nim
77 lines (64 loc) · 2.12 KB
/
libnappgui.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{.used.}
# this module builds the nappgui library from our vendored source
import std/os
import nappgui/nappgui
template trace(msg: string) =
when defined(nappguiTrace):
static:
echo "[NAPPGUI] ", msg
const
thisDir = currentSourcePath().parentDir()
config = block:
when defined(release):
when compileoption("assertions"):
ccReleaseWithAssert
else:
ccRelease
else:
ccDebug
# root path to build the nappgui library
# if not provided, we will default to using this project's bin directory
# with an nappgui subdirectory.
nappguiRoot {.strdefine.} = thisDir.parentDir.parentDir.parentDir / "bin" / "nappgui"
# <nappguiRoot>/<config>
binDir = nappguiRoot / config.name()
# <nappguiRoot>/<config>/nimcache
nimcacheDir = binDir / "nimcache"
projFile = thisDir / "nappgui" / "nappgui.nim"
nimExe = getCurrentCompilerExe()
# The built static library will be located at
# Linux/MacOSX: <projectRoot>/bin/nappgui/<config>/libnappgui.a
# Windows: <projectRoot>/bin/nappgui/<config>/nappgui.lib
libnappgui = binDir / (
when defined(windows):
"nappgui.lib"
else:
"libnappgui.a"
)
# Build the nappgui library as a separate nim process
# this way the library only needs to built once for each config
# nappguiVersionStr is used as the cache, so it will only be rebuilt if
# this changes (ie a newer version of nappgui is vendored) or if the `-f`
# option is specified.
checkCompiler()
const traceMsgPrefix = "Building " & libnappgui
trace traceMsgPrefix
const nappguiBuildResult = gorgeEx(
quoteShellCommand([
nimExe, "c", "--nimcache:" & nimcacheDir, "--outdir:" & binDir,
"--cc:" & compiler,
"-d:nappguiConfig:" & $config.ord,
projFile
]), "", nappguiVersionStr
)
when nappguiBuildResult.exitCode == 0:
trace traceMsgPrefix & ": DONE"
else:
trace traceMsgPrefix & ": FAILED"
static:
echo "===== [NAPPGUI] Build output start =========="
echo nappguiBuildResult.output
echo "===== [NAPPGUI] Build output end =========="
{. error: "Failed to build nappgui library." .}
{. passL: libnappgui .}
useNappguiLib(config)