#build-system #cmake #vcpkg #cpp #compiler-error #visual-studio

build cforge

A TOML-based build system for C/C++ with CMake and vcpkg integration

2 stable releases

new 1.0.7 Mar 14, 2025

#67 in Build Utils

MIT license

385KB
7.5K SLoC

CForge

Version License

A TOML-based build system for C/C++ projects with seamless CMake and vcpkg integration.


๐Ÿ“– Table of Contents

  1. Features
  2. Installation
  3. Quick Start
  4. Command Reference
  5. Workspace Commands
  6. Advanced Configuration
  7. Build Variants
  8. Cross-Compilation
  9. IDE Integration
  10. Scripts & Hooks
  11. Examples
  12. Troubleshooting
  13. Contributing
  14. 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!

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -m 'Add new feature')
  4. Push to your branch (git push origin feature/new-feature)
  5. Open a Pull Request

๐Ÿ“„ License

MIT License โ€” see LICENSE.

Dependencies

~5โ€“14MB
~165K SLoC