|
1 | 1 | # CMake.js
|
2 | 2 |
|
3 |
| -**CMake.js** is a build tool that allow native addon developer to compile their |
4 |
| -C++ code into executable form. It works like **[node-gyp](node-gyp.md)** but |
5 |
| -instead of Google's **gyp** format it is base on **CMake** build system. |
| 3 | +[**CMake.js**](https://github.com/cmake-js/cmake-js) is a build tool that allow native addon developers to compile their |
| 4 | +C or C++ code into executable form. It works like **[node-gyp](node-gyp.md)** but |
| 5 | +instead of Google's [**gyp**](https://gyp.gsrc.io) tool it is based on the [**CMake**](https://cmake.org) build system. |
6 | 6 |
|
7 |
| -## **CMake** reference |
| 7 | +## Quick Start |
8 | 8 |
|
9 |
| - - [Installation](https://www.npmjs.com/package/cmake-js#installation) |
10 |
| - - [How to use](https://www.npmjs.com/package/cmake-js#usage) |
| 9 | +### Install CMake |
| 10 | + |
| 11 | +CMake.js requires that CMake be installed. Installers for a variety of platforms can be found on the [CMake website](https://cmake.org). |
| 12 | + |
| 13 | +### Install CMake.js |
| 14 | + |
| 15 | +For developers, CMake.js is typically installed as a global package: |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install -g cmake-js |
| 19 | +cmake-js --help |
| 20 | +``` |
| 21 | + |
| 22 | +> For *users* of your native addon, CMake.js should be configured as a dependency in your `package.json` as described in the [CMake.js documentation](https://github.com/cmake-js/cmake-js). |
| 23 | +
|
| 24 | +### CMakeLists.txt |
| 25 | + |
| 26 | +Your project will require a `CMakeLists.txt` file. The [CMake.js README file](https://github.com/cmake-js/cmake-js#usage) shows what's necessary. |
| 27 | + |
| 28 | +### NAPI_VERSION |
| 29 | + |
| 30 | +When building N-API addons, it's crucial to specify the N-API version your code is designed to work with. With CMake.js, this information is specified in the `CMakeLists.txt` file: |
| 31 | + |
| 32 | +``` |
| 33 | +add_definitions(-DNAPI_VERSION=3) |
| 34 | +``` |
| 35 | + |
| 36 | +Since N-API is ABI-stable, your N-API addon will work, without recompilation, with the N-API version you specify in `NAPI_VERSION` and all subsequent N-API versions. |
| 37 | + |
| 38 | +In the absence of a need for features available only in a specific N-API version, version 3 is a good choice as it is the version of N-API that was active when N-API left experimental status. |
| 39 | + |
| 40 | +### NAPI_EXPERIMENTAL |
| 41 | + |
| 42 | +The following line in the `CMakeLists.txt` file will enable N-API experimental features if your code requires them: |
| 43 | + |
| 44 | +``` |
| 45 | +add_definitions(-DNAPI_EXPERIMENTAL) |
| 46 | +``` |
| 47 | + |
| 48 | +### node-addon-api |
| 49 | + |
| 50 | +If your N-API native add-on uses the optional [**node-addon-api**](https://github.com/nodejs/node-addon-api#node-addon-api-module) C++ wrapper, the `CMakeLists.txt` file requires additional configuration information as described on the [CMake.js README file](https://github.com/cmake-js/cmake-js#n-api-and-node-addon-api). |
| 51 | + |
| 52 | +## Example |
| 53 | + |
| 54 | +A working example of an N-API native addon built using CMake.js can be found on the [node-addon-examples repository](https://github.com/nodejs/node-addon-examples/tree/master/build_with_cmake#building-n-api-addons-using-cmakejs). |
| 55 | + |
| 56 | +## **CMake** Reference |
| 57 | + |
| 58 | + - [Installation](https://github.com/cmake-js/cmake-js#installation) |
| 59 | + - [How to use](https://github.com/cmake-js/cmake-js#usage) |
11 | 60 | - [Using N-API and node-addon-api](https://github.com/cmake-js/cmake-js#n-api-and-node-addon-api)
|
12 |
| - - [Tutorials](https://www.npmjs.com/package/cmake-js#tutorials) |
13 |
| - - [Use case in the works - ArrayFire.js](https://www.npmjs.com/package/cmake-js#use-case-in-the-works---arrayfirejs) |
| 61 | + - [Tutorials](https://github.com/cmake-js/cmake-js#tutorials) |
| 62 | + - [Use case in the works - ArrayFire.js](https://github.com/cmake-js/cmake-js#use-case-in-the-works---arrayfirejs) |
14 | 63 |
|
15 | 64 | Sometimes finding the right settings is not easy so to accomplish at most
|
16 | 65 | complicated task please refer to:
|
17 | 66 |
|
18 | 67 | - [CMake documentation](https://cmake.org/)
|
19 |
| -- [CMake.js wiki](https://github.com/cmake-js/cmake-js/wiki) |
| 68 | +- [CMake.js wiki](https://github.com/cmake-js/cmake-js/wiki) |
0 commit comments