@dry-software/cmake-js 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +402 -0
- package/bin/cmake-js +343 -0
- package/changelog.md +225 -0
- package/lib/appCMakeJSConfig.js +58 -0
- package/lib/buildSystem.js +123 -0
- package/lib/cMake.js +362 -0
- package/lib/cmLog.js +61 -0
- package/lib/cpp/win_delay_load_hook.cc +52 -0
- package/lib/dist.js +176 -0
- package/lib/downloader.js +92 -0
- package/lib/environment.js +97 -0
- package/lib/import/Find-VisualStudio.cs +250 -0
- package/lib/import/LICENSE +24 -0
- package/lib/import/README +6 -0
- package/lib/import/find-visualstudio.js +439 -0
- package/lib/import/util.js +70 -0
- package/lib/index.js +12 -0
- package/lib/locateNAN.js +63 -0
- package/lib/locateNodeApi.js +18 -0
- package/lib/npmConfig.js +31 -0
- package/lib/processHelpers.js +53 -0
- package/lib/runtimePaths.js +95 -0
- package/lib/targetOptions.js +33 -0
- package/lib/toolset.js +224 -0
- package/package.json +76 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const semver = require('semver')
|
|
4
|
+
|
|
5
|
+
const NODE_MIRROR = process.env.NVM_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist'
|
|
6
|
+
const ELECTRON_MIRROR = process.env.ELECTRON_MIRROR || 'https://artifacts.electronjs.org/headers/dist'
|
|
7
|
+
|
|
8
|
+
const runtimePaths = {
|
|
9
|
+
node: function (targetOptions) {
|
|
10
|
+
if (semver.lt(targetOptions.runtimeVersion, '4.0.0')) {
|
|
11
|
+
return {
|
|
12
|
+
externalPath: NODE_MIRROR + '/v' + targetOptions.runtimeVersion + '/',
|
|
13
|
+
winLibs: [
|
|
14
|
+
{
|
|
15
|
+
dir: targetOptions.isX64 ? 'x64' : '',
|
|
16
|
+
name: targetOptions.runtime + '.lib',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
tarPath: targetOptions.runtime + '-v' + targetOptions.runtimeVersion + '.tar.gz',
|
|
20
|
+
headerOnly: false,
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
return {
|
|
24
|
+
externalPath: NODE_MIRROR + '/v' + targetOptions.runtimeVersion + '/',
|
|
25
|
+
winLibs: [
|
|
26
|
+
{
|
|
27
|
+
dir: targetOptions.isArm64 ? 'arm64' : targetOptions.isX64 ? 'win-x64' : 'win-x86',
|
|
28
|
+
name: targetOptions.runtime + '.lib',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
tarPath: targetOptions.runtime + '-v' + targetOptions.runtimeVersion + '-headers.tar.gz',
|
|
32
|
+
headerOnly: true,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
nw: function (targetOptions) {
|
|
37
|
+
if (semver.gte(targetOptions.runtimeVersion, '0.13.0')) {
|
|
38
|
+
return {
|
|
39
|
+
externalPath: 'https://node-webkit.s3.amazonaws.com/v' + targetOptions.runtimeVersion + '/',
|
|
40
|
+
winLibs: [
|
|
41
|
+
{
|
|
42
|
+
dir: targetOptions.isX64 ? 'x64' : '',
|
|
43
|
+
name: targetOptions.runtime + '.lib',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
dir: targetOptions.isX64 ? 'x64' : '',
|
|
47
|
+
name: 'node.lib',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
tarPath: 'nw-headers-v' + targetOptions.runtimeVersion + '.tar.gz',
|
|
51
|
+
headerOnly: false,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
externalPath: 'https://node-webkit.s3.amazonaws.com/v' + targetOptions.runtimeVersion + '/',
|
|
56
|
+
winLibs: [
|
|
57
|
+
{
|
|
58
|
+
dir: targetOptions.isX64 ? 'x64' : '',
|
|
59
|
+
name: targetOptions.runtime + '.lib',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
tarPath: 'nw-headers-v' + targetOptions.runtimeVersion + '.tar.gz',
|
|
63
|
+
headerOnly: false,
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
electron: function (targetOptions) {
|
|
67
|
+
return {
|
|
68
|
+
externalPath: ELECTRON_MIRROR + '/v' + targetOptions.runtimeVersion + '/',
|
|
69
|
+
winLibs: [
|
|
70
|
+
{
|
|
71
|
+
dir: targetOptions.isX64 ? 'x64' : '',
|
|
72
|
+
name: 'node.lib',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
tarPath: 'node' + '-v' + targetOptions.runtimeVersion + '.tar.gz',
|
|
76
|
+
headerOnly: semver.gte(targetOptions.runtimeVersion, '4.0.0-alpha'),
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
get: function (targetOptions) {
|
|
80
|
+
assert(targetOptions && typeof targetOptions === 'object')
|
|
81
|
+
|
|
82
|
+
const runtime = targetOptions.runtime
|
|
83
|
+
const func = runtimePaths[runtime]
|
|
84
|
+
let paths
|
|
85
|
+
if (typeof func === 'function') {
|
|
86
|
+
paths = func(targetOptions)
|
|
87
|
+
if (paths && typeof paths === 'object') {
|
|
88
|
+
return paths
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
throw new Error('Unknown runtime: ' + runtime)
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = runtimePaths
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const environment = require('./environment')
|
|
4
|
+
|
|
5
|
+
class TargetOptions {
|
|
6
|
+
get arch() {
|
|
7
|
+
return this.options.arch || environment.arch
|
|
8
|
+
}
|
|
9
|
+
get isX86() {
|
|
10
|
+
return this.arch === 'ia32' || this.arch === 'x86'
|
|
11
|
+
}
|
|
12
|
+
get isX64() {
|
|
13
|
+
return this.arch === 'x64'
|
|
14
|
+
}
|
|
15
|
+
get isArm() {
|
|
16
|
+
return this.arch === 'arm'
|
|
17
|
+
}
|
|
18
|
+
get isArm64() {
|
|
19
|
+
return this.arch === 'arm64'
|
|
20
|
+
}
|
|
21
|
+
get runtime() {
|
|
22
|
+
return this.options.runtime || environment.runtime
|
|
23
|
+
}
|
|
24
|
+
get runtimeVersion() {
|
|
25
|
+
return this.options.runtimeVersion || environment.runtimeVersion
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.options = options || {}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = TargetOptions
|
package/lib/toolset.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const TargetOptions = require('./targetOptions')
|
|
3
|
+
const environment = require('./environment')
|
|
4
|
+
const assert = require('assert')
|
|
5
|
+
const CMLog = require('./cmLog')
|
|
6
|
+
const { findVisualStudio } = environment.isWin ? require('./import/find-visualstudio') : {}
|
|
7
|
+
|
|
8
|
+
class Toolset {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options || {}
|
|
11
|
+
this.targetOptions = new TargetOptions(this.options)
|
|
12
|
+
this.generator = options.generator
|
|
13
|
+
this.toolset = options.toolset
|
|
14
|
+
this.platform = options.platform
|
|
15
|
+
this.target = options.target
|
|
16
|
+
this.cCompilerPath = options.cCompilerPath
|
|
17
|
+
this.cppCompilerPath = options.cppCompilerPath
|
|
18
|
+
this.compilerFlags = []
|
|
19
|
+
this.linkerFlags = []
|
|
20
|
+
this.makePath = null
|
|
21
|
+
this.log = new CMLog(this.options)
|
|
22
|
+
this._initialized = false
|
|
23
|
+
}
|
|
24
|
+
async initialize(install) {
|
|
25
|
+
if (!this._initialized) {
|
|
26
|
+
if (environment.isWin) {
|
|
27
|
+
await this.initializeWin(install)
|
|
28
|
+
} else {
|
|
29
|
+
this.initializePosix(install)
|
|
30
|
+
}
|
|
31
|
+
this._initialized = true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
initializePosix(install) {
|
|
35
|
+
if (!this.cCompilerPath || !this.cppCompilerPath) {
|
|
36
|
+
// 1: Compiler
|
|
37
|
+
if (!environment.isGPPAvailable && !environment.isClangAvailable) {
|
|
38
|
+
if (environment.isOSX) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"C++ Compiler toolset is not available. Install Xcode Commandline Tools from Apple Dev Center, or install Clang with homebrew by invoking: 'brew install llvm --with-clang --with-asan'.",
|
|
41
|
+
)
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.",
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.options.preferClang && environment.isClangAvailable) {
|
|
50
|
+
if (install) {
|
|
51
|
+
this.log.info('TOOL', 'Using clang++ compiler, because preferClang option is set, and clang++ is available.')
|
|
52
|
+
}
|
|
53
|
+
this.cppCompilerPath = this.cppCompilerPath || 'clang++'
|
|
54
|
+
this.cCompilerPath = this.cCompilerPath || 'clang'
|
|
55
|
+
} else if (this.options.preferGnu && environment.isGPPAvailable) {
|
|
56
|
+
if (install) {
|
|
57
|
+
this.log.info('TOOL', 'Using g++ compiler, because preferGnu option is set, and g++ is available.')
|
|
58
|
+
}
|
|
59
|
+
this.cppCompilerPath = this.cppCompilerPath || 'g++'
|
|
60
|
+
this.cCompilerPath = this.cCompilerPath || 'gcc'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// if it's already set because of options...
|
|
64
|
+
if (this.generator) {
|
|
65
|
+
if (install) {
|
|
66
|
+
this.log.info('TOOL', 'Using ' + this.generator + ' generator, as specified from commandline.')
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 2: Generator
|
|
71
|
+
else if (environment.isOSX) {
|
|
72
|
+
if (this.options.preferXcode) {
|
|
73
|
+
if (install) {
|
|
74
|
+
this.log.info('TOOL', 'Using Xcode generator, because preferXcode option is set.')
|
|
75
|
+
}
|
|
76
|
+
this.generator = 'Xcode'
|
|
77
|
+
} else if (this.options.preferMake && environment.isMakeAvailable) {
|
|
78
|
+
if (install) {
|
|
79
|
+
this.log.info(
|
|
80
|
+
'TOOL',
|
|
81
|
+
'Using Unix Makefiles generator, because preferMake option is set, and make is available.',
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
this.generator = 'Unix Makefiles'
|
|
85
|
+
} else if (environment.isNinjaAvailable) {
|
|
86
|
+
if (install) {
|
|
87
|
+
this.log.info('TOOL', 'Using Ninja generator, because ninja is available.')
|
|
88
|
+
}
|
|
89
|
+
this.generator = 'Ninja'
|
|
90
|
+
} else {
|
|
91
|
+
if (install) {
|
|
92
|
+
this.log.info('TOOL', 'Using Unix Makefiles generator.')
|
|
93
|
+
}
|
|
94
|
+
this.generator = 'Unix Makefiles'
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
if (this.options.preferMake && environment.isMakeAvailable) {
|
|
98
|
+
if (install) {
|
|
99
|
+
this.log.info(
|
|
100
|
+
'TOOL',
|
|
101
|
+
'Using Unix Makefiles generator, because preferMake option is set, and make is available.',
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
this.generator = 'Unix Makefiles'
|
|
105
|
+
} else if (environment.isNinjaAvailable) {
|
|
106
|
+
if (install) {
|
|
107
|
+
this.log.info('TOOL', 'Using Ninja generator, because ninja is available.')
|
|
108
|
+
}
|
|
109
|
+
this.generator = 'Ninja'
|
|
110
|
+
} else {
|
|
111
|
+
if (install) {
|
|
112
|
+
this.log.info('TOOL', 'Using Unix Makefiles generator.')
|
|
113
|
+
}
|
|
114
|
+
this.generator = 'Unix Makefiles'
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 3: Flags
|
|
119
|
+
if (environment.isOSX) {
|
|
120
|
+
if (install) {
|
|
121
|
+
this.log.verbose('TOOL', 'Setting default OSX compiler flags.')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this.compilerFlags.push('-D_DARWIN_USE_64_BIT_INODE=1')
|
|
125
|
+
this.compilerFlags.push('-D_LARGEFILE_SOURCE')
|
|
126
|
+
this.compilerFlags.push('-D_FILE_OFFSET_BITS=64')
|
|
127
|
+
this.linkerFlags.push('-undefined dynamic_lookup')
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.compilerFlags.push('-DBUILDING_NODE_EXTENSION')
|
|
131
|
+
|
|
132
|
+
// 4: Build target
|
|
133
|
+
if (this.options.target) {
|
|
134
|
+
this.log.info('TOOL', 'Building only the ' + this.options.target + ' target, as specified from the command line.')
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async initializeWin(install) {
|
|
138
|
+
if (!this.generator) {
|
|
139
|
+
const foundVsInfo = await this._getTopSupportedVisualStudioGenerator()
|
|
140
|
+
if (foundVsInfo) {
|
|
141
|
+
if (install) {
|
|
142
|
+
this.log.info('TOOL', `Using ${foundVsInfo.generator} generator.`)
|
|
143
|
+
}
|
|
144
|
+
this.generator = foundVsInfo.generator
|
|
145
|
+
|
|
146
|
+
const isAboveVS16 = foundVsInfo.versionMajor >= 16
|
|
147
|
+
|
|
148
|
+
// The CMake Visual Studio Generator does not support the Win64 or ARM suffix on
|
|
149
|
+
// the generator name. Instead the generator platform must be set explicitly via
|
|
150
|
+
// the platform parameter
|
|
151
|
+
if (!this.platform && isAboveVS16) {
|
|
152
|
+
switch (this.targetOptions.arch) {
|
|
153
|
+
case 'ia32':
|
|
154
|
+
case 'x86':
|
|
155
|
+
this.platform = 'Win32'
|
|
156
|
+
break
|
|
157
|
+
case 'x64':
|
|
158
|
+
this.platform = 'x64'
|
|
159
|
+
break
|
|
160
|
+
case 'arm':
|
|
161
|
+
this.platform = 'ARM'
|
|
162
|
+
break
|
|
163
|
+
case 'arm64':
|
|
164
|
+
this.platform = 'ARM64'
|
|
165
|
+
break
|
|
166
|
+
default:
|
|
167
|
+
this.log.warn('TOOL', 'Unknown NodeJS architecture: ' + this.targetOptions.arch)
|
|
168
|
+
break
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
throw new Error('There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.')
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
// if it's already set because of options...
|
|
176
|
+
if (install) {
|
|
177
|
+
this.log.info('TOOL', 'Using ' + this.options.generator + ' generator, as specified from commandline.')
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.linkerFlags.push('/DELAYLOAD:NODE.EXE')
|
|
182
|
+
|
|
183
|
+
if (this.targetOptions.isX86) {
|
|
184
|
+
if (install) {
|
|
185
|
+
this.log.verbose('TOOL', 'Setting SAFESEH:NO linker flag.')
|
|
186
|
+
}
|
|
187
|
+
this.linkerFlags.push('/SAFESEH:NO')
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async _getTopSupportedVisualStudioGenerator() {
|
|
191
|
+
const CMake = require('./cMake')
|
|
192
|
+
assert(environment.isWin)
|
|
193
|
+
|
|
194
|
+
const selectedVs = await findVisualStudio(environment.runtimeVersion, this.options.msvsVersion)
|
|
195
|
+
if (!selectedVs) return null
|
|
196
|
+
|
|
197
|
+
const list = await CMake.getGenerators(this.options, this.log)
|
|
198
|
+
for (const gen of list) {
|
|
199
|
+
const found = gen.startsWith(`Visual Studio ${selectedVs.versionMajor}`)
|
|
200
|
+
if (!found) {
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// unlike previous versions "Visual Studio 16 2019" and onwards don't end with arch name
|
|
205
|
+
const isAboveVS16 = selectedVs.versionMajor >= 16
|
|
206
|
+
if (!isAboveVS16) {
|
|
207
|
+
const is64Bit = gen.endsWith('Win64')
|
|
208
|
+
if ((this.targetOptions.isX86 && is64Bit) || (this.targetOptions.isX64 && !is64Bit)) {
|
|
209
|
+
continue
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
...selectedVs,
|
|
215
|
+
generator: gen,
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Nothing matched
|
|
220
|
+
return null
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
module.exports = Toolset
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dry-software/cmake-js",
|
|
3
|
+
"description": "CMake.js - a Node.js native addon build tool",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"native",
|
|
7
|
+
"addon",
|
|
8
|
+
"module",
|
|
9
|
+
"c",
|
|
10
|
+
"c++",
|
|
11
|
+
"bindings",
|
|
12
|
+
"build",
|
|
13
|
+
"buildtools",
|
|
14
|
+
"cmake",
|
|
15
|
+
"nw.js",
|
|
16
|
+
"electron",
|
|
17
|
+
"boost",
|
|
18
|
+
"nan",
|
|
19
|
+
"napi",
|
|
20
|
+
"node-api",
|
|
21
|
+
"node-addon-api"
|
|
22
|
+
],
|
|
23
|
+
"main": "lib",
|
|
24
|
+
"version": "7.3.0",
|
|
25
|
+
"author": "Gábor Mező aka unbornchikken",
|
|
26
|
+
"maintainers": [
|
|
27
|
+
{
|
|
28
|
+
"name": "dry Software UG (haftungsbeschränkt)",
|
|
29
|
+
"email": "info@dry.software",
|
|
30
|
+
"url": "https://dry.software"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git://github.com/cmake-js/cmake-js.git"
|
|
36
|
+
},
|
|
37
|
+
"bin": {
|
|
38
|
+
"cmake-js": "./bin/cmake-js"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">= 14.15.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"axios": "^1.6.5",
|
|
45
|
+
"debug": "^4",
|
|
46
|
+
"fs-extra": "^11.2.0",
|
|
47
|
+
"memory-stream": "^1.0.0",
|
|
48
|
+
"node-api-headers": "^1.1.0",
|
|
49
|
+
"npmlog": "^6.0.2",
|
|
50
|
+
"rc": "^1.2.7",
|
|
51
|
+
"semver": "^7.5.4",
|
|
52
|
+
"tar": "^6.2.0",
|
|
53
|
+
"url-join": "^4.0.1",
|
|
54
|
+
"which": "^2.0.2",
|
|
55
|
+
"yargs": "^17.7.2"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"eslint": "^8.56.0",
|
|
59
|
+
"eslint-config-prettier": "^9.1.0",
|
|
60
|
+
"mocha": "*",
|
|
61
|
+
"nan": "^2.18.0",
|
|
62
|
+
"node-addon-api": "^6.1.0",
|
|
63
|
+
"prettier": "^3.2.2"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"test": "mocha tests",
|
|
67
|
+
"lint": "eslint lib bin/cmake-js tests"
|
|
68
|
+
},
|
|
69
|
+
"files": [
|
|
70
|
+
"lib",
|
|
71
|
+
"bin",
|
|
72
|
+
"*.md",
|
|
73
|
+
"bindings.js",
|
|
74
|
+
"bindings.d.ts"
|
|
75
|
+
]
|
|
76
|
+
}
|