百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cforge

> 数据库
开源

一个快速、跨平台且向后兼容的 CMake 构建工具,用于 C 和 C++

188 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个快速、跨平台且向后兼容的 CMake 构建工具,用于 C 和 C++

cforge

A modern C/C++ build tool with Cargo-like simplicity. cforge simplifies C/C++ project management with a clean TOML configuration, automatic dependency resolution, and cross-platform builds. It generates CMake under the hood while providing a much simpler interface.

Quick Start

bash
# Install cforge
curl -fsSL https://raw.githubusercontent.com/ChaseSunstrom/cforge/master/scripts/install.sh | bash

# Create a new project (interactive prompts guide you through setup)
cforge init myapp
cd myapp

# Build and run
cforge build
cforge run

# Or skip prompts with flags
cforge init myapp --template executable --cpp 17 --with-tests --license MIT -y

Features

  • Simple TOML configuration - No CMake syntax required
  • Portable compiler flags - Write once, works on MSVC, GCC, and Clang
  • Package registry - Search and install packages with cforge deps add
  • Multiple dependency sources - Registry, Git, vcpkg, and system libraries
  • Workspaces - Manage multi-project repositories
  • Cross-compilation - Android, iOS, Raspberry Pi, WebAssembly, embedded bare-metal
  • Embedded development - Bare-metal targets with post-build commands, flash/upload
  • IDE integration - VS Code, CLion, Visual Studio, Xcode
  • Testing & benchmarks - Integrated test runner with Catch2, GTest, doctest
  • Developer tools - Formatting, linting, watch mode, documentation
  • Hot reload - Shared library live-swapping for rapid iteration
  • CMake migration - Import existing CMakeLists.txt projects with cforge migrate
  • Lock files - Reproducible builds with exact dependency versions
  • Shell completions - Bash, Zsh, PowerShell, Fish
  • CI integration - GitHub Action for automated builds and caching

Installation

Linux / macOS

bash
curl -fsSL https://raw.githubusercontent.com/ChaseSunstrom/cforge/master/scripts/install.sh | bash

Windows (PowerShell)

powershell
irm https://raw.githubusercontent.com/ChaseSunstrom/cforge/master/scripts/install.ps1 | iex

Prerequisites

  • CMake 3.15+
  • C/C++ compiler (GCC, Clang, or MSVC)

Building from Source

bash
git clone https://github.com/ChaseSunstrom/cforge.git
cd cforge
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
cmake --install build

Shell Completions

bash
cforge completions bash >> ~/.bashrc
cforge completions zsh >> ~/.zshrc
cforge completions fish > ~/.config/fish/completions/cforge.fish
cforge completions powershell >> $PROFILE

Configuration

Projects are configured with a cforge.toml file:

…

Commands Reference

Project Management

Command Description
cforge init [name] Initialize a new project (interactive if no args given)
cforge migrate [path] Import CMakeLists.txt into cforge.toml
cforge new Create files from templates (class, header, interface, test)
cforge build Build the project
cforge run Build and run the project
cforge clean Clean build artifacts
cforge install Install project to system
cforge flash Flash firmware to embedded target
cforge circular Check for circular dependencies

Dependencies

Command Description
cforge deps add Add a dependency
cforge deps remove Remove a dependency
cforge deps search Search package registry
cforge deps info Show package details
cforge deps list List current dependencies
cforge deps tree Visualize dependency tree (with conflict detection)
cforge deps lock Manage lock file for reproducible builds
cforge deps update Update package registry
cforge deps outdated Show dependencies with newer versions

Testing & Quality

Command Description
cforge test Run tests
cforge bench Run benchmarks
cforge fmt Format code with clang-format
cforge lint Static analysis with clang-tidy
cforge doc Generate documentation with Doxygen

Tools & IDE

Command Description
cforge ide Generate IDE project files
cforge watch Watch for changes and auto-rebuild
cforge hot Hot reload session (shared library live-swapping)
cforge package Create distributable packages
cforge cache Manage binary cache
cforge completions Generate shell completions

Other

Command Description
cforge version Show version information
cforge upgrade Upgrade cforge to the latest version
cforge doctor Diagnose environment and check for required tools
cforge help Show help for a command

Project Initialization

Create a New Project

Running cforge init without arguments starts an interactive setup wizard with arrow-key selection:

bash
cforge init                            # Interactive mode (prompts for template, standard, etc.)
cforge init myapp                      # Interactive, project name pre-filled
cforge init myapp -y                   # Accept all defaults (no prompts)
cforge init myapp --template shared-library --cpp 20 --with-tests --license Apache-2.0

All flags skip their corresponding prompt. Available flags:

Flag Description
--template executable, static-lib, shared-library, header-only, embedded
--cpp C++ standard: 11, 14, 17, 20, 23
--with-tests / -t Include test infrastructure
--with-git / -g Initialize git repository
--license MIT, Apache-2.0, GPL-3.0, BSD-2-Clause, None
-y / --yes Accept all defaults without prompting

Create a Workspace

bash
cforge init --workspace myws                    # Create empty workspace
cforge init --workspace myws --projects app lib # Workspace with projects

Generate Code from Templates

bash
cforge new class MyClass                # Create MyClass.hpp and MyClass.cpp
cforge new class MyClass -n myproj      # With namespace
cforge new header utils                 # Create utils.hpp
cforge new interface IService           # Create abstract interface
cforge new test MyClass                 # Create test file
cforge new struct Config                # Create struct header

Building

…

In Workspaces

bash
cforge build                           # Build main project
cforge build -p mylib                  # Build specific project
cforge build --gen-workspace-cmake     # Generate workspace CMakeLists.txt

Running

bash
cforge run                             # Build and run
cforge run -c Release                  # Run release build
cforge run --no-build                  # Run without rebuilding
cforge run -- arg1 arg2                # Pass arguments to executable
cforge run -p myapp -- --config file   # Run specific project with args

Dependencies

Registry Packages

toml
[dependencies]
fmt = "11.1.4"
spdlog = "*"           # Latest version
json = "3.11.2"
bash
cforge deps add fmt                    # Add from registry
cforge deps add fmt@11.1.4             # Specific version
cforge deps add spdlog --features async # With features
cforge deps search json                # Search packages
cforge deps info nlohmann_json         # Package details
cforge deps outdated                   # Check for updates

Git Dependencies

toml
[dependencies.git.imgui]
url = "https://github.com/ocornut/imgui.git"
tag = "v1.89.9"
bash
cforge deps add mylib --git https://github.com/user/mylib --tag v1.0

vcpkg Dependencies

toml
[dependencies.vcpkg]
curl = { version = "7.80.0", features = ["ssl"] }
bash
cforge deps add boost --vcpkg

System Dependencies

toml
[dependencies.system.OpenGL]
method = "find_package"
components = ["GL", "GLU"]

[dependencies.system.gtk3]
method = "pkg_config"
package = "gtk+-3.0"

Lock Files

bash
cforge deps lock                       # Generate/update lock file
cforge deps lock --verify              # Verify deps match lock
cforge deps lock --force               # Force regeneration
cforge deps lock --clean               # Remove lock file

Commit cforge.lock to version control for reproducible builds.

Dependency Tree

bash
cforge deps tree                       # Show dependency tree
cforge deps tree -a                    # Include all details
cforge deps tree -d 2                  # Limit depth
cforge deps tree --check               # Detect version conflicts (exit code 1 if found)
cforge deps tree --format dot          # Graphviz DOT output
cforge deps tree --format dot | dot -Tpng -o deps.png  # Generate graph image

In workspaces, cforge deps tree also shows the inter-project dependency graph and warns about version conflicts across projects.


Portable Compiler Flags

cforge provides portable build options that automatically translate to the correct flags for each compiler:

Option Values Description
optimize "none", "debug", "size", "speed", "aggressive" Optimization level
warnings "none", "default", "all", "strict", "pedantic" Warning level
debug_info true / false Include debug symbols
sanitizers ["address", "undefined", "thread", "leak"] Runtime sanitizers
lto true / false Link-time optimization
exceptions true / false C++ exceptions
rtti true / false Runtime type info
hardening "none", "basic", "full" Security hardening
stdlib "default", "libc++", "libstdc++" Standard library
visibility "default", "hidden" Symbol visibility

Flag Translation

Portable MSVC GCC/Clang
optimize = "speed" /O2 -O2
optimize = "size" /O1 /Os -Os
optimize = "aggressive" /Ox -O3
warnings = "all" /W4 -Wall -Wextra
warnings = "strict" /W4 /WX -Wall -Wextra -Werror
lto = true /GL + /LTCG -flto
debug_info = true /Zi -g
sanitizers = ["address"] /fsanitize=address -fsanitize=address

Platform & Compiler Configuration

toml
# Platform-specific settings
[platform.windows]
hardening = "full"
defines = ["WIN32"]
links = ["ws2_32"]

[platform.linux]
hardening = "basic"
links = ["pthread"]

[platform.macos]
stdlib = "libc++"
frameworks = ["Cocoa"]

# Compiler-specific settings
[compiler.msvc]
warnings = "strict"
defines = ["_CRT_SECURE_NO_WARNINGS"]

[compiler.gcc]
warnings = "pedantic"

[compiler.clang]
flags = ["-fcolor-diagnostics"]

Workspaces

For multi-project repositories:

toml
# workspace.toml or cforge.toml
[workspace]
name = "my-workspace"
projects = ["app", "lib", "tests"]
main_project = "app"
bash
cforge build                           # Build main project
cforge build -p lib                    # Build specific project
cforge build --gen-workspace-cmake     # Generate workspace CMake

Testing

toml
[test]
enabled = true
framework = "catch2"  # or "gtest", "doctest", "boost"
bash
cforge test                            # Run all tests
cforge test -c Release                 # Test release build
cforge test Math                       # Run tests in Math category
cforge test -c Release -- Math Add     # Specific tests
cforge test -v                         # Verbose output

Benchmarks

toml
[benchmark]
directory = "bench"
framework = "google"       # google, nanobench, catch2
auto_link_project = true   # Link project library
bash
cforge bench                           # Run all benchmarks
cforge bench --filter 'BM_Sort'        # Run matching benchmarks
cforge bench --no-build                # Skip rebuild
cforge bench --json > r

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++buildbuild-toolccforge

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库