Project Structure¶
Complete guide to CCGO project organization and directory structure.
Overview¶
CCGO projects follow a standardized structure:
- Source code:
src/for implementation,include/for headers - Tests:
tests/for unit tests - Benchmarks:
benches/for performance tests - Documentation:
docs/for Doxygen/Sphinx docs - Configuration:
CCGO.tomlfor project settings - Build outputs:
target/for compiled binaries
Standard Project Layout¶
myproject/
├── CCGO.toml # Project configuration
├── CMakeLists.txt # CMake configuration (generated)
├── build_config.py # Build-specific settings (generated)
├── .ccgoignore # Files to exclude from CCGO operations
├── README.md # Project documentation
├── LICENSE # License file
├── .gitignore # Git ignore rules
│
├── include/ # Public headers
│ └── myproject/
│ ├── myproject.h # Main header
│ ├── version.h # Version info (generated)
│ └── feature.h # Feature-specific headers
│
├── src/ # Implementation files
│ ├── myproject.cpp # Main implementation
│ ├── feature.cpp # Feature implementations
│ └── internal/ # Private implementation
│ └── utils.cpp
│
├── tests/ # Unit tests
│ ├── test_main.cpp # Test runner
│ ├── test_myproject.cpp # Tests for main module
│ └── test_feature.cpp # Tests for features
│
├── benches/ # Benchmarks
│ ├── bench_main.cpp # Benchmark runner
│ └── bench_performance.cpp # Performance benchmarks
│
├── docs/ # Documentation
│ ├── Doxyfile # Doxygen configuration
│ ├── api/ # API documentation
│ └── guides/ # User guides
│
├── examples/ # Example applications (optional)
│ ├── basic/
│ │ └── main.cpp
│ └── advanced/
│ └── main.cpp
│
├── cmake_build/ # CMake build directory (generated)
│ ├── android/
│ ├── ios/
│ ├── linux/
│ └── windows/
│
└── target/ # Build outputs (generated)
├── android/
├── ios/
├── linux/
└── windows/
Directory Details¶
Root Files¶
CCGO.toml¶
Purpose: Main project configuration file.
Content:
[package]
name = "myproject"
version = "1.0.0"
description = "My C++ project"
[library]
type = "both"
[build]
cpp_standard = "17"
[dependencies]
spdlog = { git = "https://github.com/gabime/spdlog.git", tag = "v1.12.0" }
See: Configuration Guide
CMakeLists.txt¶
Purpose: CMake configuration (auto-generated by CCGO).
Content:
cmake_minimum_required(VERSION 3.20)
project(myproject VERSION 1.0.0)
# CCGO cmake utilities
include(${CCGO_CMAKE_DIR}/CMakeUtils.cmake)
# Add subdirectories
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(benches)
Note: Do not edit manually - regenerated on each build.
build_config.py¶
Purpose: Build-specific settings (auto-generated).
Content:
Usage: Used by build scripts internally.
.ccgoignore¶
Purpose: Exclude files from CCGO operations.
Content:
See: Configuration Guide - .ccgoignore
include/¶
Purpose: Public header files that users of your library will include.
Structure:
include/
└── myproject/ # Namespace directory (required)
├── myproject.h # Main header
├── version.h # Version info (generated)
├── config.h # Configuration (generated)
├── feature_a.h # Feature headers
├── feature_b.h
└── internal/ # Internal headers (not for public use)
└── impl.h
Guidelines:
-
Namespace directory: Always use a subdirectory matching your project name
-
Header guards: Use
#pragma onceor traditional guards -
Version header: Auto-generated with version info
-
Minimize includes: Only include what's necessary
src/¶
Purpose: Implementation files (.cpp, .cc, .cxx).
Structure:
src/
├── myproject.cpp # Main implementation
├── feature_a.cpp # Feature implementations
├── feature_b.cpp
├── internal/ # Private implementation
│ ├── utils.cpp
│ └── platform/ # Platform-specific code
│ ├── android.cpp
│ ├── ios.cpp
│ └── linux.cpp
└── CMakeLists.txt # Generated by CCGO
Guidelines:
-
One class per file: Keep files focused
-
Private headers: Use internal/ for private headers
-
Platform-specific code: Use subdirectories or conditional compilation
tests/¶
Purpose: Unit tests using Catch2 or Google Test.
Structure:
tests/
├── test_main.cpp # Test runner
├── test_myproject.cpp # Tests for main module
├── test_feature_a.cpp # Feature-specific tests
├── test_feature_b.cpp
└── CMakeLists.txt # Generated by CCGO
Example test file:
// test_myproject.cpp
#include <catch2/catch_test_macros.hpp>
#include <myproject/myproject.h>
TEST_CASE("Basic functionality", "[myproject]") {
myproject::MyClass obj;
REQUIRE(obj.get_value() == 42);
}
TEST_CASE("Feature A", "[feature_a]") {
myproject::FeatureA feature;
REQUIRE(feature.is_enabled());
}
Test runner:
Running tests:
benches/¶
Purpose: Performance benchmarks using Google Benchmark.
Structure:
benches/
├── bench_main.cpp # Benchmark runner
├── bench_performance.cpp # Performance benchmarks
├── bench_feature_a.cpp # Feature-specific benchmarks
└── CMakeLists.txt # Generated by CCGO
Example benchmark:
// bench_performance.cpp
#include <benchmark/benchmark.h>
#include <myproject/myproject.h>
static void BM_MyFunction(benchmark::State& state) {
myproject::MyClass obj;
for (auto _ : state) {
obj.do_work();
}
}
BENCHMARK(BM_MyFunction);
BENCHMARK_MAIN();
Running benchmarks:
docs/¶
Purpose: Documentation source files.
Structure:
docs/
├── Doxyfile # Doxygen configuration
├── README.md # Documentation overview
├── api/ # API documentation
│ └── reference.md
├── guides/ # User guides
│ ├── getting-started.md
│ └── advanced.md
└── images/ # Documentation images
└── architecture.png
Generating docs:
examples/¶
Purpose: Example applications showing how to use your library.
Structure:
examples/
├── basic/ # Simple example
│ ├── main.cpp
│ └── CMakeLists.txt
├── advanced/ # Advanced usage
│ ├── main.cpp
│ └── CMakeLists.txt
└── README.md # Examples documentation
Example application:
// examples/basic/main.cpp
#include <myproject/myproject.h>
#include <iostream>
int main() {
myproject::MyClass obj;
std::cout << "Value: " << obj.get_value() << std::endl;
return 0;
}
Building examples:
# examples/basic/CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(basic_example)
find_package(myproject REQUIRED)
add_executable(basic main.cpp)
target_link_libraries(basic myproject::myproject)
cmake_build/¶
Purpose: CMake build artifacts (generated, not committed to git).
Structure:
cmake_build/
├── android/ # Android build files
│ ├── armeabi-v7a/
│ ├── arm64-v8a/
│ └── x86_64/
├── ios/ # iOS build files
│ ├── arm64/
│ └── x86_64/
├── linux/ # Linux build files
├── windows/ # Windows build files
└── macos/ # macOS build files
Note: Add to .gitignore:
target/¶
Purpose: Final build outputs (generated).
Structure:
target/
├── android/ # Android outputs
│ └── MyProject_Android_SDK-1.0.0.zip
├── ios/ # iOS outputs
│ └── MyProject_iOS_SDK-1.0.0.zip
├── linux/ # Linux outputs
│ └── MyProject_Linux_SDK-1.0.0.zip
├── windows/ # Windows outputs
│ └── MyProject_Windows_SDK-1.0.0.zip
└── doc/ # Documentation
└── html/
Note: Add to .gitignore:
File Naming Conventions¶
Header Files¶
include/myproject/
├── myproject.h # Main header (lowercase, matches project)
├── feature_a.h # Feature headers (lowercase, underscores)
├── my_class.h # Class headers (lowercase, underscores)
└── constants.h # Utility headers
Source Files¶
src/
├── myproject.cpp # Matches header name
├── feature_a.cpp
├── my_class.cpp
└── internal/
└── utils.cpp # Private utilities
Test Files¶
Benchmark Files¶
benches/
├── bench_performance.cpp # Prefix with "bench_"
├── bench_feature_a.cpp
└── bench_algorithms.cpp
Multi-Module Projects¶
For projects with multiple libraries:
workspace/
├── CCGO.toml # Workspace configuration (optional)
├── lib_core/ # Core library
│ ├── CCGO.toml
│ ├── include/
│ └── src/
├── lib_utils/ # Utilities library
│ ├── CCGO.toml
│ ├── include/
│ └── src/
└── app/ # Application
├── CCGO.toml
├── src/
└── main.cpp
Workspace CCGO.toml:
Module dependencies:
# app/CCGO.toml
[dependencies]
lib_core = { path = "../lib_core" }
lib_utils = { path = "../lib_utils" }
Platform-Specific Files¶
Android¶
project/
├── android/ # Android-specific files (optional)
│ ├── gradle.properties
│ └── proguard-rules.pro
└── CCGO.toml
[android]
min_sdk_version = 21
iOS¶
project/
├── ios/ # iOS-specific files (optional)
│ ├── Info.plist
│ └── Entitlements.plist
└── CCGO.toml
[ios]
deployment_target = "12.0"
Windows¶
project/
├── windows/ # Windows-specific files (optional)
│ ├── resource.rc
│ └── app.manifest
└── CCGO.toml
[windows]
subsystem = "console"
Best Practices¶
1. Consistent Naming¶
Use consistent naming conventions:
# Good - consistent lowercase with underscores
include/mylib/my_feature.h
src/my_feature.cpp
tests/test_my_feature.cpp
# Bad - inconsistent casing
include/mylib/MyFeature.h
src/my_feature.cpp
tests/TestMyFeature.cpp
2. Organize by Feature¶
Group related files:
src/
├── networking/ # Networking feature
│ ├── client.cpp
│ ├── server.cpp
│ └── protocol.cpp
└── database/ # Database feature
├── connection.cpp
└── query.cpp
3. Separate Public and Private¶
Keep API surface clean:
4. Documentation Near Code¶
Keep documentation close to source:
5. Examples Are Tests¶
Examples should compile and run:
examples/
└── basic/
├── main.cpp # Working example
├── CMakeLists.txt # Build configuration
└── README.md # How to run
.gitignore Template¶
Recommended .gitignore for CCGO projects:
# Build directories
cmake_build/
target/
bin/
build/
# IDE files
.vscode/
.idea/
*.swp
*.swo
*~
# OS files
.DS_Store
Thumbs.db
desktop.ini
# Python
__pycache__/
*.pyc
*.pyo
*.egg-info/
# Generated files
*.autosave
*.user
*.log
# Dependencies
vendor/
Migration from Existing Projects¶
From CMake Project¶
-
Create CCGO.toml:
-
Copy source files:
-
Configure CCGO.toml:
-
Build:
From Header-Only Library¶
-
Keep headers in include/:
-
Configure as header-only:
From Multiple CMakeLists.txt¶
-
Merge into CCGO structure:
-
Use workspace:
Common Patterns¶
Library with Examples¶
mylib/
├── CCGO.toml
├── include/
├── src/
├── tests/
└── examples/
├── basic/
├── advanced/
└── integration/