CMake.js is a build tool that allow native addon developers to compile their C or C++ code into executable form. It works like node-gyp but instead of Google's gyp tool it is based on the CMake build system.
CMake.js requires that CMake be installed. Installers for a variety of platforms can be found on the CMake website.
For developers, CMake.js is typically installed as a global package:
npm install -g cmake-js cmake-js --help
For users of your native addon, CMake.js should be configured as a dependency in your
package.jsonas described in the CMake.js documentation.
Your project will require a
CMakeLists.txt file. The CMake.js README file shows what's necessary.
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
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.
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.
The following line in the
CMakeLists.txt file will enable N-API experimental features if your code requires them:
A working example of an N-API native addon built using CMake.js can be found on the node-addon-examples repository.
- How to use
- Using N-API and node-addon-api
- Use case in the works - ArrayFire.js
Sometimes finding the right settings is not easy so to accomplish at most complicated task please refer to: