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 | bashThis 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 --versionNOTE: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 runcpm 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.ccpm.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
| Format | Example | Description |
|---|---|---|
| github:owner/repo | github:nlohmann/json | Latest default branch |
| github:owner/repo@tag | github:fmtlib/fmt@10.2.1 | Pinned version |
| github:owner/repo@branch | github:owner/repo@main | Specific branch |
Commands
cpm init <name>Create a new C/C++ projectcpm installInstall all dependencies from cpm.tomlcpm buildCompile the projectcpm build -sProduction build — optimized + portable bundle in dist/cpm runInstall + build + run in one commandcpm run file.cppCompile and run a single file (no project needed)cpm startRun the already-built binarycpm add <pkg>Add a package, e.g. cpm add github:nlohmann/jsoncpm remove <name>Remove a package by namecpm updateRe-download all dependenciescpm listShow installed packagescpm setupInstall the Nix backendcpm --versionShow cpm versionDependencies
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 flagsBuild & Run
Development
cpm run # install + build + run
cpm build # compile only
cpm start # run existing binaryProduction build
cpm build -sProduces a dist/ folder:
dist/
├── myapp ← optimized, stripped binary
├── lib*.so ← bundled shared libraries
└── run.sh ← portable launcherCopy 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.hppFAQ
cpm is open source — MIT LicenseContribute on GitHub