Guide
Getting started
Install CPM, make a project, add a library and publish your own.
The npm-style package manager and build system for C++
One manifest. A lockfile. Dependencies built once and shared. No CMake.
Install · Quick start · Commands · Registry · Docs
cpm init -y hello && cd hello
cpm install fmt
cpm run
Why CPM?
- 📦 One file describes your project.
cpm.jsonclists the name, the C++ standard and the dependencies. Sources are found by convention, and CPM writes Ninja files directly, so there's no CMake. - 🔒 Reproducible by default.
cpm-lock.jsonpins every version, git commit and archive hash. Teammates and CI get exactly what you built. - ⚡ Build dependencies once. Each library is compiled once per toolchain and shared by every project on your machine.
- 🌐 A real registry. Install from cpm-registry.com, and publish your own libraries after a GitHub sign-in.
- 🧰 Zero dependencies. CPM is one self-contained binary of plain C++23, built with itself.
Install
One command installs CPM and, if your machine doesn't have them yet, a C++ compiler and Ninja.
Windows (PowerShell)
irm https://cpm-registry.com/install.ps1 | iex
Linux (x86-64) and macOS (Apple silicon, macOS 13.3+)
curl -fsSL https://cpm-registry.com/install.sh | sh
Open a new terminal afterwards so cpm is on your PATH, then try the quick start.
The script puts cpm in ~/.cpm/bin after checking its SHA-256 against the release, then runs cpm setup. That command looks for what CPM needs and says what it will change before it changes anything:
| Platform | What cpm setup installs when it's missing |
|---|---|
| Windows | WinLibs GCC (MinGW-w64, UCRT) and Ninja, into ~/.cpm/tools. Nothing outside your user folder changes. |
| Linux | g++ and ninja-build from your distribution, with sudo: apt, dnf, pacman, zypper or apk |
| macOS | Apple's Command Line Tools (Clang), plus Ninja into ~/.cpm/tools |
Run cpm setup --check at any time to see what's there without changing anything. If you already have GCC 13+ or Clang 17+, Ninja 1.10+ and git, CPM uses those and installs nothing.
Download the binary for your platform from the latest release, check it against SHA256SUMS, put it on your PATH, and run cpm setup.
The install scripts accept these environment variables:
CPM_HOMEinstalls somewhere other than~/.cpm.CPM_NO_SETUP=1skipscpm setup.CPM_NO_MODIFY_PATH=1leaves yourPATH,CPM_HOMEand shell profiles alone.
Quick start
Create a project:
cpm init -y hello # an executable; also --lib, --shared-lib, --header-only
cd hello
Add a library from the registry:
cpm install fmt
Use it in src/main.cpp:
#include <fmt/format.h>
int main() {
fmt::print("Hello from {}!\n", "CPM");
}
Build and run:
cpm run
# Hello from CPM!
cpm install added the dependency to cpm.jsonc. CPM edits the file in place and keeps your comments; the template cpm init writes explains every field. Trimmed down, it looks like this:
{
"name": "hello",
"version": "0.1.0",
// The C++ standard this package, and everything built for it, is compiled with.
"std": "c++23",
"type": "executable",
"dependencies": {
"fmt": "^12.2.0"
}
}
A project is just a manifest and a conventional layout:
hello/
├── cpm.jsonc the manifest
├── cpm-lock.json exact versions (commit it)
├── src/main.cpp the entry point (src/lib.cpp makes a library)
├── src/*.cpp everything else in src/ is compiled and linked in
└── tests/*.test.cpp each one is a test program for `cpm test`
Commands
| Command | What it does |
|---|---|
cpm setup [--check] |
Install a C++ compiler and Ninja if they're missing, or just report what's there |
cpm init [dir] |
Create a project: executable, static or shared library, or header-only |
cpm install <pkg> (i, add) |
Add dependencies: fmt, fmt@^12, ../mylib, git+https://…#v1.0 |
cpm install |
Install everything in cpm.jsonc exactly as cpm-lock.json says |
cpm update [pkg…] (up) |
Move dependencies to the newest versions their ranges allow |
cpm remove <pkg> (rm) |
Remove dependencies |
cpm build [--release] |
Compile into build/debug/ or build/release/ |
cpm run [script] [-- args] |
Build and run the program, or run a script from cpm.jsonc |
cpm test [filter] |
Build and run the test programs in tests/ |
cpm login · cpm logout · cpm whoami |
Sign in to the registry with GitHub |
cpm publish [--dry-run] |
Publish this library to the registry |
cpm yank <pkg>@<ver> |
Hide a published version from new installs |
cpm owner list|add|remove |
Manage who can publish a package |
Run cpm <command> --help for every option.
The registry
cpm-registry.com is CPM's default registry. Search it, read package pages, and copy install commands. To start with it holds fmt, spdlog, nlohmann-json, doctest, Catch2 and CLI11.
Publish your own library:
cpm login # sign in with GitHub, in the browser
cpm publish --dry-run # see what would be published
cpm publish
CPM packs a reproducible source archive: the same files always give the same SHA-256. The registry checks it again before accepting it. Published versions never change; to withdraw a broken one, use cpm yank.
Run a registry of your own. A registry can be:
- a plain directory or static website: static registries;
- a full service like cpm-registry.com, whose source is meirborowski/cpm-registry and runs on Cloudflare's free tier.
Point CPM at another registry in ~/.cpm/config.jsonc:
{
"registries": {
"default": "https://cpm-registry.com/",
"work": "https://registry.example.com/"
}
}
How it works
flowchart LR
M["cpm.jsonc"] -->|resolve| L["cpm-lock.json"]
L -->|"download + verify SHA-256"| S[("~/.cpm/store")]
S -->|"build once per toolchain"| S
S -->|link| C["cpm_modules/"]
C --> N["Ninja"] --> B["build/debug/hello"]
- Resolve. Every package gets exactly one version, which avoids ODR violations. The choice is saved in
cpm-lock.json. - Fetch. Sources go into a global store,
~/.cpm/store, checked against the hashes in the lockfile. - Build once. Each library is compiled once per ABI fingerprint: compiler, standard library, C++ standard, flags and platform. Every project with the same fingerprint reuses the result.
- Link.
cpm_modules/in your project points into the store, and CPM writes abuild.ninjafor your code.
Configuration
| Setting | Where |
|---|---|
| Registries, compiler, Ninja path, colours | ~/.cpm/config.jsonc (%USERPROFILE%\.cpm\config.jsonc on Windows) |
| Use another compiler | CXX=clang++ or --cxx clang++ |
| Move CPM's home (store, caches, sign-in) | CPM_HOME |
| Profiles, defines, per-platform settings | cpm.jsonc (manifest reference) |
Status
CPM is young, at v0.3, and moving fast. Every change is tested on Windows (MinGW-w64 GCC), Linux (GCC and Clang) and macOS (Apple Clang).
Works today:
- executables, plus static, shared and header-only libraries, in C++11 to C++26;
- registry, git and path dependencies;
- a shared build cache, with prebuilt binaries when a registry offers them;
- publishing;
- a one-command install that also sets up a compiler and Ninja.
On the roadmap:
- MSVC support;
- building CMake-based libraries directly (the "Legacy Bridge");
- prebuilt binaries for registry packages;
cpm searchandcpm outdated;- workspaces.
Documentation
- Specification: the manifest, dependencies, the lockfile, the store, ABI fingerprints, the build, the registry protocol and the CLI
- Architecture and roadmap
- Contributing: building CPM from source, the tests, and releases
License
MIT © meirborowski
From CPM's repository: README.md