forked from JCMais/node-libcurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binding.gyp
259 lines (258 loc) · 8.72 KB
/
binding.gyp
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
{
# Those variables can be overwritten when installing the package, like:
# npm install --curl-extra_link_args=true
# or if using yarn:
# npm_config_curl_extra_link_args=true yarn install
#
'variables': {
# Comma separated list
'curl_include_dirs%': '',
'curl_libraries%': '',
'curl_static_build%': 'false',
'curl_config_bin%': 'node <(module_root_dir)/scripts/curl-config.js',
'node_libcurl_no_setlocale%': 'false',
'node_libcurl_cpp_std%': '<!(node <(module_root_dir)/scripts/cpp-std.js)',
'macos_universal_build%': 'false',
},
'targets': [
{
'target_name': '<(module_name)',
'type': 'loadable_module',
'sources': [
'src/node_libcurl.cc',
'src/Easy.cc',
'src/Share.cc',
'src/Multi.cc',
'src/Curl.cc',
'src/CurlHttpPost.cc',
'src/CurlVersionInfo.cc',
'src/Http2PushFrameHeaders.cc',
],
'include_dirs' : [
"<!(node -e \"require('nan')\")",
],
'conditions': [
['node_libcurl_no_setlocale=="true"', {
'defines' : [
'NODE_LIBCURL_NO_SETLOCALE'
]
}],
['curl_include_dirs!=""', {
'include_dirs': ['<@(curl_include_dirs)']
}],
['curl_libraries!=""', {
'libraries': ['<@(curl_libraries)']
}],
# Windows is only build statically
# In the future we can add support for other build types
['OS=="win"', {
'msvs_settings': {
'VCCLCompilerTool': {
# 4244 -> nan_new.h(208): warning C4244: curl_off_t to double loss of data
# 4506 and 4838 -> about v8 inline function and narrowing
# 4068 -> Unknown pragma (mostly GCC pragmas being used)
# 4996 -> Declared wrongly Nan::Callback::Call
# 4309 -> 'static_cast': truncation of constant value on v8 header
'DisableSpecificWarnings': ['4244', '4506', '4068', '4838', '4996', '4309'],
'AdditionalOptions': [
'/std:<(node_libcurl_cpp_std)',
'/MP', #compile across multiple CPUs
],
},
'VCLinkerTool': {
'GenerateDebugInformation': 'true',
},
},
'configurations' : {
'Release': {
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': '1',
'Optimization': 2, # /O2 safe optimization
'FavorSizeOrSpeed': 1, # /Ot, favour speed over size
'InlineFunctionExpansion': 2, # /Ob2, inline anything eligible
'WholeProgramOptimization': 'true', # /GL, whole program optimization, needed for LTCG
'OmitFramePointers': 'true',
'EnableFunctionLevelLinking': 'true',
'EnableIntrinsicFunctions': 'true',
'WarnAsError': 'true',
}
}
},
'Debug': {
'msvs_settings': {
'VCCLCompilerTool': {
'WarnAsError': 'false'
}
}
}
},
'dependencies': [
'<!@(node "<(module_root_dir)/scripts/retrieve-win-deps.js")'
],
'defines' : [
'CURL_STATICLIB'
]
}, { # OS != "win"
# Use level 2 optimizations
'cflags' : [
'-O2',
],
'cflags_cc' : [
'-O2',
'-std=<(node_libcurl_cpp_std)',
'-Wno-narrowing',
],
# Allow C++ exceptions
# Disable level 3 optimizations
'cflags!': [
'-fno-exceptions',
'-O3'
],
'cflags_cc!': [
'-fno-exceptions',
'-O3'
],
'conditions': [
['curl_include_dirs==""', {
'include_dirs' : [
# '<!@(node "<(module_root_dir)/scripts/curl-config.js" --cflags | sed "s/-D.* //g" | sed s/-I//g)'
'<!(<(curl_config_bin) --prefix)/include'
],
}],
],
}],
['OS=="linux"', {
'conditions': [
['curl_static_build=="true"', {
# pretty sure cflags adds that
'defines': [
'CURL_STATICLIB',
],
'conditions': [
['curl_libraries==""', {
'libraries': [
'<!@(<(curl_config_bin) --static-libs)',
],
}]
],
}, { # do not use static linking - default
'conditions': [
['curl_libraries==""', {
'libraries': [
'-Wl,-rpath <!(<(curl_config_bin) --prefix)/lib',
'<!@(<(curl_config_bin) --libs)',
],
}]
],
}]
],
}],
['OS=="mac"', {
'conditions': [
['curl_static_build=="true"', {
# pretty sure cflags adds that
'defines': [
'CURL_STATICLIB',
],
'xcode_settings': {
'OTHER_LDFLAGS': [
# HACK: -framework CoreFoundation appears twice, but CoreFoundation is a singleton
# because it doesn't start with a -. We need to remove one of the instances of
# -framework CoreFoundation or GYP will break our args.
# This seems to be required starting with xcode 12
# original workaround from https://github.com/JCMais/node-libcurl/pull/312
'-static',
'<!@(<(curl_config_bin) --static-libs | sed "s/-framework CoreFoundation//")',
],
'LD_RUNPATH_SEARCH_PATHS': [
'<!@(<(curl_config_bin) --static-libs | node -e "console.log(require(\'fs\').readFileSync(0, \'utf-8\').split(\' \').filter(i => i.startsWith(\'-L\')).join(\' \').replace(/-L/g, \'\'))")'
],
}
}, { # do not use static linking - default
'libraries': [
'-L <!@(<(curl_config_bin) --prefix)/lib -lcurl'
],
'xcode_settings': {
'LD_RUNPATH_SEARCH_PATHS': [
'<!(<(curl_config_bin) --prefix)/lib',
'/opt/local/lib',
'/usr/local/opt/curl/lib',
'/usr/local/lib',
'/usr/lib'
],
}
}],
['macos_universal_build=="true"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS' : [
'-arch x86_64',
'-arch arm64'
],
'OTHER_CFLAGS': [
'-arch x86_64',
'-arch arm64'
],
'OTHER_LDFLAGS': [
'-arch x86_64',
'-arch arm64'
]
}
}]
],
'xcode_settings': {
'conditions': [
['curl_include_dirs==""', {
'OTHER_CPLUSPLUSFLAGS' : [
'<!(<(curl_config_bin) --prefix)/include',
],
'OTHER_CFLAGS':[
'<!(<(curl_config_bin) --prefix)/include',
],
}],
],
'OTHER_CPLUSPLUSFLAGS':[
'-std=<(node_libcurl_cpp_std)','-stdlib=libc++',
],
'OTHER_LDFLAGS':[
'-Wl,-bind_at_load',
'-stdlib=libc++'
],
'GCC_ENABLE_CPP_RTTI': 'YES',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'MACOSX_DEPLOYMENT_TARGET':'11.6',
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD':'<(node_libcurl_cpp_std)',
'OTHER_LDFLAGS': ['-stdlib=libc++'],
'WARNING_CFLAGS':[
'-Wno-c++11-narrowing',
'-Wno-constant-conversion'
],
},
}],
]
},
{
'target_name': 'action_after_build',
'type': 'none',
'dependencies': [ '<(module_name)' ],
'copies': [
{
'files': [ '<(PRODUCT_DIR)/<(module_name).node' ],
'destination': '<(module_path)'
}
],
'conditions': [['OS=="mac" and curl_static_build!="true"', {
'postbuilds': [
{
'postbuild_name': '@rpath for libcurl',
'action': [
'<(module_root_dir)/scripts/gyp-macos-postbuild.sh',
'<(module_path)/<(module_name).node'
],
},
]
}]]
}
]
}