ccgo 3.4.1

A high-performance C++ cross-platform build CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
# 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.toml` for 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:**
```toml
[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](configuration.md)

#### CMakeLists.txt

**Purpose:** CMake configuration (auto-generated by CCGO).

**Content:**
```cmake
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:**
```python
PROJECT_NAME = "myproject"
PROJECT_VERSION = "1.0.0"
BUILD_TYPE = "release"
CPP_STANDARD = "17"
```

**Usage:** Used by build scripts internally.

#### .ccgoignore

**Purpose:** Exclude files from CCGO operations.

**Content:**
```
# Build directories
cmake_build/
target/
bin/

# IDE files
.vscode/
.idea/

# Generated files
*.pyc
```

**See:** [Configuration Guide - .ccgoignore](configuration.md#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:**

1. **Namespace directory:** Always use a subdirectory matching your project name
   ```cpp
   // Good
   #include <myproject/myproject.h>

   // Bad - no namespace
   #include <myproject.h>
   ```

2. **Header guards:** Use `#pragma once` or traditional guards
   ```cpp
   #pragma once

   namespace myproject {
   // ...
   }
   ```

3. **Version header:** Auto-generated with version info
   ```cpp
   // version.h (generated)
   #pragma once

   #define MYPROJECT_VERSION_MAJOR 1
   #define MYPROJECT_VERSION_MINOR 0
   #define MYPROJECT_VERSION_PATCH 0
   #define MYPROJECT_VERSION "1.0.0"
   ```

4. **Minimize includes:** Only include what's necessary
   ```cpp
   // Good - forward declare when possible
   class FeatureA;

   // Bad - include if not needed
   #include "feature_a.h"
   ```

### 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:**

1. **One class per file:** Keep files focused
   ```
   src/
   ├── feature_a.cpp         # FeatureA implementation
   └── feature_b.cpp         # FeatureB implementation
   ```

2. **Private headers:** Use internal/ for private headers
   ```cpp
   // src/internal/utils.h
   #pragma once
   // Internal utilities not for public use
   ```

3. **Platform-specific code:** Use subdirectories or conditional compilation
   ```cpp
   // Option 1: Separate files
   #ifdef __ANDROID__
   #include "platform/android.cpp"
   #elif defined(__APPLE__)
   #include "platform/ios.cpp"
   #endif

   // Option 2: Conditional blocks
   void platform_init() {
   #ifdef __ANDROID__
       // Android-specific
   #elif defined(__APPLE__)
       // iOS-specific
   #endif
   }
   ```

### 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:**

```cpp
// 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:**

```cpp
// test_main.cpp
#define CATCH_CONFIG_MAIN
#include <catch2/catch_test_macros.hpp>
```

**Running tests:**

```bash
ccgo test                    # Run all tests
ccgo test --filter "Basic"   # Run specific test
```

### 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:**

```cpp
// 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:**

```bash
ccgo bench                   # Run all benchmarks
ccgo bench --filter "MyFunc" # Run specific benchmark
```

### 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:**

```bash
ccgo doc                     # Generate documentation
ccgo doc --open              # Generate and open in browser
```

### 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:**

```cpp
// 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:**

```cmake
# 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`:

```
cmake_build/
```

### 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`:

```
target/
```

## 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

```
tests/
├── test_myproject.cpp       # Prefix with "test_"
├── test_feature_a.cpp
└── test_my_class.cpp
```

### 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:**

```toml
[workspace]
members = [
    "lib_core",
    "lib_utils",
    "app"
]
```

**Module dependencies:**

```toml
# 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:

```
include/
└── mylib/
    ├── public_api.h         # Public API only
    └── internal/            # Internal details
        └── impl.h
```

### 4. Documentation Near Code

Keep documentation close to source:

```
src/
├── feature_a/
│   ├── feature_a.cpp
│   ├── feature_a.h
│   └── README.md            # Feature documentation
```

### 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:

```gitignore
# 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

1. **Create CCGO.toml:**
   ```bash
   ccgo init
   ```

2. **Copy source files:**
   ```bash
   mkdir -p include/mylib src
   cp src/*.h include/mylib/
   cp src/*.cpp src/
   ```

3. **Configure CCGO.toml:**
   ```toml
   [package]
   name = "mylib"
   version = "1.0.0"

   [build]
   cpp_standard = "17"
   ```

4. **Build:**
   ```bash
   ccgo build linux
   ```

### From Header-Only Library

1. **Keep headers in include/:**
   ```
   include/
   └── mylib/
       ├── mylib.h
       └── impl.h
   ```

2. **Configure as header-only:**
   ```toml
   [library]
   type = "header-only"
   ```

### From Multiple CMakeLists.txt

1. **Merge into CCGO structure:**
   ```
   Old:
   project/
   ├── CMakeLists.txt
   ├── module1/
   │   └── CMakeLists.txt
   └── module2/
       └── CMakeLists.txt

   New:
   project/
   ├── CCGO.toml
   ├── module1/
   │   ├── CCGO.toml
   │   └── src/
   └── module2/
       ├── CCGO.toml
       └── src/
   ```

2. **Use workspace:**
   ```toml
   # Root CCGO.toml
   [workspace]
   members = ["module1", "module2"]
   ```

## Common Patterns

### Library with Examples

```
mylib/
├── CCGO.toml
├── include/
├── src/
├── tests/
└── examples/
    ├── basic/
    ├── advanced/
    └── integration/
```

### Library with Tools

```
mylib/
├── CCGO.toml
├── include/
├── src/
├── tests/
└── tools/
    ├── converter/
    └── analyzer/
```

### Library with Plugins

```
mylib/
├── CCGO.toml
├── include/
├── src/
├── plugins/
│   ├── plugin_a/
│   └── plugin_b/
└── tests/
```

## See Also

- [Installation Guide]installation.md
- [Configuration Guide]configuration.md
- [Build System]../features/build-system.md
- [CCGO.toml Reference]../reference/ccgo-toml.md