-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathbinding.gyp
More file actions
238 lines (237 loc) · 9.68 KB
/
binding.gyp
File metadata and controls
238 lines (237 loc) · 9.68 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
{
"conditions": [
[
'OS=="mac"',
{
"variables": {
"arch%": "<!(uname -m)",
"cflags_cpp": "gnu++20",
}
},
'OS=="linux"',
{
"variables": {
"cflags_cpp": "-std=c++20 -fexceptions",
"arch%": "<!(uname -m)",
}
},
'OS=="win"',
{
"variables": {
"cflags_cpp": "/std:c++20",
"arch%": "<!(node -e \"console.log(process.arch)\")",
},
},
]
],
"variables": {
"openssl_fips": "0",
# look for include files for these versions - taking top first priority
"msodbsver%": ["msodbcsql18", "msodbcsql17"],
"ext%": ".cpp",
"homebrew%": "/opt/homebrew/lib/libodbc.a",
"unixlocalodbc%": "-l/usr/local/odbc",
"linuxodbc%": "-lodbc",
"winodbc%": "odbc32",
# pick up libodbc from somwhere - note the ms driver is loaded
# dynamicaly via odbc, no
# link dependency is added
"linkdir%": "/usr/local/lib /usr/local/ssl/lib64/ /opt/homebrew/lib /home/linuxbrew/.linuxbrew/lib/ /usr/lib /usr/lib64 .",
},
"targets": [
{
# seems this is only way to add the cpp version flag
# on ms compiler - now needed for electron
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1,
"AdditionalOptions": [
"/std:c++20",
"/D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS"
],
}
},
"target_name": "sqlserver",
"make_global_settings": [
["make_flags", "-j2"]
],
"defines": [
# "NAPI_DISABLE_CPP_EXCEPTIONS",
# Uncomment the next line to use Node-API instead of NAN
# "CONNECTION_USE_NODE_API",
"BOUNDDATUM_USE_NODE_API",
],
"variables": {
# Set the target variable only if it is not passed in by prebuild
"target%": '<!(node -e "console.log(process.versions.node)")',
# which folders are available for include eg.
# /opt/microsoft/msodbcsql18/include/ /opt/microsoft/msodbcsql17/include/
"msodbc_include_folders%": [
'<!@(node -p "'
"'<(msodbsver)'"
".split(' ')"
".map(x => ["
"'/opt/microsoft/' + x +'/include/'"
" ,"
"'/usr/local/opt/' + x + '/include/'"
" ,"
"'/usr/local/opt/' + x + '/include/' + x + '/'"
" ,"
"'/opt/homebrew/include/' + x + '/'"
" ,"
"'/home/linuxbrew/.linuxbrew/include/'"
"])"
".flatMap(y => y)"
".filter(z => require('fs').existsSync(z))"
".join(' ')"
'")'
],
# set fo
# the link folders available -L/usr/local/lib -L/usr/lib -L.
"link_path%": [
'<!@(node -p "'
"'<(linkdir)'"
".split(' ')"
".filter(x => require('fs')"
".existsSync(x))"
".map(x => '-L'+ x)"
".join(' ')"
'")'
], # set for macos based on silicon
# enumerate the cpp src files rather than name them.
"fileset%": [
'<!@(node -p "'
"['cpp/binding.cpp']"
".concat("
"require('fs').readdirSync('./cpp/src/common').map(f => 'cpp/src/common/'+f),"
"require('fs').readdirSync('./cpp/src/core').map(f => 'cpp/src/core/'+f),"
"require('fs').readdirSync('./cpp/src/js').map(f => 'cpp/src/js/'+f),"
"require('fs').readdirSync('./cpp/src/js/workers').map(f => 'cpp/src/js/workers/'+f),"
"require('fs').readdirSync('./cpp/src/js/columns').map(f => 'cpp/src/js/columns/'+f),"
"require('fs').readdirSync('./cpp/src/odbc').map(f => 'cpp/src/odbc/'+f),"
"require('fs').readdirSync('./cpp/src/utils').map(f => 'cpp/src/utils/'+f)"
")"
".filter(x => x.endsWith('<(ext)'))"
".join(' ')"
'")'
],
},
"sources": ["<!@(node -p \"'<(fileset)'" ".split(' ')" ".join(' ')\")"],
"include_dirs": [
"<!(node -p \"require('node-addon-api').include_dir\")",
"cpp",
"cpp/include",
"cpp/include/common",
"cpp/include/core",
"cpp/include/js",
"cpp/include/js/workers",
"cpp/include/js/columns",
"cpp/include/odbc",
"cpp/include/utils",
],
"defines": [
"NODE_GYP_V4",
],
"actions": [
{
"action_name": "print_variables",
"action": [
"node", "-p",
"'compiler: ' + (process.platform === 'win32' ? 'MSVC' : (process.env.CXX || 'g++')) + ' | cflags_cpp <(cflags_cpp) | arch: <(arch) | link_path: <(link_path) | msodbc_include_folders <(msodbc_include_folders) | fileset <(fileset)'",
],
"inputs": [],
"outputs": ["<!@(node -p \"'<(fileset)'.split(' ')[0]\")"],
#'outputs': ['src/ConnectionHandles.cpp']
}
],
#
# currently for electron v20+ manually set the package.json
# for node_modules/prebuild dependencies (else code will not
# compile) - need to raise PR for prebuild
# cat .\package.json | grep gyp
# "node-gyp": "^9.1.0",
# "nw-gyp": "^3.6.3",
#
# also patch nan with https://github.com/VerteDinde/nan/tree/deprecate_accessor_signature
# whilst the PR is pending - this is only needed for electron v20 and
# above
#
"conditions": [
[
'target < "13.0"',
{
"defines": [
"PRE_V13",
],
},
],
[
'OS=="win"',
{
"link_settings": {
"libraries": ["<(winodbc)"],
},
"defines": [
"UNICODE=1",
"WINDOWS_BUILD",
"_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS",
# "BOUNDDATUM_USE_NODE_API",
# Uncomment the next line to use Node-API instead of NAN
# "CONNECTION_USE_NODE_API",
],
},
],
[
'OS=="linux"',
{
"link_settings": {
"libraries": [
"<!@(node -p \"'<(link_path)'.split(' ').join(' ')\")",
"<(linuxodbc)",
],
},
"defines": ["LINUX_BUILD", "UNICODE","NAPI_CPP_EXCEPTIONS"],
"cflags_cc": ["<(cflags_cpp)"],
"cflags": ["-U_FORTIFY_SOURCE", "-fno-lto"],
"conditions": [
['<!(which gcc-10 2>/dev/null && echo 1 || echo 0)'=='1', {
"make_global_settings": [
["CC", "gcc-10"],
["CXX", "g++-10"]
]
}]
],
"include_dirs": [
"<!@(node -p \"'<(msodbc_include_folders)'.split(' ').join(' ')\")",
"/usr/include/",
],
},
],
[
'OS=="mac"',
{
"link_settings": {
"libraries": [
"<(link_path)",
"<(linuxodbc)",
#'-lodbc'
],
},
"defines": ["LINUX_BUILD", "UNICODE", "NAPI_CPP_EXCEPTIONS"],
"xcode_settings": {
"CLANG_CXX_LANGUAGE_STANDARD": "<(cflags_cpp)",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_ENABLE_CPP_RTTI": "YES",
"OTHER_CPLUSPLUSFLAGS": ["-fexceptions"]
},
"include_dirs": [
"<!@(node -p \"'<(msodbc_include_folders)'.split(' ').join(' ')\")",
"/opt/homebrew/include",
"/usr/local/include/",
],
},
],
],
}
],
}