@@ -12,6 +12,7 @@ proc getNodeGypConfig(getNimPath: string, release: bool = false): JsonNode =
12
12
" linkflags" : [" -ldl" ]
13
13
}
14
14
15
+ # https://stackoverflow.com/questions/52605527/cmake-or-g-include-dll-libraries
15
16
const cMakeListsContent = """
16
17
cmake_minimum_required(VERSION 3.15)
17
18
cmake_policy(SET CMP0091 NEW)
@@ -25,9 +26,10 @@ include_directories(${CMAKE_JS_INC})
25
26
26
27
file(GLOB SOURCE_FILES "./denim_build/nimcache/*.c" "./denim_build/nimcache/*.h")
27
28
28
- add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
29
- set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX ".node")
30
- target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
29
+ add_library(DENIM_PKG_NAME SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
30
+ set_target_properties(DENIM_PKG_NAME PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX ".node")
31
+
32
+ DENIM_PKG_LINK_LIBS
31
33
32
34
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
33
35
# Generate node.lib
@@ -50,25 +52,23 @@ proc buildCommand*(v: Values) =
50
52
QuitFailure .quit
51
53
52
54
if not isEmptyDir (addonPathDirectory):
53
- echo addonPathDirectory
54
55
if not v.has (" -y" ):
55
- display (" Directory is not empty: " & os.splitPath (addonPathDirectory).tail, indent = 2 , br = " after " )
56
- if promptConfirm (" 👉 Are you sure you want to remove contents?" ):
56
+ displayInfo (" Directory is not empty: " & os.splitPath (addonPathDirectory).tail)
57
+ if promptConfirm (" 👉 Do you want to remove current contents? (y/N) " ):
57
58
os.removeDir (addonPathDirectory)
58
59
else :
59
60
display (" Canceled" , indent= 2 , br= " after" )
60
61
QuitFailure .quit
61
62
else :
62
63
os.removeDir (addonPathDirectory)
63
- display (" 🔥 Running Nim Compiler" , indent = 2 , br = " both " )
64
+ displayInfo (" 🔥 Running Nim Compiler" )
64
65
65
66
var args = @ [
66
67
" --nimcache:$1" ,
67
68
" --define:napibuild" ,
68
69
" --compileOnly" ,
69
- " --noMain" ,
70
+ " --noMain"
70
71
]
71
-
72
72
if v.has (" -r" ):
73
73
add args, " -d:release"
74
74
add args, " --opt:speed"
@@ -87,7 +87,7 @@ proc buildCommand*(v: Values) =
87
87
display (nimCmd.output)
88
88
var getNimPath = execCmdEx (" choosenim show path" )
89
89
if getNimPath.exitCode != 0 :
90
- display (" Can't find Nim path" )
90
+ displayError (" Can't find Nim path" )
91
91
QuitFailure .quit
92
92
discard execProcess (" ln" , args = [
93
93
" -s" ,
@@ -96,16 +96,33 @@ proc buildCommand*(v: Values) =
96
96
], options= {poStdErrToStdOut, poUsePath})
97
97
98
98
if v.has (" --cmake" ):
99
- display (" ✨ Building with CMake.js" , indent= 2 , br= " after" )
100
- writeFile (currDir / " CMakeLists.txt" , cMakeListsContent.replace (" DENIM_PKG_NAME" , entryFile.splitFile.name))
99
+ displayInfo (" ✨ Building with CMake.js" )
100
+
101
+ # cmake - add target libs, if any
102
+ var denimLinkLibs: seq [string ]
103
+ if v.has (" --libs" ):
104
+ for x in v.get (" --libs" ).getStr.split (" ," ):
105
+ denimLinkLibs.add (x)
106
+
107
+ let pkgName = entryFile.splitFile.name
108
+ writeFile (currDir / " CMakeLists.txt" ,
109
+ cMakeListsContent.multiReplace (
110
+ (" DENIM_PKG_NAME" , pkgName),
111
+ (" DENIM_PKG_LINK_LIBS" ,
112
+ if denimLinkLibs.len > 0 :
113
+ " target_link_libraries(" & pkgName & " " & denimLinkLibs.join (" " ) & " )"
114
+ else : " "
115
+ )
116
+ )
117
+ )
101
118
let cmakeCmd = execCmdEx (" cmake-js compile --runtime node --out " & " denim_build" / " build" )
102
119
if cmakeCmd.exitCode != 0 :
103
120
display (cmakeCmd.output)
104
121
QuitFailure .quit
105
122
elif v.has (" --verbose" ):
106
123
display (cmakeCmd.output)
107
124
else :
108
- display (" ✨ Building with node-gyp" , indent = 2 , br = " after " )
125
+ displayInfo (" ✨ Building with node-gyp" )
109
126
var
110
127
gyp = %* {" targets" : [getNodeGypConfig (getNimPath.output.strip, v.has (" -r" ))]}
111
128
jsonConfigPath = cachePathDirectory / entryFile.replace (" .nim" , " .json" )
@@ -133,10 +150,10 @@ proc buildCommand*(v: Values) =
133
150
binaryTargetPath = binDirectory / binName
134
151
135
152
if fileExists (binaryNodePath) == false :
136
- display (" 👉 Oups! $1 not found. Try build again" % [binName], indent = 2 )
153
+ displayError (" 👉 Oups! $1 not found. Try build again" % [binName])
137
154
QuitFailure .quit
138
155
else :
139
156
discard existsOrCreateDir (binDirectory) # ensure bin directory exists
140
157
moveFile (binaryNodePath, binaryTargetPath) # move .node addon
141
- display (" 👌 Done! Check your / bin directory" , indent = 2 , br = " after " )
142
- QuitSuccess .quit
158
+ displaySuccess (" 👌 Done! Check your ` bin` directory" )
159
+ displayInfo (binDirectory)
0 commit comments