cpm — C/C++ Package Manager

A fast, isolated package manager for C and C++ projects. Like uv for Python, but for C++.

Installation

One-line install (Linux)

curl -fsSL https://raw.githubusercontent.com/Rana718/cpm/main/install.sh | bash

This installs system build tools (cmake, ninja, g++), Nix for isolated builds, and the cpm binary to /usr/local/bin/.

From source

git clone https://github.com/Rana718/cpm.git
cd cpm
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . -j$(nproc)
sudo cp cpm /usr/local/bin/

Verify

cpm --version
NOTE:cpm requires Linux x86_64, git, curl, and Nix (auto-installed).

Quick Start

# Create a new project
mkdir myapp && cd myapp
cpm init myapp

# Add a dependency
cpm add github:nlohmann/json

# Build and run
cpm run

cpm init creates a project with a cpm.toml, main.cpp, and editor support via compile_commands.json.

Run a single file

# No project needed — uses system g++
cpm run hello.cpp
cpm run test.c

cpm.toml

The project manifest — equivalent to package.json or pyproject.toml.

[project]
name = "myapp"
version = "0.1.0"
cpp_standard = "20"    # 11, 14, 17, 20, 23, 26
compiler = "gcc-13"    # optional: gcc, gcc-13, clang-17
entry = "main.cpp"
output = "myapp"

[scripts]
start = "./myapp"

[dependencies]
# Header-only libraries (fast — just clones the repo)
json = "github:nlohmann/json@v3.11.3"
fmt  = "github:fmtlib/fmt"            # latest tag

[system-dependencies]
# Compiled libraries (built inside nix-shell)
hiredis = "github:redis/hiredis"
seastar = "github:scylladb/seastar"

Dependency formats

FormatExampleDescription
github:owner/repogithub:nlohmann/jsonLatest default branch
github:owner/repo@taggithub:fmtlib/fmt@10.2.1Pinned version
github:owner/repo@branchgithub:owner/repo@mainSpecific branch

Commands

cpm init <name>Create a new C/C++ project
cpm installInstall all dependencies from cpm.toml
cpm buildCompile the project
cpm build -sProduction build — optimized + portable bundle in dist/
cpm runInstall + build + run in one command
cpm run file.cppCompile and run a single file (no project needed)
cpm startRun the already-built binary
cpm add <pkg>Add a package, e.g. cpm add github:nlohmann/json
cpm remove <name>Remove a package by name
cpm updateRe-download all dependencies
cpm listShow installed packages
cpm setupInstall the Nix backend
cpm --versionShow cpm version

Dependencies

Header-only libraries

These are git-cloned and symlinked into .cpm/include/. Fast — no compilation. Add under [dependencies].

[dependencies]
json = "github:nlohmann/json@v3.11.3"
fmt  = "github:fmtlib/fmt"

Compiled / system libraries

Built from source inside nix-shell. Provides correct compiler + all system deps. Add under [system-dependencies].

[system-dependencies]
hiredis = "github:redis/hiredis"
seastar = "github:scylladb/seastar"
TIP:Not sure which to use? If the library is header-only (e.g. nlohmann/json, Eigen, spdlog) use [dependencies]. If it needs to be compiled (hiredis, grpc, seastar) use [system-dependencies].

Where files go

.cpm/
├── include/        ← symlinked headers
├── lib/            ← compiled .so files
├── lib-static/     ← compiled .a files
├── packages/       ← cloned repos
└── defines.txt     ← compiler flags

Build & Run

Development

cpm run          # install + build + run
cpm build        # compile only
cpm start        # run existing binary

Production build

cpm build -s

Produces a dist/ folder:

dist/
├── myapp       ← optimized, stripped binary
├── lib*.so     ← bundled shared libraries
└── run.sh      ← portable launcher

Copy dist/ to any Linux server and run ./dist/run.sh.

Multi-file projects

Put additional source files in a src/ directory. cpm automatically picks them up.

myapp/
├── cpm.toml
├── main.cpp
└── src/
    ├── server.cpp
    └── handlers.hpp

FAQ

cpm is open source — MIT LicenseContribute on GitHub