CMake.js
A CMake-based build tool for compiling Node.js native C/C++ addons
Repository Health
Technical Analysis
CMake.js is a Node.js native addon build tool that works almost exactly like node-gyp, but drives the CMake build system instead of gyp. It compiles C and C++ addons for Node.js and downloads the required headers and libraries for the target runtime automatically.
Modules built with CMake.js are compatible out of the box with Node.js, Electron, and NW.js, and when built against Node-API they can run across all of those runtimes without separate builds. It exposes a command-line interface (cmake-js build, configure, rebuild, etc.) and a programmatic API for integrating native builds into a project’s toolchain.
What You Get
- A cmake-js CLI with configure, build, rebuild, clean, and print-configure commands
- Automatic download of Node.js/Electron/NW.js headers and import libraries for the target runtime
- Out-of-the-box compatibility with Node.js, Electron, and NW.js, plus cross-runtime Node-API builds
- A programmatic API for driving builds from your own scripts
- CMake toolchain support for advanced cross-compilation and platform configuration
Common Use Cases
- Compiling C/C++ native addons for Node.js using CMake instead of node-gyp
- Building native modules that must run on Electron or NW.js without post-build steps
- Producing cross-runtime addons with Node-API from a single build configuration
- Integrating existing CMake-based C/C++ libraries into a Node.js package
Under The Hood
Architecture - CMake.js is a Node.js CLI (bin/cmake-js) backed by a lib/ layer that orchestrates a native build. It resolves the target runtime and version, downloads the matching headers and import libraries (dist manifest handling), locates a system CMake via which, generates the CMake configuration, and shells out to CMake and the platform compiler. A distributed-headers/runtime-paths module maps each runtime (Node.js, Electron, NW.js) to its include and lib locations.
Tech Stack - JavaScript running on Node.js 14.15+. Key dependencies include yargs for the CLI, rc for layered configuration, fs-extra and tar for filesystem and archive handling, semver for version resolution, which to find CMake, url-join for building download URLs, and node-api-headers to supply Node-API definitions. It requires an external CMake installation and a C/C++ toolchain at runtime.
Code Quality - The repository has a tests/ directory run under mocha exercising configuration and build paths, a documented changelog across 15+ releases, and a modular lib/ structure separating runtime resolution, downloading, and CMake invocation. Development activity has slowed but the project is mature with 60+ contributors and over a million weekly downloads.
API Design - The CLI intentionally mirrors node-gyp (configure, build, rebuild, clean), lowering the barrier for developers migrating from gyp. Sensible defaults and rc-based configuration keep simple cases simple, while flags expose CMake toolchains and target selection for advanced cross-compilation. The main friction is inherent to native builds — you must supply a working CMake and compiler — so the learning curve reflects the native-build domain rather than the tool itself.”