@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 ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Gábor Mező aka unbornchikken
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,402 @@
1
+ # CMake.js (MIT)
2
+
3
+ [![Node CI](https://github.com/cmake-js/cmake-js/actions/workflows/node.yaml/badge.svg)](https://github.com/cmake-js/cmake-js/actions/workflows/node.yaml)
4
+ [![npm](https://img.shields.io/npm/v/cmake-js)](https://www.npmjs.com/package/cmake-js)
5
+
6
+ ## About
7
+
8
+ CMake.js is a Node.js native addon build tool which works (almost) _exactly_ like [node-gyp](https://github.com/TooTallNate/node-gyp), but instead of [gyp](http://en.wikipedia.org/wiki/GYP_%28software%29), it is based on [CMake](http://cmake.org) build system. It's compatible with the following runtimes:
9
+
10
+ - Node.js 14.15+ since CMake.js v7.0.0 (for older runtimes please use an earlier version of CMake.js). Newer versions can produce builds targeting older runtimes
11
+ - [NW.js](https://github.com/nwjs/nw.js): all CMake.js based native modules are compatible with NW.js out-of-the-box, there is no [nw-gyp like magic](https://github.com/nwjs/nw.js/wiki/Using-Node-modules#3rd-party-modules-with-cc-addons) required
12
+ - [Electron](https://github.com/electron/electron): out-of-the-box build support, [no post build steps required](https://github.com/electron/electron/blob/main/docs/tutorial/using-native-node-modules.md)
13
+
14
+ If you use `node-api` for your module instead of `nan` it should be able to run on all the runtimes above without needing to be built separately for each.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install cmake-js
20
+ ```
21
+
22
+ **Help:**
23
+
24
+ ```bash
25
+ cmake-js --help
26
+ ```
27
+
28
+ ```
29
+ Usage: cmake-js [<command>] [options]
30
+
31
+ Commands:
32
+ cmake-js install Install Node.js distribution files if needed
33
+ cmake-js configure Configure CMake project
34
+ cmake-js print-configure Print the configuration command
35
+ cmake-js print-cmakejs-src Print the value of the CMAKE_JS_SRC variable
36
+ cmake-js print-cmakejs-include Print the value of the CMAKE_JS_INC variable
37
+ cmake-js print-cmakejs-lib Print the value of the CMAKE_JS_LIB variable
38
+ cmake-js build Build the project (will configure first if
39
+ required)
40
+ cmake-js print-build Print the build command
41
+ cmake-js clean Clean the project directory
42
+ cmake-js print-clean Print the clean command
43
+ cmake-js reconfigure Clean the project directory then configure the
44
+ project
45
+ cmake-js rebuild Clean the project directory then build the
46
+ project
47
+ cmake-js compile Build the project, and if build fails, try a
48
+ full rebuild
49
+
50
+ Options:
51
+ --version Show version number [boolean]
52
+ -h, --help Show help [boolean]
53
+ -l, --log-level set log level (silly, verbose, info, http, warn,
54
+ error), default is info [string]
55
+ -d, --directory specify CMake project's directory (where CMakeLists.txt
56
+ located) [string]
57
+ -D, --debug build debug configuration [boolean]
58
+ -B, --config specify build configuration (Debug, RelWithDebInfo,
59
+ Release), will ignore '--debug' if specified [string]
60
+ -c, --cmake-path path of CMake executable [string]
61
+ -m, --prefer-make use Unix Makefiles even if Ninja is available (Posix)
62
+ [boolean]
63
+ -x, --prefer-xcode use Xcode instead of Unix Makefiles [boolean]
64
+ -g, --prefer-gnu use GNU compiler instead of default CMake compiler, if
65
+ available (Posix) [boolean]
66
+ -G, --generator use specified generator [string]
67
+ -t, --toolset use specified toolset [string]
68
+ -A, --platform use specified platform name [string]
69
+ -T, --target only build the specified target [string]
70
+ -C, --prefer-clang use Clang compiler instead of default CMake compiler,
71
+ if available (Posix) [boolean]
72
+ --cc use the specified C compiler [string]
73
+ --cxx use the specified C++ compiler [string]
74
+ -r, --runtime the runtime to use [string]
75
+ -v, --runtime-version the runtime version to use [string]
76
+ -a, --arch the architecture to build in [string]
77
+ -p, --parallel the number of threads cmake can use [number]
78
+ --CD Custom argument passed to CMake in format:
79
+ -D<your-arg-here> [string]
80
+ -i, --silent Prevents CMake.js to print to the stdio [boolean]
81
+ -O, --out Specify the output directory to compile to, default is
82
+ projectRoot/build [string]
83
+ ```
84
+
85
+ **Requirements:**
86
+
87
+ - [CMake](http://www.cmake.org/download/)
88
+ - A proper C/C++ compiler toolchain of the given platform
89
+ - **Windows**:
90
+ - [Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/). If you installed nodejs with the installer, you can install these when prompted.
91
+ - An alternate way is to install the [Chocolatey package manager](https://chocolatey.org/install), and run `choco install visualstudio2017-workload-vctools` in an Administrator Powershell
92
+ - If you have multiple versions installed, you can select a specific version with `npm config set msvs_version 2017` (Note: this will also affect `node-gyp`)
93
+ - **Unix/Posix**:
94
+ - Clang or GCC
95
+ - Ninja or Make (Ninja will be picked if both present)
96
+
97
+ ## Usage
98
+
99
+ ### General
100
+
101
+ It is advised to use Node-API for new projects instead of NAN. It provides ABI stability making usage simpler and reducing maintainance.
102
+
103
+ In a nutshell. _(For more complete documentation please see [the first tutorial](https://github.com/unbornchikken/cmake-js/wiki/TUTORIAL-01-Creating-a-native-module-by-using-CMake.js-and-NAN).)_
104
+
105
+ - Install cmake-js for your module `npm install --save cmake-js`
106
+ - Put a CMakeLists.txt file into your module root with this minimal required content:
107
+
108
+ ```cmake
109
+ cmake_minimum_required(VERSION 3.15)
110
+ cmake_policy(SET CMP0091 NEW)
111
+ cmake_policy(SET CMP0042 NEW)
112
+
113
+ project (your-addon-name-here)
114
+
115
+ add_definitions(-DNAPI_VERSION=4)
116
+
117
+ include_directories(${CMAKE_JS_INC})
118
+
119
+ file(GLOB SOURCE_FILES "your-source files-location-here")
120
+
121
+ add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
122
+ set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
123
+ target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
124
+
125
+ if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
126
+ # Generate node.lib
127
+ execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
128
+ endif()
129
+ ```
130
+
131
+ - Add the following into your package.json scripts section:
132
+
133
+ ```json
134
+ "scripts": {
135
+ "install": "cmake-js compile"
136
+ }
137
+ ```
138
+
139
+ - Add the following into your package.json, using the same NAPI_VERSION value you provided to cmake
140
+
141
+ ```json
142
+ "binary": {
143
+ "napi_versions": [7]
144
+ },
145
+ ```
146
+
147
+ #### Commandline
148
+
149
+ With cmake-js installed as a depdendency or devDependency of your module, you can access run commands directly with:
150
+
151
+ ```
152
+ npx cmake-js --help
153
+ # OR
154
+ yarn cmake-js --help
155
+ ```
156
+
157
+ Please refer to the `--help` for the lists of available commands (they are like commands in `node-gyp`).
158
+
159
+ You can override the project default runtimes via `--runtime` and `--runtime-version`, such as: `--runtime=electron --runtime-version=0.26.0`. See below for more info on runtimes.
160
+
161
+ ### CMake Specific
162
+
163
+ `CMAKE_JS_VERSION` variable will reflect the actual CMake.js version. So CMake.js based builds could be detected, eg.:
164
+
165
+ ```cmake
166
+ if (CMAKE_JS_VERSION)
167
+ add_subdirectory(node_addon)
168
+ else()
169
+ add_subdirectory(other_subproject)
170
+ endif()
171
+ ```
172
+
173
+ ### NPM Config Integration
174
+
175
+ You can set npm configuration options for CMake.js.
176
+
177
+ For all users (global):
178
+
179
+ ```
180
+ npm config set cmake_<key> <value> --global
181
+ ```
182
+
183
+ For current user:
184
+
185
+ ```
186
+ npm config set cmake_<key> <value>
187
+ ```
188
+
189
+ CMake.js will set a variable named `"<key>"` to `<value>` (by using `-D<key>="<value>"` option). User settings will **overwrite** globals.
190
+
191
+ UPDATE:
192
+
193
+ You can set CMake.js command line arguments with npm config using the following pattern:
194
+
195
+ ```
196
+ npm config set cmake_js_G "Visual Studio 56 Win128"
197
+ ```
198
+
199
+ Which sets the CMake generator, basically defaults to:
200
+
201
+ ```
202
+ cmake-js -G "Visual Studio 56 Win128"
203
+ ```
204
+
205
+ #### Example:
206
+
207
+ Enter at command prompt:
208
+
209
+ ```
210
+ npm config set cmake_Foo="bar"
211
+ ```
212
+
213
+ Then write to your CMakeLists.txt the following:
214
+
215
+ ```cmake
216
+ message (STATUS ${Foo})
217
+ ```
218
+
219
+ This will print during configure:
220
+
221
+ ```
222
+ --- bar
223
+ ```
224
+
225
+ ### Custom CMake options
226
+
227
+ You can add custom CMake options by beginning option name with `CD`.
228
+
229
+ #### Example
230
+
231
+ In command prompt:
232
+
233
+ ```
234
+ cmake-js compile --CDFOO="bar"
235
+ ```
236
+
237
+ Then in your CMakeLists.txt:
238
+
239
+ ```cmake
240
+ message (STATUS ${FOO})
241
+ ```
242
+
243
+ This will print during configure:
244
+
245
+ ```
246
+ --- bar
247
+ ```
248
+
249
+ ### Runtimes
250
+
251
+ #### Important
252
+
253
+ It is important to understand that this setting is to be configured in the **application's root package.json file**. If you're creating a native module targeting nw.js for example, then **do not specify anything** in your module's package.json. It's the actual application's decision to specify its runtime, your module's just compatible anything that was mentioned in the [About chapter](#about). Actually defining `cmake-js` key in your module's package.json file may lead to an error. Why? If you set it up to use nw.js 0.12.1 for example, then when it gets compiled during development time (to run its unit tests for example) it's gonna be compiled against io.js 1.2 runtime. But if you're having io.js 34.0.1 at the command line then, which is binary incompatible with 1.2, then your unit tests will fail for sure. So it is advised to not use cmake-js target settings in your module's package.json, because that way CMake.js will use that you have, and your tests will pass.
254
+
255
+ #### Configuration
256
+
257
+ If any of the `runtime`, `runtimeVersion`, or `arch` configuration parameters is not explicitly configured, sensible defaults will be auto-detected based on the JavaScript environment where CMake.js runs within.
258
+
259
+ You can configure runtimes for compiling target for all depending CMake.js modules in an application. Define a `cmake-js` key in the application's root `package.json` file, eg.:
260
+
261
+ ```json
262
+ {
263
+ "name": "ta-taram-taram",
264
+ "description": "pa-param-pam-pam",
265
+ "version": "1.0.0",
266
+ "main": "app.js",
267
+ "cmake-js": {
268
+ "runtime": "node",
269
+ "runtimeVersion": "0.12.0",
270
+ "arch": "ia32"
271
+ }
272
+ }
273
+ ```
274
+
275
+ Available settings:
276
+
277
+ - **runtime**: application's target runtime, possible values are:
278
+ - `node`: Node.js
279
+ - `nw`: nw.js
280
+ - `electron`: Electron
281
+ - **runtimeVersion**: version of the application's target runtime, for example: `0.12.1`
282
+ - **arch**: architecture of application's target runtime (eg: `x64`, `ia32`, `arm64`, `arm`). _Notice: on non-Windows systems the C++ toolset's architecture's gonna be used despite this setting. If you don't specify this on Windows, then architecture of the main node runtime is gonna be used, so you have to choose a matching nw.js runtime._
283
+
284
+ #### Node-API and `node-addon-api`
285
+
286
+ [ABI-stable Node.js API
287
+ (Node-API)](https://nodejs.org/api/n-api.html#n_api_node_api),
288
+ which was previously known as N-API, supplies a set of C
289
+ APIs that allow to compilation and loading of native modules by
290
+ different versions of Node.js that support Node-API which includes
291
+ all versions of Node.js v10.x and later.
292
+
293
+ To compile a native module that uses only the
294
+ [plain `C` Node-API calls](https://nodejs.org/api/n-api.html#n_api_node_api),
295
+ follow the directions for plain `node` native modules.
296
+
297
+ You must also add the following lines to your CMakeLists.txt, to allow for building on windows
298
+
299
+ ```
300
+ if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
301
+ # Generate node.lib
302
+ execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
303
+ endif()
304
+ ```
305
+
306
+ To compile a native module that uses the header-only C++ wrapper
307
+ classes provided by
308
+ [`node-addon-api`](https://github.com/nodejs/node-addon-api),
309
+ you need to make your package depend on it with:
310
+
311
+ npm install --save node-addon-api
312
+
313
+ cmake-js will then add it to the include search path automatically
314
+
315
+ You should add the following to your package.json, with the correct version number, so that cmake-js knows the module is node-api and that it can skip downloading the nodejs headers
316
+
317
+ ```json
318
+ "binary": {
319
+ "napi_versions": [7]
320
+ },
321
+ ```
322
+
323
+ #### Electron
324
+
325
+ On Windows, the [`win_delay_load_hook`](https://www.electronjs.org/docs/tutorial/using-native-node-modules#a-note-about-win_delay_load_hook) is required to be embedded in the module or it will fail to load in the render process.
326
+ cmake-js will add the hook if the CMakeLists.txt contains the library `${CMAKE_JS_SRC}`.
327
+
328
+ Without the hook, the module can only be called from the render process using the Electron [remote](https://github.com/electron/electron/blob/master/docs/api/remote.md) module.
329
+
330
+ #### Runtime options in CMakeLists.txt
331
+
332
+ The actual node runtime parameters are detectable in CMakeLists.txt files, the following variables are set:
333
+
334
+ - **NODE_RUNTIME**: `"node"`, `"nw"`, `"electron"`
335
+ - **NODE_RUNTIMEVERSION**: for example: `"0.12.1"`
336
+ - **NODE_ARCH**: `"x64"`, `"ia32"`, `"arm64"`, `"arm"`
337
+
338
+ #### NW.js
339
+
340
+ To make compatible your NW.js application with any NAN CMake.js based modules, write the following to your application's package.json file (this is not neccessary for node-api modules):
341
+
342
+ ```json
343
+ {
344
+ "cmake-js": {
345
+ "runtime": "nw",
346
+ "runtimeVersion": "nw.js-version-here",
347
+ "arch": "whatever-setting-is-appropriate-for-your-application's-windows-build"
348
+ }
349
+ }
350
+ ```
351
+
352
+ That's it. There is nothing else to do either on the application's or on the module's side, CMake.js modules are compatible with NW.js out-of-the-box. For more complete documentation please see [the third tutorial](https://github.com/unbornchikken/cmake-js/wiki/TUTORIAL-03-Using-CMake.js-based-native-modules-with-nw.js).
353
+
354
+ #### Heroku
355
+
356
+ [Heroku](https://heroku.com) uses the concept of a [buildpack](https://devcenter.heroku.com/articles/buildpacks) to define
357
+ how an application should be prepared to run in a [dyno](https://devcenter.heroku.com/articles/dynos).
358
+ The typical buildpack for note-based applications,
359
+ [heroku/nodejs](https://github.com/heroku/heroku-buildpack-nodejs),
360
+ provides an environment capable of running [node-gyp](https://github.com/TooTallNate/node-gyp),
361
+ but not [CMake](http://cmake.org).
362
+
363
+ The least "painful" way of addressing this is to use heroku's multipack facility:
364
+
365
+ - Set the applications' buildpack to
366
+ [https://github.com/heroku/heroku-buildpack-multi.git](https://github.com/heroku/heroku-buildpack-multi.git)
367
+
368
+ - In the root directory of the application,
369
+ create a file called `.buildpacks` with these two lines:
370
+
371
+ https://github.com/brave/heroku-cmake-buildpack.git
372
+ https://github.com/heroku/heroku-buildpack-nodejs.git
373
+
374
+ - Deploy the application to have the changes take effect
375
+
376
+ The `heroku-buildpack-multi` will run each buildpack in order allowing the node application to reference CMake in the Heroku
377
+ build environment.
378
+
379
+ ## Tutorials
380
+
381
+ - [TUTORIAL 01 Creating a native module by using CMake.js and NAN](https://github.com/unbornchikken/cmake-js/wiki/TUTORIAL-01-Creating-a-native-module-by-using-CMake.js-and-NAN)
382
+ - [TUTORIAL 02 Creating CMake.js based native addons with Qt Creator](https://github.com/unbornchikken/cmake-js/wiki/TUTORIAL-02-Creating-CMake.js-based-native-addons-with-QT-Creator)
383
+ - [TUTORIAL 03 Using CMake.js based native modules with NW.js](https://github.com/unbornchikken/cmake-js/wiki/TUTORIAL-03-Using-CMake.js-based-native-modules-with-nw.js)
384
+ - [TUTORIAL 04 Creating CMake.js based native modules with Boost dependency](https://github.com/unbornchikken/cmake-js/wiki/TUTORIAL-04-Creating-CMake.js-based-native-modules-with-Boost-dependency)
385
+
386
+ ## Real examples
387
+
388
+ - [@julusian/jpeg-turbo](https://github.com/julusian/node-jpeg-turbo) - A Node-API wrapping around libjpeg-turbo. cmake-js was a good fit here, as libjpeg-turbo provides cmake files that can be used, and would be hard to replicate correctly in node-gyp
389
+ - [node-datachannel](https://github.com/murat-dogan/node-datachannel) - Easy to use WebRTC data channels and media transport
390
+ - [aws-iot-device-sdk-v2](https://github.com/aws/aws-iot-device-sdk-js-v2) AWS IoT Device SDK for JavaScript v2
391
+
392
+ Open a PR to add your own project here.
393
+
394
+ ## Changelog
395
+
396
+ View [changelog.md](changelog.md)
397
+
398
+ ## Credits
399
+
400
+ https://github.com/cmake-js/cmake-js/graphs/contributors
401
+
402
+ Ty all!