@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/bin/cmake-js ADDED
@@ -0,0 +1,343 @@
1
+ #!/usr/bin/env node
2
+ 'use strict'
3
+
4
+ const log = require('npmlog')
5
+ const BuildSystem = require('../').BuildSystem
6
+ const util = require('util')
7
+ const version = require('../package').version
8
+ const logLevels = ['silly', 'verbose', 'info', 'http', 'warn', 'error']
9
+
10
+ const npmConfigData = require('rc')('npm')
11
+ for (const [key, value] of Object.entries(npmConfigData)) {
12
+ if (key.startsWith('cmake_js_')) {
13
+ const option = key.substr(9)
14
+ if (option.length === 1) {
15
+ process.argv.push('-' + option)
16
+ } else {
17
+ process.argv.push('--' + option)
18
+ }
19
+ if (value) {
20
+ process.argv.push(value)
21
+ }
22
+ }
23
+ }
24
+
25
+ const yargs = require('yargs')
26
+ .usage('CMake.js ' + version + '\n\nUsage: $0 [<command>] [options]')
27
+ .version(version)
28
+ .command('install', 'Install Node.js distribution files if needed')
29
+ .command('configure', 'Configure CMake project')
30
+ .command('print-configure', 'Print the configuration command')
31
+ .command('print-cmakejs-src', 'Print the value of the CMAKE_JS_SRC variable')
32
+ .command('print-cmakejs-include', 'Print the value of the CMAKE_JS_INC variable')
33
+ .command('print-cmakejs-lib', 'Print the value of the CMAKE_JS_LIB variable')
34
+ .command('build', 'Build the project (will configure first if required)')
35
+ .command('print-build', 'Print the build command')
36
+ .command('clean', 'Clean the project directory')
37
+ .command('print-clean', 'Print the clean command')
38
+ .command('reconfigure', 'Clean the project directory then configure the project')
39
+ .command('rebuild', 'Clean the project directory then build the project')
40
+ .command('compile', 'Build the project, and if build fails, try a full rebuild')
41
+ .options({
42
+ h: {
43
+ alias: 'help',
44
+ demand: false,
45
+ describe: 'show this screen',
46
+ type: 'boolean',
47
+ },
48
+ l: {
49
+ alias: 'log-level',
50
+ demand: false,
51
+ describe: 'set log level (' + logLevels.join(', ') + '), default is info',
52
+ type: 'string',
53
+ },
54
+ d: {
55
+ alias: 'directory',
56
+ demand: false,
57
+ describe: "specify CMake project's directory (where CMakeLists.txt located)",
58
+ type: 'string',
59
+ },
60
+ D: {
61
+ alias: 'debug',
62
+ demand: false,
63
+ describe: 'build debug configuration',
64
+ type: 'boolean',
65
+ },
66
+ B: {
67
+ alias: 'config',
68
+ demand: false,
69
+ describe: "specify build configuration (Debug, RelWithDebInfo, Release), will ignore '--debug' if specified",
70
+ type: 'string',
71
+ },
72
+ c: {
73
+ alias: 'cmake-path',
74
+ demand: false,
75
+ describe: 'path of CMake executable',
76
+ type: 'string',
77
+ },
78
+ m: {
79
+ alias: 'prefer-make',
80
+ demand: false,
81
+ describe: 'use Unix Makefiles even if Ninja is available (Posix)',
82
+ type: 'boolean',
83
+ },
84
+ x: {
85
+ alias: 'prefer-xcode',
86
+ demand: false,
87
+ describe: 'use Xcode instead of Unix Makefiles',
88
+ type: 'boolean',
89
+ },
90
+ g: {
91
+ alias: 'prefer-gnu',
92
+ demand: false,
93
+ describe: 'use GNU compiler instead of default CMake compiler, if available (Posix)',
94
+ type: 'boolean',
95
+ },
96
+ G: {
97
+ alias: 'generator',
98
+ demand: false,
99
+ describe: 'use specified generator',
100
+ type: 'string',
101
+ },
102
+ t: {
103
+ alias: 'toolset',
104
+ demand: false,
105
+ describe: 'use specified toolset',
106
+ type: 'string',
107
+ },
108
+ A: {
109
+ alias: 'platform',
110
+ demand: false,
111
+ describe: 'use specified platform name',
112
+ type: 'string',
113
+ },
114
+ T: {
115
+ alias: 'target',
116
+ demand: false,
117
+ describe: 'only build the specified target',
118
+ type: 'string',
119
+ },
120
+ C: {
121
+ alias: 'prefer-clang',
122
+ demand: false,
123
+ describe: 'use Clang compiler instead of default CMake compiler, if available (Posix)',
124
+ type: 'boolean',
125
+ },
126
+ cc: {
127
+ demand: false,
128
+ describe: 'use the specified C compiler',
129
+ type: 'string',
130
+ },
131
+ cxx: {
132
+ demand: false,
133
+ describe: 'use the specified C++ compiler',
134
+ type: 'string',
135
+ },
136
+ r: {
137
+ alias: 'runtime',
138
+ demand: false,
139
+ describe: 'the runtime to use',
140
+ type: 'string',
141
+ },
142
+ v: {
143
+ alias: 'runtime-version',
144
+ demand: false,
145
+ describe: 'the runtime version to use',
146
+ type: 'string',
147
+ },
148
+ a: {
149
+ alias: 'arch',
150
+ demand: false,
151
+ describe: 'the architecture to build in',
152
+ type: 'string',
153
+ },
154
+ p: {
155
+ alias: 'parallel',
156
+ demand: false,
157
+ describe: 'the number of threads cmake can use',
158
+ type: 'number',
159
+ },
160
+ CD: {
161
+ demand: false,
162
+ describe: 'Custom argument passed to CMake in format: -D<your-arg-here>',
163
+ type: 'string',
164
+ },
165
+ i: {
166
+ alias: 'silent',
167
+ describe: 'Prevents CMake.js to print to the stdio',
168
+ type: 'boolean',
169
+ },
170
+ O: {
171
+ alias: 'out',
172
+ describe: 'Specify the output directory to compile to, default is projectRoot/build',
173
+ type: 'string',
174
+ },
175
+ })
176
+ const argv = yargs.argv
177
+
178
+ // If help, then print and exit:
179
+
180
+ if (argv.h) {
181
+ console.info(yargs.help())
182
+ process.exit(0)
183
+ }
184
+
185
+ // Setup log level:
186
+
187
+ if (argv.l && logLevels.includes(argv.l)) {
188
+ log.level = argv.l
189
+ log.resume()
190
+ }
191
+
192
+ log.silly('CON', 'argv:')
193
+ log.silly('CON', util.inspect(argv))
194
+
195
+ log.verbose('CON', 'Parsing arguments')
196
+
197
+ // Extract custom cMake options
198
+ const customOptions = {}
199
+ for (const arg of process.argv) {
200
+ if (arg.startsWith('--CD')) {
201
+ const separator = arg.indexOf('=')
202
+ if (separator < 5) continue
203
+ const key = arg.substring(4, separator)
204
+ const value = arg.substring(separator + 1)
205
+ if (!value) continue
206
+ customOptions[key] = value
207
+ }
208
+ }
209
+
210
+ const options = {
211
+ directory: argv.directory || null,
212
+ debug: argv.debug,
213
+ cmakePath: argv.c || null,
214
+ generator: argv.G,
215
+ toolset: argv.t,
216
+ platform: argv.A,
217
+ target: argv.T,
218
+ preferMake: argv.m,
219
+ preferXcode: argv.x,
220
+ preferGnu: argv.g,
221
+ preferClang: argv.C,
222
+ cCompilerPath: argv.cc,
223
+ cppCompilerPath: argv.cxx,
224
+ runtime: argv.r,
225
+ runtimeVersion: argv.v,
226
+ arch: argv.a,
227
+ cMakeOptions: customOptions,
228
+ silent: argv.i,
229
+ out: argv.O,
230
+ config: argv.B,
231
+ parallel: argv.p,
232
+ extraCMakeArgs: argv._.slice(1),
233
+ }
234
+
235
+ log.verbose('CON', 'options:')
236
+ log.verbose('CON', util.inspect(options))
237
+
238
+ const command = argv._[0] || 'build'
239
+
240
+ log.verbose('CON', 'Running command: ' + command)
241
+
242
+ const buildSystem = new BuildSystem(options)
243
+
244
+ function ifCommand(c, f) {
245
+ if (c === command) {
246
+ f()
247
+ return true
248
+ }
249
+ return false
250
+ }
251
+
252
+ function exitOnError(promise) {
253
+ promise.catch(function () {
254
+ process.exit(1)
255
+ })
256
+ }
257
+
258
+ function install() {
259
+ exitOnError(buildSystem.install())
260
+ }
261
+ function configure() {
262
+ exitOnError(buildSystem.configure())
263
+ }
264
+ function printConfigure() {
265
+ exitOnError(
266
+ buildSystem.getConfigureCommand().then(function (command) {
267
+ console.info(command)
268
+ }),
269
+ )
270
+ }
271
+ function printCmakeJsLib() {
272
+ exitOnError(
273
+ buildSystem.getCmakeJsLibString().then(function (command) {
274
+ console.info(command)
275
+ }),
276
+ )
277
+ }
278
+ function printCmakeJsInclude() {
279
+ exitOnError(
280
+ buildSystem.getCmakeJsIncludeString().then(function (command) {
281
+ console.info(command)
282
+ }),
283
+ )
284
+ }
285
+ function printCmakeJsSrc() {
286
+ exitOnError(
287
+ buildSystem.getCmakeJsSrcString().then(function (command) {
288
+ console.info(command)
289
+ }),
290
+ )
291
+ }
292
+ function build() {
293
+ exitOnError(buildSystem.build())
294
+ }
295
+ function printBuild() {
296
+ exitOnError(
297
+ buildSystem.getBuildCommand().then(function (command) {
298
+ console.info(command)
299
+ }),
300
+ )
301
+ }
302
+ function clean() {
303
+ exitOnError(buildSystem.clean())
304
+ }
305
+ function printClean() {
306
+ exitOnError(
307
+ buildSystem.getCleanCommand().then(function (command) {
308
+ console.info(command)
309
+ }),
310
+ )
311
+ }
312
+ function reconfigure() {
313
+ exitOnError(buildSystem.reconfigure())
314
+ }
315
+ function rebuild() {
316
+ exitOnError(buildSystem.rebuild())
317
+ }
318
+ function compile() {
319
+ exitOnError(buildSystem.compile())
320
+ }
321
+
322
+ let done = ifCommand('install', install)
323
+ done = done || ifCommand('configure', configure)
324
+ done = done || ifCommand('print-configure', printConfigure)
325
+ done = done || ifCommand('print-cmakejs-src', printCmakeJsSrc)
326
+ done = done || ifCommand('print-cmakejs-include', printCmakeJsInclude)
327
+ done = done || ifCommand('print-cmakejs-lib', printCmakeJsLib)
328
+ done = done || ifCommand('build', build)
329
+ done = done || ifCommand('print-build', printBuild)
330
+ done = done || ifCommand('clean', clean)
331
+ done = done || ifCommand('print-clean', printClean)
332
+ done = done || ifCommand('reconfigure', reconfigure)
333
+ done = done || ifCommand('rebuild', rebuild)
334
+ done = done || ifCommand('compile', compile)
335
+
336
+ if (!done) {
337
+ if (command) {
338
+ log.error('COM', 'Unknown command: ' + command)
339
+ process.exit(1)
340
+ } else {
341
+ build()
342
+ }
343
+ }
package/changelog.md ADDED
@@ -0,0 +1,225 @@
1
+ # v7.3.0 - 15/01/23
2
+
3
+ - feat(windows): replace custom libnode.def generation with version from node-api-headers
4
+ - fix: support for vs2015 with nodejs 18 and older (#317)
5
+ - fix(windows): always remove Path if PATH is also defined (#319)
6
+ - fix: Cmake arguments got converted to numbers (#314)
7
+ - fix: update node-api-headers
8
+ - chore: update dependencies
9
+
10
+ # v7.2.1 - 14/02/23
11
+
12
+ - fix: support Windows11SDK
13
+
14
+ # v7.2.0 - 12/02/23
15
+
16
+ - fix: `-DCMAKE_JS_VERSION=undefined` (#298)
17
+ - fix: Only add build type to `CMAKE_LIBRARY_OUTPUT_DIRECTORY` if needed (#299)
18
+ - feat: Forward extra arguments to CMake commands (#297)
19
+
20
+ # v7.1.1 - 15/12/22
21
+
22
+ - fix build errors on windows
23
+
24
+ # v7.1.0 - 14/12/22
25
+
26
+ - add commands for retrieving cmake-js include and lib directories
27
+ - fix win delay hook issues with electron
28
+ - fix missing js_native_api_symbols in windows node.lib
29
+
30
+ # v7.0.0 - 08/10/22
31
+
32
+ - update dependencies
33
+ - replace some dependencies with modern language features
34
+ - follow node-gyp behaviour for visual-studio version detection and selection
35
+ - automatically locate node-addon-api and add to include paths
36
+ - avoid downloads when building for node-api
37
+ - encourage use of MT builds with MSVC, rather than MD
38
+
39
+ # v6.3.1 - 05/06/22
40
+
41
+ - add missing bluebird dependency
42
+ - fix platform detection for visual studio 2019 and newer
43
+ - fix platform detection for macos
44
+
45
+ # v6.3.0 - 26/11/21
46
+
47
+ - add offline mode: https://github.com/cmake-js/cmake-js/pull/260
48
+ - handle missing buildSystem.log: https://github.com/cmake-js/cmake-js/pull/259
49
+ - Add config flag: https://github.com/cmake-js/cmake-js/pull/251
50
+ - Remove escaped quotes from windows registry queries: https://github.com/cmake-js/cmake-js/pull/250
51
+
52
+ # v6.2.1 - 20/07/21
53
+
54
+ - EOL hotfix (Thx Windows!)
55
+
56
+ # v6.2.0 - 19/07/21
57
+
58
+ - various fixes
59
+
60
+ # v6.1.0 - 27/02/20
61
+
62
+ - Add support for "-A/--platform" option to make target platform selectable for Visual Studio 2019 generator: https://github.com/cmake-js/cmake-js/pull/201
63
+
64
+ # v6.0.0 - 30/09/19
65
+
66
+ - Dropped compatibility of old Node.js runtimes (<10.0.0)
67
+ - --cc and --cxx flags for overriding compiler detection: https://github.com/cmake-js/cmake-js/pull/191
68
+
69
+ # v5.3.2 - 21/08/19
70
+
71
+ - Visual Studio detection fixes
72
+
73
+ # v5.3.1 - 18/07/19
74
+
75
+ - VS 2019 Support fix: https://github.com/cmake-js/cmake-js/pull/187
76
+
77
+ # v5.3.0 - 09/07/19
78
+
79
+ - VS 2019 Support: https://github.com/cmake-js/cmake-js/pull/178/, https://github.com/cmake-js/cmake-js/pull/184/
80
+
81
+ # v5.2.1 - 10/04/19
82
+
83
+ - Win delay load hook: https://github.com/cmake-js/cmake-js/pull/165/
84
+
85
+ # v5.1.1 - 02/04/19
86
+
87
+ - CMake 3.14 support fixed - https://github.com/cmake-js/cmake-js/pull/161
88
+
89
+ # v5.1.0 - 14/02/19
90
+
91
+ - CMake 3.14 support - https://github.com/cmake-js/cmake-js/pull/159
92
+
93
+ # v5.0.1 - 24/01/19
94
+
95
+ - Linux line ending hotfix (I hate Windows!)
96
+
97
+ # v5.0.0 - 24/01/19
98
+
99
+ - [semver major] Add case sensitive NPM config integration https://github.com/cmake-js/cmake-js/pull/151
100
+ - better npm config integration, all CMake.js commandline argument could be set by using npm config: https://github.com/cmake-js/cmake-js#npm-config-integration
101
+ - support for Electron v4+ https://github.com/cmake-js/cmake-js/pull/152
102
+
103
+ # v4.0.1 - 03/10/18
104
+
105
+ - log argument hotfix https://github.com/cmake-js/cmake-js/pull/145
106
+
107
+ # v4.0.0 - 14/09/18
108
+
109
+ BREAKING CHANGES:
110
+
111
+ - -s/--std (along with -o/--prec11 option removed, you have to specify compiler standard in CMakeLists.txt files https://github.com/cmake-js/cmake-js/issues/72
112
+ - Implicit -w compiler flag doesn't get added on OSX https://github.com/cmake-js/cmake-js/pull/133
113
+
114
+ # v3.7.3 - 16/05/18
115
+
116
+ - npm config hotfix https://github.com/cmake-js/cmake-js/pull/123
117
+
118
+ # v3.7.2 - 16/05/18
119
+
120
+ - do not use, breaks ES5 compatibility
121
+
122
+ # v3.7.1 - 07/05/18
123
+
124
+ - Linux line ending hotfix (wat)
125
+
126
+ # v3.7.0 - 07/05/18
127
+
128
+ - PR: replace unzip with unzipper https://github.com/cmake-js/cmake-js/pull/120
129
+ - PR: replace npmconf with rc https://github.com/cmake-js/cmake-js/pull/119
130
+ - PR: update to modern fs-extras https://github.com/cmake-js/cmake-js/pull/118
131
+ - PR: Adds toolset command line flag https://github.com/cmake-js/cmake-js/pull/115
132
+
133
+ # v3.6.2 - 17/02/18
134
+
135
+ - use https distribution download urls
136
+ - custom cmake options made case sensitive
137
+
138
+ # v3.6.1 - 11/01/18
139
+
140
+ - Detect 2017 Windows Build Tools
141
+
142
+ # v3.6.0 - 11/27/17
143
+
144
+ - "T" option for building specified target: https://github.com/cmake-js/cmake-js/pull/98
145
+
146
+ # v3.5.0 - 06/21/17
147
+
148
+ - Added Visual Studio 2017 compatibility: https://github.com/cmake-js/cmake-js/pull/78
149
+
150
+ # v3.4.1 - 02/4/17
151
+
152
+ - FIX: test output instead of guessing by platform: https://github.com/cmake-js/cmake-js/pull/77
153
+
154
+ # v3.4.0 - 01/12/17
155
+
156
+ - "G" option to set custom generators: https://github.com/cmake-js/cmake-js/pull/64
157
+
158
+ # v3.3.1 - 09/13/16
159
+
160
+ - fix of default parameters: https://github.com/cmake-js/cmake-js/pull/57
161
+
162
+ # v3.3.0 - 09/02/16
163
+
164
+ - silent option (https://github.com/cmake-js/cmake-js/pull/54)
165
+ - out option (https://github.com/cmake-js/cmake-js/pull/53)
166
+
167
+ # v3.2.3 - 08/17/16
168
+
169
+ - Line endings
170
+
171
+ # v3.2.2 - 12/08/16
172
+
173
+ - Multi directory support for Windows/MSVC build
174
+
175
+ # v3.2.1 - 25/04/16
176
+
177
+ - Linux line ending hotfix
178
+
179
+ # v3.2.0 - 25/04/16
180
+
181
+ - Added NW.js 0.13+ compatibility
182
+ - Node v0.10.x support fixed (https://github.com/cmake-js/cmake-js/pull/45, https://github.com/cmake-js/cmake-js/issues/50)
183
+ - CMAKE_JS_VERSION defined (https://github.com/cmake-js/cmake-js/issues/48)
184
+
185
+ # v3.1.2 - 03/02/16
186
+
187
+ - Fixed cmake-js binary ES5 compatibility.
188
+
189
+ # v3.1.1 - 03/02/16
190
+
191
+ - Fixed line endings
192
+
193
+ # v3.1.0 - 03/02/16
194
+
195
+ - Custom CMake parameter support (https://github.com/gerhardberger)
196
+
197
+ # v3.0.0 - 20/11/15
198
+
199
+ - Visual C++ Build Tools support
200
+ - std option introduced
201
+ - better unit test coverage
202
+
203
+ # v2.1.0 - 29/10/15
204
+
205
+ - explicit options for use GNU or Clang compiler instead of CMake's default (see --help for details)
206
+
207
+ # v2.0.2 - 22/10/15
208
+
209
+ - Fix: print-\* commands report "undefined"
210
+
211
+ # v2.0.0 - 17/10/15
212
+
213
+ - Fix: distribution files only gets downloaded if needed (4.0.0+)
214
+ - option to generate Xcode project (-x, --prefer-xcode) - by https://github.com/javedulu
215
+ - compile command for fast module compilation during npm updates (instead of rebuild)
216
+ - codebase switched to ECMAScript 2015
217
+
218
+ # v1.1.1 - 06/10/15
219
+
220
+ - Hotfix for build NW.js correctly.
221
+
222
+ # v1.1.0 - 05/10/15
223
+
224
+ - Node.js 4.0.0+ support
225
+ - Downloads the small, header only tarball for Node.js 4+
@@ -0,0 +1,58 @@
1
+ 'use strict'
2
+ const path = require('path')
3
+
4
+ function getConfig(lookPath, log) {
5
+ const pjsonPath = path.join(lookPath, 'package.json')
6
+ log.silly('CFG', "Looking for package.json in: '" + pjsonPath + "'.")
7
+ try {
8
+ const json = require(pjsonPath)
9
+ log.silly('CFG', 'Loaded:\n' + JSON.stringify(json))
10
+ if (json && json['cmake-js'] && typeof json['cmake-js'] === 'object') {
11
+ log.silly('CFG', 'Config found.')
12
+ return json['cmake-js']
13
+ } else {
14
+ log.silly('CFG', 'Config not found.')
15
+ return null
16
+ }
17
+ } catch (e) {
18
+ log.silly('CFG', "'package.json' not found.")
19
+ return null
20
+ }
21
+ }
22
+
23
+ module.exports = function (projectPath, log) {
24
+ log.verbose('CFG', "Looking for application level CMake.js config in '" + projectPath + '.')
25
+ let currPath = projectPath
26
+ let lastConfig = null
27
+ let currConfig
28
+ for (;;) {
29
+ currConfig = getConfig(currPath, log)
30
+ if (currConfig) {
31
+ lastConfig = currConfig
32
+ }
33
+ try {
34
+ log.silly('CFG', 'Looking for parent path.')
35
+ const lastPath = currPath
36
+ currPath = path.normalize(path.join(currPath, '..'))
37
+ if (lastPath === currPath) {
38
+ currPath = null // root
39
+ }
40
+ if (currPath) {
41
+ log.silly('CFG', "Parent path: '" + currPath + "'.")
42
+ }
43
+ } catch (e) {
44
+ log.silly('CFG', 'Exception:\n' + e.stack)
45
+ break
46
+ }
47
+ if (currPath === null) {
48
+ log.silly('CFG', "Parent path with package.json file doesn't exists. Done.")
49
+ break
50
+ }
51
+ }
52
+ if (lastConfig) {
53
+ log.verbose('CFG', 'Application level CMake.js config found:\n' + JSON.stringify(lastConfig))
54
+ } else {
55
+ log.verbose('CFG', "Application level CMake.js config doesn't exists.")
56
+ }
57
+ return lastConfig
58
+ }