Skip to content

Commit 3a0ce03

Browse files
Merge pull request nodegit#1953 from ianhattendorf/allow-cpp-standard-override
Allow overriding C++ standard
2 parents 75404d3 + 9da0cdb commit 3a0ce03

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

generate/templates/templates/binding.gyp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
22
"variables": {
3+
"variables": {
4+
"target%": "none",
5+
},
36
"is_electron%": "<!(node ./utils/isBuildingForElectron.js <(node_root_dir))",
47
"is_IBMi%": "<!(node -p \"os.platform() == 'aix' && os.type() == 'OS400' ? 1 : 0\")",
58
"electron_openssl_root%": "<!(node ./utils/getElectronOpenSSLRoot.js <(module_root_dir))",
69
"electron_openssl_static%": "<!(node -p \"process.platform !== 'linux' || process.env.NODEGIT_OPENSSL_STATIC_LINK === '1' ? 1 : 0\")",
10+
"cxx_version%": "<!(node ./utils/defaultCxxStandard.js <(target))",
11+
"has_cxxflags%": "<!(node -p \"process.env.CXXFLAGS ? 1 : 0\")",
712
"macOS_deployment_target": "10.11"
813
},
914

@@ -122,7 +127,7 @@
122127
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
123128
"MACOSX_DEPLOYMENT_TARGET": "<(macOS_deployment_target)",
124129
'CLANG_CXX_LIBRARY': 'libc++',
125-
'CLANG_CXX_LANGUAGE_STANDARD':'c++14',
130+
'CLANG_CXX_LANGUAGE_STANDARD':'c++<(cxx_version)',
126131

127132
"WARNING_CFLAGS": [
128133
"-Wno-unused-variable",
@@ -150,6 +155,7 @@
150155
"msvs_settings": {
151156
"VCCLCompilerTool": {
152157
"AdditionalOptions": [
158+
"/std:c++<(cxx_version)",
153159
"/EHsc"
154160
]
155161
},
@@ -172,10 +178,12 @@
172178
]
173179
}],
174180
["OS=='linux' or OS.endswith('bsd') or <(is_IBMi) == 1", {
175-
"cflags": [
176-
"-std=c++14"
177-
],
178181
"conditions": [
182+
["<(has_cxxflags) == 0", {
183+
"cflags_cc": [
184+
"-std=c++<(cxx_version)"
185+
],
186+
}],
179187
["<(is_electron) == 1 and <(electron_openssl_static) == 1", {
180188
"include_dirs": [
181189
"<(electron_openssl_root)/include"

utils/defaultCxxStandard.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const targetSpecified = process.argv[2] !== 'none';
2+
3+
let isNode18OrElectron20AndUp = false;
4+
if (targetSpecified) {
5+
// Assume electron if target is specified.
6+
// If building node 18 / 19 via target, will need to specify C++ standard manually
7+
const majorVersion = process.argv[2].split('.')[0];
8+
isNode18OrElectron20AndUp = majorVersion >= 20;
9+
} else {
10+
// Node 18 === 108
11+
isNode18OrElectron20AndUp = Number.parseInt(process.versions.modules) >= 108;
12+
}
13+
14+
const defaultCxxStandard = isNode18OrElectron20AndUp
15+
? '17'
16+
: '14';
17+
18+
process.stdout.write(defaultCxxStandard);

0 commit comments

Comments
 (0)