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