ccgo
A cross-platform C++ build system designed to simplify and accelerate multi-platform development.
Features
- ๐ Fast cross-platform C++ builds for Android, iOS, macOS, Windows, Linux, and OpenHarmony (OHOS)
- ๐๏ธ Kotlin Multiplatform (KMP) support
- ๐ฆ Conan C/C++ package manager integration
- ๐๏ธ Conditional compilation with Features system (similar to Cargo)
- ๐งช Integrated testing with GoogleTest
- ๐ Benchmarking support with Google Benchmark
- ๐ Documentation generation
- ๐ ๏ธ Project scaffolding from templates
- โ Environment dependency checking
- ๐งน Smart build artifact cleaning
Installation
# Install from PyPI (pre-built binaries)
# Or install from crates.io
# Or build from source
# Binary will be at target/release/ccgo
Quick Start
# Create a new C++ library project
# Navigate to the project directory
# Build for Android
# Run tests
# Build documentation
Commands Reference
1. Project Creation
ccgo new - Create New Project
Create a new library project in a new directory.
Options:
--template-url <url>- Custom template repository URL--data <key>=<value>- Template variables (repeatable)--defaults- Use default values for all prompts
Examples:
# Create with interactive prompts
# Create with all defaults
# Use custom template
# Set template variables
ccgo init - Initialize in Current Directory
Initialize a library project in the current directory.
Options:
--template-url <url>- Custom template repository URL--data <key>=<value>- Template variables (repeatable)--defaults- Use default values for all prompts--force- Skip confirmation prompt
Examples:
2. Build Commands
ccgo build - Build for Platforms
Build your library for specific platforms.
Targets:
android- Build for Android (supports--arch)ios- Build for iOSmacos- Build for macOSwindows- Build for Windowslinux- Build for Linuxohos- Build for OpenHarmony (supports--arch)kmp- Build Kotlin Multiplatform libraryconan- Build Conan C/C++ packageinclude- Build include headers
Options:
--arch <architectures>- Comma-separated architecture list (Android/OHOS only)- Android:
armeabi-v7a,arm64-v8a,x86_64 - OHOS:
armeabi-v7a,arm64-v8a,x86_64
- Android:
--link-type <type>- Library link type:static,shared, orboth(default:both)--toolchain <toolchain>- Windows toolchain:auto,msvc, ormingw(default:auto)--ide-project- Generate IDE project files--docker- Build using Docker (cross-platform builds)-F, --features <features>- Comma-separated list of features to enable--no-default-features- Disable default features--all-features- Enable all available features
Examples:
# Build for Android with specific architectures
# Build for OHOS with all architectures
# Build for iOS
# Build for macOS
# Build for Windows
# Build for Windows with specific toolchain
# Build for Linux
# Build static libraries only
# Build shared libraries only
# Build both static and shared libraries (default)
# Build Kotlin Multiplatform library
# Build Conan C/C++ package
# Generate IDE project for Android
# Cross-platform build using Docker
# Build with specific features enabled
# Build without default features
# Build with all features enabled
3. Testing & Benchmarking
ccgo test - Run Tests
Build and run GoogleTest-based unit tests.
Options:
--build-only- Only build tests without running--run-only- Only run tests (assumes already built)--filter <pattern>- GoogleTest filter (e.g., 'MyTest*')--ide-project- Generate IDE project for tests--gtest-args <args>- Additional GoogleTest arguments
Examples:
# Build and run all tests
# Only build tests
# Run specific tests
# Run tests multiple times
# Generate IDE project for debugging tests
ccgo bench - Run Benchmarks
Build and run Google Benchmark-based performance benchmarks.
Options:
--build-only- Only build benchmarks without running--run-only- Only run benchmarks (assumes already built)--filter <pattern>- Google Benchmark filter (e.g., 'BM_Sort*')--ide-project- Generate IDE project for benchmarks--benchmark-args <args>- Additional Google Benchmark arguments--format <format>- Output format:console,json,csv(default: console)
Examples:
# Build and run all benchmarks
# Only build benchmarks
# Run specific benchmarks
# Output results as JSON
# Output results as CSV
4. Documentation
ccgo doc - Build Documentation
Generate project documentation (typically using Doxygen).
Options:
--open- Open documentation in browser after building--serve- Start local web server to view documentation--port <port>- Port for web server (default: 8000)--clean- Clean build before generating
Examples:
# Build documentation
# Build and open in browser
# Build and serve on localhost:8000
# Serve on custom port
# Clean build
5. Publishing
ccgo publish - Publish Libraries
Publish your library to package repositories.
Targets:
android- Publish to Maven repositoryohos- Publish to OHPM repositorykmp- Publish KMP library to Maven (local or remote)
Examples:
# Publish Android library to Maven
# Publish OHOS library to OHPM
# Publish Kotlin Multiplatform library
6. Maintenance Commands
ccgo check - Check Dependencies
Verify that platform-specific development dependencies are installed.
Targets:
all- Check all platforms (default)android- Check Android development environmentios- Check iOS development environmentmacos- Check macOS development environmentwindows- Check Windows development environmentlinux- Check Linux development environmentohos- Check OpenHarmony development environment
Options:
--verbose- Show detailed information
Examples:
# Check all platforms
# Check Android environment
# Check with verbose output
ccgo clean - Clean Build Artifacts
Remove build artifacts and caches.
Targets:
all- Clean all platforms (default)android- Clean Android build cachesios- Clean iOS build cachesmacos- Clean macOS build cachesohos- Clean OpenHarmony build cacheskmp- Clean Kotlin Multiplatform build cachesexamples- Clean examples build caches
Options:
--native-only- Clean onlycmake_build/(native CMake builds)--dry-run- Show what would be cleaned without deleting-y, --yes- Skip confirmation prompts
Examples:
# Clean all (with confirmation)
# Clean only Android
# Preview what will be deleted
# Clean all without confirmation
# Clean only native CMake builds
7. Help
ccgo help - Show Help
Display comprehensive help information.
# Or get help for specific command
Environment Variables
Android
ANDROID_HOME- Android SDK locationANDROID_NDK_HOME- Android NDK locationJAVA_HOME- Java Development Kit location
OpenHarmony (OHOS)
OHOS_SDK_HOMEorHOS_SDK_HOME- OHOS Native SDK location
iOS/macOS
- Requires Xcode and command-line tools
Project Structure
Projects created with ccgo follow this structure:
my-project/
โโโ CCGO.toml # CCGO project config
โโโ CMakeLists.txt # Root CMake configuration
โโโ src/ # Source code
โโโ include/ # Public headers
โโโ docs/ # docs files
โโโ tests/ # GoogleTest unit tests
โโโ benches/ # Benchmark tests
โโโ android/ # Android-specific files (Gradle)
โโโ ohos/ # OHOS-specific files (hvigor)
โโโ kmp/ # Kotlin Multiplatform files (Gradle)
SDK Archive Structure
When you run ccgo build <target>, the output is placed in target/{debug|release}/<platform>/ with a unified archive structure.
Archive Naming Convention
{PROJECT}_{PLATFORM}_SDK-{version}[-{suffix}].zip # Main SDK archive
{PROJECT}_{PLATFORM}_SDK-{version}[-{suffix}]-SYMBOLS.zip # Debug symbols archive
Examples:
MYLIB_ANDROID_SDK-1.0.0-release.zipMYLIB_IOS_SDK-1.0.0-beta.5-dirty.zipMYLIB_LINUX_SDK-2.1.0-SYMBOLS.zip
Unified SDK Archive Structure
All platforms follow the same archive structure:
{PROJECT}_{PLATFORM}_SDK-{version}.zip
โโโ lib/{platform}/
โ โโโ static/ # Static libraries (.a, .lib)
โ โ โโโ [{arch}/] # Architecture subdirectory (if multi-arch)
โ โ โโโ lib{name}.a
โ โโโ shared/ # Shared libraries (.so, .dylib, .dll)
โ โโโ [{arch}/]
โ โโโ lib{name}.so
โโโ include/{project}/ # Public header files
โ โโโ **/*.h
โโโ haars/{platform}/ # Platform packages (Android AAR / OHOS HAR)
โ โโโ {PROJECT}_{PLATFORM}_SDK-{version}.aar
โโโ meta/{platform}/ # Metadata files
โโโ build_info.json # Build information
โโโ archive_info.json # Archive file listing
Platform-Specific Build Artifacts
Android
Output: target/{debug|release}/android/
| File | Description |
|---|---|
MYLIB_ANDROID_SDK-{version}.zip |
Main SDK archive |
MYLIB_ANDROID_SDK-{version}-SYMBOLS.zip |
Debug symbols (unstripped .so) |
MYLIB_ANDROID_SDK-{version}.aar |
Android Archive (standalone) |
SDK Contents:
โโโ lib/android/static/{arch}/lib{name}.a
โโโ lib/android/shared/{arch}/lib{name}.so
โโโ include/{project}/**/*.h
โโโ haars/android/*.aar
โโโ meta/android/build_info.json
iOS
Output: target/{debug|release}/ios/
| File | Description |
|---|---|
MYLIB_IOS_SDK-{version}.zip |
Main SDK archive |
MYLIB_IOS_SDK-{version}-SYMBOLS.zip |
Debug symbols (dSYM) |
SDK Contents:
โโโ lib/ios/static/{name}.xcframework/
โโโ lib/ios/shared/{name}.xcframework/
โโโ include/{project}/**/*.h
โโโ meta/ios/build_info.json
Architectures: arm64 (device), arm64-simulator, x86_64-simulator
macOS
Output: target/{debug|release}/macos/
| File | Description |
|---|---|
MYLIB_MACOS_SDK-{version}.zip |
Main SDK archive |
MYLIB_MACOS_SDK-{version}-SYMBOLS.zip |
Debug symbols (dSYM) |
SDK Contents:
โโโ lib/macos/static/{name}.xcframework/
โโโ lib/macos/shared/{name}.xcframework/
โโโ include/{project}/**/*.h
โโโ meta/macos/build_info.json
Architectures: Universal binary (arm64 + x86_64)
tvOS
Output: target/{debug|release}/tvos/
SDK Contents:
โโโ lib/tvos/static/{name}.xcframework/
โโโ lib/tvos/shared/{name}.xcframework/
โโโ include/{project}/**/*.h
โโโ meta/tvos/build_info.json
Architectures: arm64 (device), arm64-simulator
watchOS
Output: target/{debug|release}/watchos/
SDK Contents:
โโโ lib/watchos/static/{name}.xcframework/
โโโ lib/watchos/shared/{name}.xcframework/
โโโ include/{project}/**/*.h
โโโ meta/watchos/build_info.json
Architectures: arm64_32, armv7k (device), arm64-simulator
Linux
Output: target/{debug|release}/linux/
| File | Description |
|---|---|
MYLIB_LINUX_SDK-{version}.zip |
Main SDK archive |
MYLIB_LINUX_SDK-{version}-SYMBOLS.zip |
Debug symbols (unstripped .so) |
SDK Contents:
โโโ lib/linux/static/lib{name}.a
โโโ lib/linux/shared/lib{name}.so
โโโ include/{project}/**/*.h
โโโ meta/linux/build_info.json
Architecture: x86_64
Windows
Output: target/{debug|release}/windows/
| File | Description |
|---|---|
MYLIB_WINDOWS_SDK-{version}.zip |
Main SDK archive |
SDK Contents (MinGW):
โโโ lib/windows/static/lib{name}.a
โโโ lib/windows/shared/{name}.dll
โโโ lib/windows/shared/lib{name}.dll.a # Import library
โโโ include/{project}/**/*.h
โโโ meta/windows/build_info.json
SDK Contents (MSVC):
โโโ lib/windows/static/{name}.lib
โโโ lib/windows/shared/{name}.dll
โโโ lib/windows/shared/{name}.lib # Import library
โโโ include/{project}/**/*.h
โโโ meta/windows/build_info.json
Architecture: x86_64
OpenHarmony (OHOS)
Output: target/{debug|release}/ohos/
| File | Description |
|---|---|
MYLIB_OHOS_SDK-{version}.zip |
Main SDK archive |
MYLIB_OHOS_SDK-{version}-SYMBOLS.zip |
Debug symbols (unstripped .so) |
MYLIB_OHOS_SDK-{version}.har |
Harmony Archive (standalone) |
SDK Contents:
โโโ lib/ohos/static/{arch}/lib{name}.a
โโโ lib/ohos/shared/{arch}/lib{name}.so
โโโ include/{project}/**/*.h
โโโ haars/ohos/*.har
โโโ meta/ohos/build_info.json
Conan
Output: target/{debug|release}/conan/
SDK Contents:
โโโ lib/conan/static/lib{name}.a
โโโ lib/conan/shared/lib{name}.so
โโโ include/{project}/**/*.h
โโโ meta/conan/build_info.json
Metadata Files
build_info.json
Contains build metadata:
archive_info.json
Contains file listing with sizes:
Excluded Files
The following files are automatically excluded from archives:
CPPLINT.cfg.clang-format.clang-tidy
Features System
CCGO supports a features system similar to Cargo's, enabling conditional compilation and optional dependencies. This allows you to:
- Enable/disable parts of your library at build time
- Make dependencies optional and only include them when needed
- Define feature groups that enable multiple sub-features
Defining Features in CCGO.toml
[]
= "mylib"
= "1.0.0"
[]
# Default features enabled when none are specified
= ["std"]
# Feature definitions
= []
= ["http-client"] # Enables optional dependency
= ["networking", "async"] # Enables other features
= ["networking", "advanced", "logging"]
# Dependency feature syntax
= ["serde/derive"] # Enables feature on dependency
[[]]
= "http-client"
= "^1.0"
= true # Only included when enabled by a feature
[[]]
= "async"
= "^2.0"
= true
[[]]
= "serde"
= "^1.0"
= ["std"] # Features to enable on this dependency
= false # Disable dependency's default features
Using Features in Builds
# Build with default features
# Build with specific features
# Build without default features
# Build with specific features, no defaults
# Build with all available features
CMake Integration
Features are passed to CMake as compile definitions with the CCGO_FEATURE_ prefix:
# In your CMakeLists.txt, check for features:
if(DEFINED CCGO_FEATURE_DEFINITIONS)
foreach(def ${CCGO_FEATURE_DEFINITIONS})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${def})
endforeach()
endif()
In your C++ code:
void
Feature Resolution
Features are resolved transitively:
- Default features are enabled unless
--no-default-featuresis specified - Requested features from
--featuresare added - Transitive features are resolved (e.g.,
fullenablesadvancedwhich enablesnetworking) - Optional dependencies are included only if enabled by an active feature
Example resolution for --features full:
full โ advanced, networking, logging
advanced โ networking, async
networking โ http-client (optional dep)
Result: full, advanced, networking, logging, async, http-client are all enabled.
Workspaces
CCGO supports workspaces for managing multiple related packages in a single repository. Workspaces provide:
- Unified dependency management across packages
- Shared configuration and settings
- Single-command builds for all packages
Creating a Workspace
Create a root CCGO.toml with a [workspace] section:
# Root CCGO.toml (workspace root)
[]
= [
"core",
"utils",
"examples/*" # Glob patterns supported
]
= ["examples/deprecated"]
= "2" # Dependency resolver version
# Shared dependencies for workspace members
[[]]
= "fmt"
= "^10.0"
= "https://github.com/fmtlib/fmt.git"
= ["std"]
[[]]
= "spdlog"
= "^1.12"
Workspace Member Configuration
Member packages can inherit dependencies from the workspace:
# core/CCGO.toml
[]
= "my-core"
= "1.0.0"
[[]]
= "fmt"
= true # Inherit from workspace
= ["extra"] # Additional features (merged with workspace)
[[]]
= "spdlog"
= true
Workspace Structure
my-workspace/
โโโ CCGO.toml # Workspace root configuration
โโโ core/
โ โโโ CCGO.toml # Member package
โ โโโ CMakeLists.txt
โ โโโ src/
โโโ utils/
โ โโโ CCGO.toml # Member package
โ โโโ CMakeLists.txt
โ โโโ src/
โโโ examples/
โโโ demo1/
โ โโโ CCGO.toml # Member (matched by glob)
โโโ deprecated/
โโโ CCGO.toml # Excluded member
Workspace with Root Package
A workspace root can also be a package itself (virtual workspace):
[]
= ["crates/*"]
[]
= "my-workspace-root"
= "1.0.0"
Dependency Inheritance
When a member uses workspace = true:
- Version is inherited from workspace if not specified locally
- Git/Path sources are inherited from workspace
- Features are merged (workspace features + local features)
- default_features uses workspace setting if not specified locally
# Workspace defines:
[[]]
= "fmt"
= "^10.0"
= ["std"]
# Member uses:
[[]]
= "fmt"
= true
= ["color"] # Results in: ["std", "color"]
Resolver Versions
resolver = "1"- Legacy resolver (default)resolver = "2"- New resolver with better feature unification across packages
Advanced Usage
Using Custom Templates
You can create projects from custom templates:
# From GitHub repository
# From local directory
CI/CD Integration
The generated build.py script supports CI/CD workflows with environment variables:
CI_IS_RELEASE- Build as release vs betaCI_BUILD_<PLATFORM>- Enable/disable platform builds
Example:
Multi-Architecture Builds
Build for multiple architectures simultaneously:
# Android: build for 32-bit ARM, 64-bit ARM, and x86_64
# OHOS: build for all supported architectures
Troubleshooting
Common Issues
-
"Command not found" after installation
- Ensure
piporcargoinstall directory is in your PATH - For pip: typically
~/.local/bin(Linux/macOS) or%APPDATA%\Python\Scripts(Windows) - For cargo: typically
~/.cargo/bin
- Ensure
-
Android build fails
- Verify
ANDROID_HOME,ANDROID_NDK_HOME, andJAVA_HOMEare set - Run
ccgo check android --verboseto diagnose
- Verify
-
OHOS build fails
- Verify
OHOS_SDK_HOMEorHOS_SDK_HOMEis set - Run
ccgo check ohos --verboseto diagnose
- Verify
-
iOS/macOS build fails
- Ensure Xcode and command-line tools are installed
- Run
xcode-select --installif needed
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
ccgo is available under the MIT license. See the LICENSE file for the full license text.