Reference
Commands
Every command and option, configuration and environment variables.
cpm [global options] <command> [command options] [arguments] [-- passthrough…]
1. Global options
Global options may appear before or after the command, but not after --.
| Option | Description |
|---|---|
-C, --dir <path> |
Run as if started in <path>. |
-v, --verbose |
More output. Repeat (-vv) to also print every subprocess command line. |
-q, --quiet |
Errors only. |
--color <auto|always|never> |
Colour output. auto: on when stderr is a terminal, NO_COLOR is unset and TERM is not dumb. |
-h, --help |
Help for CPM or for the given command. Printed to stdout. |
-V, --version |
Prints cpm <version> to stdout. With -v it adds the commit, the compiler CPM was built with, and $CPM_HOME. |
Short boolean flags can be combined (-Dv). Option values may be attached (--profile=release, -j8) or separate (--profile release, -j 8).
2. Exit codes
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Operation failed: resolution, network, integrity, compile or link error, failing test, invalid manifest |
2 |
Usage error: unknown command or option, missing or invalid argument |
130 |
Interrupted (Ctrl-C / SIGINT). Child processes are terminated, and staged store writes are abandoned, never half-committed. |
| n | cpm run: the exit code of the script or program, if CPM itself succeeded |
3. Commands
cpm init
cpm init [<dir>] [-y] [--name <name>] [--lib | --shared-lib | --header-only] [--std <std>] [--force]
Scaffolds a package in <dir> (default ., created if missing).
- Interactive by default. It asks, in this order, for name, version (
0.1.0), description, type (executable), C++ standard (c++23) and license, npm-style:version: (0.1.0). Pressing Enter takes the default in parentheses. An invalid answer is explained and the question is asked again. At the end of input, the remaining defaults are taken. Values given as options (--name,--lib/--shared-lib/--header-only,--std) are not asked. The type question also accepts short answers:exe,lib/static,shared/dll,header. Prompts go to stderr. When stdin is not a terminal,-yis implied. -yaccepts every default. The name is the directory name lowercased, with every run of invalid characters replaced by-and leading or trailing punctuation trimmed. If the result is still invalid (manifest.md §3.1),--nameis required.- Never overwrites existing files. An existing
cpm.jsoncis an error unless--forceis given. Other existing files are skipped with a notice. - Files created (
<id>is the name turned into a C++ identifier for the templates' namespace:.and-become_, a leading digit gets a_prefix, and a C++ keyword orstdgets a_suffix):
| Type | Files |
|---|---|
| executable (default) | cpm.jsonc, src/main.cpp, src/greeting.hpp, src/greeting.cpp, tests/greeting.test.cpp, .gitignore |
--lib / --shared-lib |
cpm.jsonc, include/<name>/<name>.hpp, src/lib.cpp, tests/<name>.test.cpp, .gitignore |
--header-only |
cpm.jsonc, include/<name>/<name>.hpp, tests/<name>.test.cpp, .gitignore |
The generated cpm.jsonc carries comments that explain each field and the conventions. The executable template shows the core/entrypoint split (manifest.md §4): greeting.cpp is shared by the executable and the test. The C++ templates only use C++11, so they build with every std. .gitignore contains cpm_modules/, /build/ and compile_commands.json. If a .gitignore already exists, missing lines are appended to it.
Afterwards CPM lists the files it created and the ones it kept, and prints the next steps: cd <dir> (if needed), then cpm run (executables) or cpm build, then cpm test.
cpm install
cpm install [<spec>…] [-D] [-E] [--frozen-lockfile] [--offline | --prefer-offline]
[--registry <name|url>] [--profile <name> | --release] [--no-build]
aliases: i, add
Without specs, CPM installs everything in the manifest. With specs, it adds or updates those dependencies (dependencies.md §1.4).
| Option | Description |
|---|---|
-D, --save-dev |
Write new specs to devDependencies. |
-E, --save-exact |
Write the exact version instead of ^<version> for bare names. |
--frozen-lockfile |
Fail if the lockfile is not fresh. Never writes the manifest or the lockfile. Not allowed together with specs. |
--offline |
Use only the caches and the store. Fail on anything that needs the network. |
--prefer-offline |
Use cached index documents of any age, and fetch only what is missing. |
--registry <name|url> |
Registry for the registry specs given on this command line; they are written in the object form { "version": …, "registry": … }. |
--profile <name>, --release |
Prepare binaries for this profile's ABI. Default debug. |
--no-build |
Resolve, fetch and link headers, and use prebuilt binaries the registry offers, but build nothing from source. cpm build builds what is missing later. |
--cxx <compiler> |
Compiler whose ABI the dependency binaries are built for (build.md §1.1). |
A spec is a registry package (fmt adds ^<newest release>, or the exact version with -E; fmt@~10.1 keeps the range as typed), a path (../mylib, file:../mylib), a git URL (git+https://host/repo.git#v1.2.0, github:owner/repo#v1.2.0), or a path or git spec prefixed with a name (mylib@file:../mylib). A path or git spec without a name takes the name from the package's own cpm.jsonc; a package without one must be added by hand with a manifest overlay. Relative paths are resolved against the current directory and written relative to the project root. --offline and --prefer-offline exclude each other.
After a successful install CPM reports every manifest edit (Updated cpm.jsonc: dependencies "mylib": "file:../mylib") and every package change: + added, - removed, ~ changed version or source.
Pipeline (each step is reported):
- Load the manifest and the lockfile, and parse the specs.
- Resolve (dependencies.md §4), skipped when the lock is fresh and no specs were given.
- Fetch missing sources into the store, verifying integrity (store.md).
- Ensure binaries for the selected ABI: a prebuilt binary if available, otherwise a source build (build.md §5).
- Link
cpm_modules/, remove stale package directories, and write.cpm-modules.json. - Only after every earlier step succeeds: apply the manifest edits (manifest.md §10), then write
cpm-lock.json.
If a step fails, the manifest and the lockfile stay untouched. Store entries that were completed are kept, since they are valid cache content.
cpm remove
cpm remove <name>… [--offline] [--profile <name> | --release] [--cxx <compiler>]
aliases: rm, uninstall
Removes the named packages from dependencies and devDependencies, then re-runs the install pipeline with every remaining lock entry pinned (dependencies.md §4.5). Naming a package that is not a direct dependency is an error. Store entries are never deleted (store.md §8).
cpm build
cpm build [--profile <name> | --release] [-j <n>] [--tests] [--cxx <compiler>] [--clean]
Builds the root package (build.md). If the lockfile is stale or cpm_modules is out of date, it installs first and says so.
| Option | Description |
|---|---|
--profile <name> |
Profile to build (default debug). |
--release |
Same as --profile release. |
-j, --jobs <n> |
Parallel jobs passed to Ninja (default: Ninja's default). |
--tests |
Also build the test executables. |
--cxx <compiler> |
Compiler override (build.md §1.1). |
--clean |
Delete cpm_modules/.cache/<profile>/ and build/<profile>/ before building. |
On success it prints the profile, the elapsed time, and the main output path, for example build/debug/hello.exe (build.md §4.1).
cpm run
cpm run [<script>] [--profile <name> | --release] [-j <n>] [--cxx <compiler>] [-- <args>…]
With
<script>: runsscripts.<script>from the manifest through the system shell, in the project root, without building first. The arguments after--reach the script exactly as given:- Windows:
%COMSPEC%(normallycmd.exe) runs/d /s /c "<script> <args>". Each argument is quoted with C runtime rules and then has cmd's metacharacters( ) ! ^ " < > & |escaped with^.%cannot be escaped on a cmd command line, so%NAME%inside an argument is still expanded. - POSIX:
/bin/sh -c '<script> "$@"' sh <args>, so the shell never re-parses the arguments.
A name that is not defined in
scriptsis an error, which lists the defined scripts.- Windows:
Without
<script>: builds the root package and runs it with the arguments after--, in the current directory (like any program the user runs). A package that is not an executable is an error before anything is built.Both: stdin, stdout and stderr are inherited, and the exit code becomes CPM's. While the child runs, CPM ignores Ctrl-C and leaves it to the child. A child that ends because of Ctrl-C makes CPM exit with 130.
Environment (scripts and the executable): the inherited environment, plus:
| Variable | Value |
|---|---|
PATH |
prefixed with build/<profile> and the directory of the running cpm |
CPM_PROJECT_ROOT |
absolute project root |
CPM_PROFILE |
active profile name |
CPM_PACKAGE_NAME, CPM_PACKAGE_VERSION |
from the manifest |
CPM_BIN_DIR |
build/<profile>, absolute |
CPM_EXE |
absolute path of the running cpm |
Paths in these variables use the OS's own separators. pre<script>/post<script> hooks are reserved and not run in v0.1.
cpm test
cpm test [<filter>…] [--profile <name> | --release] [-j <n>] [--timeout <seconds>] [--no-run]
Builds and runs tests/*.test.cpp executables (build.md §7). A filter selects tests whose name contains it. Several filters are ORed. --no-run only builds. Exits with 1 if any test fails.
cpm update
cpm update [<name>…] [--profile <name> | --release] [--cxx <compiler>] [--no-build]
alias: up
Re-resolves without the lockfile's preferences for the named packages (direct or transitive), or for every package when no name is given, so each moves to the newest version its ranges allow. A git dependency on a branch moves to the branch's current commit. The manifest is not changed: to go beyond a range, edit it or run cpm install <name>@<range>. Naming a package that is not in cpm-lock.json is an error. Otherwise the pipeline is cpm install's, including the report of every change.
cpm publish
cpm publish [--registry <name|url>] [--out <dir>] [--dry-run]
Packs the current package and adds its version to a registry (registry.md §6). Without --registry it uses the default registry. A file:// registry is written directly. Any other registry needs --out <dir>, which writes the archive and the updated index document there, to be uploaded to the registry's host. --dry-run runs every check and packs the archive, then lists the files and writes nothing. --with-binary is reserved and currently refused.
cpm setup
cpm setup [--check] [--yes] [--managed]
Makes the machine ready to build: a C++ compiler CPM supports (GCC 13+, Clang 17+, Apple Clang 15+), Ninja 1.10+, and the helpers it drives (git, curl, tar). The one-line installers run it after installing CPM (registry.md §8). It first reports what it finds, then installs what is missing:
| Platform | Compiler | Ninja | git and curl |
|---|---|---|---|
| Windows | WinLibs GCC (MinGW-w64, UCRT), unpacked into $CPM_HOME/tools |
downloaded into $CPM_HOME/tools |
curl comes with Windows; git is not installed, and CPM prints how to get it |
| Linux | the distribution's packages (apt-get, dnf, pacman, zypper, apk, with sudo unless run as root), choosing the newest GCC package the distribution has |
the distribution's package, or downloaded into $CPM_HOME/tools when there is no package manager |
the distribution's packages (with ca-certificates on apt-get, which CPM runs without recommended packages) |
| macOS | Apple's Command Line Tools (xcode-select --install, which asks in a dialog; run cpm setup again afterwards) |
downloaded into $CPM_HOME/tools |
come with macOS and the Command Line Tools |
With apt-get, CPM installs a versioned GCC package such as g++-14 only if apt-cache policy lists that exact package. apt reads a name no package has as a regular expression, so g++-15 could otherwise match unrelated packages like clang-15.
- Pinned downloads. What goes into
$CPM_HOME/toolsis listed, with URLs and SHA-256 checksums, in thetoolchains.jsonof CPM's built-in registry (registry.md §8.2);CPM_TOOLCHAINS_URLreplaces that location. Every download is verified before it is unpacked, unpacked into a staging directory, and moved into place only when complete. - Configuration. When CPM installs a tool into
$CPM_HOME/tools, or chooses a compiler that is not the first one onPATH(such asg++-14), it records it in$CPM_HOME/config.jsonc("cxx","ninja"), editing the file in place so comments survive. Tools that are already usable are left alone. - Before changing anything CPM lists the commands it will run and the downloads with their sizes, and asks.
--yesanswers yes (for scripts and CI).--checkonly reports, and exits with 1 if anything is missing. --managedinstalls the tools CPM can provide into$CPM_HOME/tools(on Windows the compiler and Ninja, elsewhere Ninja) even when usable ones are already installed, and points the configuration at them.- Last, CPM checks the result the way a build would use it: it probes the compiler, checks that it accepts
-std=c++23, and runsninja --version.
cpm login, cpm logout, cpm whoami
cpm login [--registry <name|url>] [--with-token]
cpm logout [--registry <name|url>]
cpm whoami [--registry <name|url>]
For registry services (registry.md §7); the default registry unless --registry is given. cpm login signs in with GitHub's device flow: it prints a code and a URL, opens the URL in a browser when it can, waits for the user to approve, and saves the token in $CPM_HOME/credentials.json. --with-token reads a token from standard input instead (for CI, with a token created on the service's website). cpm logout revokes the token on the service and removes it locally. cpm whoami prints the signed-in account.
cpm yank
cpm yank <name>@<version> [--undo] [--registry <name|url>]
Marks a published version as yanked, or with --undo reverses that (registry.md §7.4). Needs cpm login and ownership of the package.
cpm owner
cpm owner list <name> [--registry <name|url>]
cpm owner add <name> <github-login> [--registry <name|url>]
cpm owner remove <name> <github-login> [--registry <name|url>]
Lists or changes the owners of a package on a registry service. Changing them needs ownership.
Reserved command names (post-MVP)
outdated, info, why, store (prune, status), clean, fmt, workspace.
4. Output
Normative:
- CPM's status messages, warnings, errors and the build tool's output go to stderr.
- stdout is reserved for requested data:
--version,--help, and the output of programs and scripts started bycpm run/cpm test -v.cpm runcan therefore be used in pipes. - Diagnostics follow architecture.md §5.
Non-normative, recommended style (status verb right-aligned to 12 columns, bold green when colour is on):
$ cpm i fmt
Resolving 2 packages
Downloading fmt@10.2.1 (412 KiB)
Building fmt@10.2.1 from source (abi 3f9a1c2b7d4e5a60)
Linked 2 packages into cpm_modules
dependencies:
+ fmt 10.2.1
devDependencies:
+ doctest 2.4.11 (header-only)
Done in 6.2s
$ cpm build
Compiling hello v0.1.0 (debug, gcc 13.2.0)
[4/4] LINK build/debug/hello.exe
Finished debug in 1.21s → build/debug/hello.exe
Progress lines that rewrite themselves (\r) are used only when stderr is a terminal.
5. Configuration
User configuration lives in $CPM_HOME/config.jsonc (JSONC, optional):
{
"registries": {
"default": "https://registry.example.org/cpm/",
"internal": { "url": "file:///C:/registries/internal/", "allowHttp": false }
},
"cxx": "g++", // compiler (build.md §1.1)
"ninja": "C:/tools/ninja.exe", // otherwise CPM_NINJA, then PATH
"jobs": 0, // 0 = Ninja's default
"color": "auto",
"linkMode": "auto" // auto | symlink | junction | copy (store.md §6)
}
- A registry value is a URL string or an object
{ "url", "allowHttp" }. Tokens for registry services are not part of the configuration:cpm loginkeeps them in$CPM_HOME/credentials.json(registry.md §7.2), soconfig.jsonccan be shared safely. - Built-in default: when no
defaultregistry is configured andCPM_REGISTRYis unset, CPM uses the URL built into it (src/install/default_registry.hpp). Since 0.2 that is the public registry servicehttps://cpm-registry.com/. - Unknown keys warn. Precedence for each setting: command-line option > environment variable >
config.jsonc> built-in default.
6. Environment variables
| Variable | Effect |
|---|---|
CPM_HOME |
CPM home directory (store.md §1) |
CPM_REGISTRY |
URL that overrides the default registry |
CPM_TOOLCHAINS_URL |
URL of the toolchains.json that cpm setup reads (default: the built-in registry's) |
CPM_NINJA |
Path to ninja |
CXX |
Compiler (build.md §1.1) |
CPM_KEEP_SANDBOX |
1 keeps failed dependency-build sandboxes for inspection |
CPM_LOG |
debug or trace: internal diagnostics on stderr |
NO_COLOR |
Turns colour off (same as --color never) unless --color always is given |
Variables CPM sets for child processes: CPM_PROJECT_ROOT, CPM_PROFILE, CPM_PACKAGE_NAME, CPM_PACKAGE_VERSION, CPM_BIN_DIR, CPM_EXE (scripts), plus CPM_TEST=1 (tests).
From CPM's repository: docs/spec/cli.md