2 stable releases
new 1.0.7 | Mar 14, 2025 |
---|
#67 in Build Utils
385KB
7.5K
SLoC
CForge
A TOML-based build system for C/C++ projects with seamless CMake and vcpkg integration.
๐ Table of Contents
- Features
- Installation
- Quick Start
- Command Reference
- Workspace Commands
- Advanced Configuration
- Build Variants
- Cross-Compilation
- IDE Integration
- Scripts & Hooks
- Examples
- Troubleshooting
- Contributing
- License
๐ Features
- ๐ Simple TOML Configuration: Easy project setup without complex CMake syntax.
- ๐ Multi-platform: Supports Windows, macOS, Linux.
- ๐ฆ Dependency Management: Integrated support for
vcpkg
,Conan
, Git, and custom dependencies. - ๐๏ธ Workspaces: Manage multiple projects together.
- ๐ฏ Cross-compilation: Android, iOS, Raspberry Pi, WebAssembly.
- ๐งฐ IDE Integration: VS Code, CLion, Xcode, Visual Studio.
- ๐งช Testing: Integrated with CTest.
- ๐ Custom Scripts: Run project-specific tasks.
- โ๏ธ Automatic Tool Setup: Installs missing tools automatically.
- ๐ Enhanced Diagnostics: Clear, informative compiler errors.
๐ฅ Installation
From Cargo
cargo install cforge
From Source
git clone https://github.com/ChaseSunstrom/cforge.git
cd cforge
cargo build --release
cargo install --path .
Prerequisites
- Rust
- CMake (โฅ3.15)
- C/C++ Compiler (GCC, Clang, MSVC)
- Optional: Ninja, Make, or Visual Studio Build Tools
โก Quick Start
cforge init
cforge build
cforge run
๐ ๏ธ Command Reference
Command | Description | Example |
---|---|---|
init |
Create new project/workspace | cforge init --template lib |
build |
Build the project | cforge build --config Release |
clean |
Clean build artifacts | cforge clean |
run |
Run built executable | cforge run -- arg1 arg2 |
test |
Execute tests (CTest integration) | cforge test --filter MyTest |
install |
Install project binaries | cforge install --prefix /usr/local |
deps |
Manage dependencies | cforge deps --update |
script |
Execute custom scripts | cforge script format |
startup |
Manage workspace startup project | cforge startup my_app |
ide |
Generate IDE project files | cforge ide vscode |
package |
Package project binaries | cforge package --type zip |
list |
List variants, configs, or targets | cforge list variants |
๐ Workspace Commands
cforge init --workspace
cforge build <project>
cforge run <project>
cforge clean <project>
cforge startup <project>
cforge startup --list
โ๏ธ Advanced Configuration
Example cforge.toml
:
[project]
name = "my_project"
version = "0.1.0"
description = "My C/C++ project"
type = "executable"
language = "c++"
standard = "c++17"
[build]
build_dir = "build"
default_config = "Debug"
generator = "Ninja"
[build.configs.Debug]
defines = ["DEBUG", "_DEBUG"]
flags = ["NO_OPT", "DEBUG_INFO"]
[dependencies.vcpkg]
enabled = true
packages = ["fmt", "boost"]
[targets.default]
sources = ["src/**/*.cpp"]
include_dirs = ["include"]
links = ["fmt"]
๐ฉ Build Variants
Define variants to optimize builds:
[variants]
default = "standard"
[variants.variants.standard]
description = "Standard build"
[variants.variants.performance]
description = "Optimized build"
defines = ["HIGH_PERF=1"]
flags = ["OPTIMIZE_MAX", "LTO"]
๐ Cross-Compilation
Examples:
cforge build --target android-arm64
cforge build --target wasm
๐ฅ๏ธ IDE Integration
Generate IDE-specific files:
cforge ide vscode
cforge ide clion
cforge ide xcode
cforge ide vs2022
๐ Scripts & Hooks
Define scripts and hooks in cforge.toml
:
[scripts]
scripts = {
"format" = "clang-format -i src/*.cpp include/*.h"
}
[hooks]
pre_build = ["echo Building..."]
post_build = ["echo Done!"]
Run scripts:
cforge script format
๐งฉ Examples
Simple Project:
cforge init
cforge build
cforge run
External Dependencies:
# Add dependencies in cforge.toml
cforge deps
cforge build
cforge run
Multi-project Workspace:
cforge init --workspace
# Initialize individual projects
cforge build
cforge run app1
๐ง Troubleshooting
- CMake not found: Ensure it's installed and in PATH.
- Dependency failures: Run
cforge deps --update
. - Cross-compilation: Check environment variables (e.g.,
$ANDROID_NDK
). - Compiler errors: Use
cforge build --verbosity verbose
.
๐ค Contributing
Contributions welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature
) - Commit your changes (
git commit -m 'Add new feature'
) - Push to your branch (
git push origin feature/new-feature
) - Open a Pull Request
๐ License
MIT License โ see LICENSE.
Dependencies
~5โ14MB
~165K SLoC