Registry / devops / cmake-harden

cmake-harden

JSON →
library1.1.2jsnpmunverified

A CMake module that applies compiler hardening options based on OpenSSF guidelines for C and C++ projects. Current stable version is 1.1.2, released with low cadence. It differs from other hardening approaches by being a simple, dependency-free module installable via npm, integrating seamlessly with Node.js CMake projects. It supports hardening both C and C++ targets with optional RUNTIME flags.

npm install cmake-harden
INSTALL
IMPORT
SIG · CMAKE-HARDEN
C
cmake-harden
devopsjavascriptv1.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

harden
✓ include(cmake-harden) harden(my_target CXX RUNTIME)
✗ find_package(cmake-harden) or include(cmake-harden) without find_package path
Requires find_package with PATHS node_modules/cmake-harden if installed via npm. The harden macro is defined after inclusion.
find_package(cmake-harden)
✓ find_package(cmake-harden REQUIRED PATHS node_modules/cmake-harden)
✗ find_package(cmake-harden) without PATHS
The module is not installed system-wide; must specify path to node_modules.
include(cmake-harden)
✓ include(cmake-harden/cmake-harden.cmake)
✗ include(cmake-harden) without full path or with find_package
If using include directly, the file path must be correct after find_package resolves the location.

Shows how to include the cmake-harden module and apply hardening to a C executable target.

find_package(cmake-harden REQUIRED PATHS node_modules/cmake-harden) add_executable(myapp main.c) harden(myapp C) target_compile_options(myapp PRIVATE -Wall -Wextra)
Debug
Known issues
gotchafind_package must specify PATHS to node_modules when installed via npm
fix
Use find_package(cmake-harden REQUIRED PATHS node_modules/cmake-harden)
affects: *
gotchaThe module does not set CMAKE_CXX_FLAGS or CMAKE_C_FLAGS globally; it applies to specific targets
fix
Call harden() on each target you want to harden
affects: *
gotchaThe RUNTIME argument only adds runtime hardening flags (e.g., -D_FORTIFY_SOURCE=2), not compile-time
fix
Use harden(target CXX RUNTIME) to also add runtime flags
affects: *
deprecatedNo deprecated features known
Errors
Common errors & fixes
CMake Error at CMakeLists.txt:1 (find_package): By not providing "Findcmake-harden.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "cmake-harden", but CMake did not find one.
Missing PATHS argument or cmake-harden not installed
fix
Ensure npm install cmake-harden is run, then add PATHS node_modules/cmake-harden to find_package
CMake Error at CMakeLists.txt:5 (harden): Unknown CMake command "harden".
Module not included before calling harden()
fix
Add include(cmake-harden/cmake-harden.cmake) or use find_package and then include the module file
npm WARN cmake-harden@1.1.2 requires a peer of cmake but none is installed.
cmake is not listed as a peer dependency but npm may warn
fix
Ensure cmake is available in the system or project (not an npm issue)
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
2
Resources
cmake-harden — npm install cmake-harden · libregistry