CMake.js is a Node.js native addon build tool that replaces node-gyp's gyp with CMake. Current stable version is 8.0.0 (released late 2024), requiring Node.js >=20.17.0 or >=22.9.0. It supports Node.js, NW.js, and Electron runtimes out of the box, with automatic runtime detection and build configuration. Key differentiators: uses CMake instead of GYP, supports modern Node.js versions, built-in fetch for smaller install size, and native addon development without post-build steps for Electron/NW.js. Release cadence is irregular with major version bumps roughly every 1-2 years, each introducing breaking changes.
npm install cmake-jsVerified import paths — ran on the pinned version, not inferred.
Shows minimal setup: CMakeLists.txt with cmake-js include hook, and CLI compile command.
Upgrade Node.js to ^20.17.0 || >=22.9.0
Use v6.x for older Node.js or upgrade Node.js to 14.15+
Update CMakeLists.txt to use new variable names as per upgrade guide
Use Visual Studio 2015 or newer
Use --cmake-path or -DCMAKE_TOOLCHAIN_FILE=... when targeting different architecture
Use: cmake-js compile --runtime=electron --runtimeVersion=28.0.0
Add 'include(../node_modules/cmake-js/cmake-js.cmake)' to CMakeLists.txt, or run 'npm install cmake-js'
Specify runtime explicitly: --runtime=node --runtime-version=20.0.0
Install CMake >=3.10 and ensure generator matches platform (e.g., 'Unix Makefiles' on Linux, 'Visual Studio 17 2022' on Windows)