cpm (C++ Project Manager) is a command-line tool designed to simplify the creation, building, and management of C++ projects using CMake. It provides a streamlined workflow for common development tasks, including project scaffolding, dependency management, and automated code generation.
- Project Creation: Quickly scaffold new C++ projects with a standard directory structure, including
src/andassets/directories. - Dependency Management: Declare Git-based dependencies in a
package.tomlfile, whichcpmautomatically fetches and integrates into your CMake build. - Automated Builds: Generates
CMakeLists.txtbased on yourpackage.tomland handles the entire CMake build process. - Resource Management: Embed assets (images, shaders, etc.) directly into your executable and access them through a simple, generated API.
- Code Generation: Generate boilerplate for new C++ classes, structs, blank headers, or source file pairs.
- All-in-One Testing: A single command to create the test harness (if needed), build, and run your tests using Google Test.
- LSP Support: Automatically generates
compile_commands.jsonfor improved Language Server Protocol (LSP) support in editors.
You can install cpm by running the following command in your terminal:
curl -sSL https://raw.githubusercontent.com/0xThurling/cpm/main/install.sh | bashThis will download and run the install.sh script, which will install the cpm binary in /usr/local/bin.
- Download the latest binary for your platform from the releases page.
- Make the binary executable:
chmod +x cpm
- Move the binary to a directory in your
PATH. For example:# For macOS and Linux sudo mv cpm /usr/local/bin/
- macOS (x64, arm64)
- Linux (x64)
Creates a new C++ project with a standard directory structure.
Generates CMakeLists.txt and builds the project.
If a script_name is provided, it will run the corresponding script from the package.toml file. If no scripts are defined, it will build and run the project.
Displays a summary of the project's configuration.
Displays a tree-like structure of the project's files and directories.
Displays some statistics about the project.
Lists the project's dependencies and their versions.
Lists all the scripts in the project.
Builds and runs tests. It will automatically set up Google Test if not present.
Removes the build/ directory.
Embeds a resource file into the executable.
Generates boilerplate code.
class <ClassName>: Creates a class.struct <StructName>: Creates a struct.header <FileName>: Creates a header file.source <FileName>: Creates a header and source file.
[project]
name = "my_project"
type = "executable"
[dependencies]
# Example:
# sdl = { git = "https://github.com/libsdl-org/SDL.git", tag = "release-2.30.3", target="SDL2::SDL2" }
[resources]
files = [
# "assets/icon.png",
# "assets/shader.glsl"
]files: A list of file paths for assets you want to embed in your project via thecpm embedcommand.
- You can define custom scripts in your
package.tomlfile that can be run withcpm run <script_name>. pre-build: This script will be run before the build process starts.post-build: This script will be run after the build process has finished successfully.
[scripts]
pre-build = "echo pre-build"
post-build = "echo post-build"cpm offers experimental support for Conan, a C++ package manager, allowing you to integrate third-party libraries seamlessly.
To add Conan packages, create a [conan-dependencies] section in your package.toml file. Specify each package and its version in the format package_name = "version".
For example:
[conan-dependencies]
fmt = "10.2.1"After adding your dependencies, you can run cpm install, cpm build, or cpm run. These commands will automatically detect the changes in package.toml, fetch the specified Conan packages, and configure your CMake project to use them.
Contributions are welcome! Please feel free to open issues or submit pull requests.
This project is licensed under the MIT License.