# C++ Build Assistant

A JavaScript/TypeScript build automation tool for C++ projects using Conan and Ninja.

## Features

- ✅ Dependency checking (CMake, Conan, Ninja, GCC)
- 🔧 Automatic Conan configuration generation
- 📦 Conan package management
- ⚙️ CMake configuration with Ninja generator
- 🏗️ Parallel builds with Ninja
- 🧪 CTest integration
- 🎨 Colorized output
- 🚀 Full workflow automation

## Prerequisites

Install the required tools:

### macOS
```bash
brew install cmake conan ninja gcc
```

### Linux (Ubuntu/Debian)
```bash
sudo apt-get install cmake ninja-build g++
pip install conan
```

### Windows
```bash
choco install cmake conan ninja
```

## Usage

### From npm scripts (recommended)

```bash
# Check dependencies
npm run cpp:check

# Full build workflow
npm run cpp:full

# Individual steps
npm run cpp:install      # Install Conan deps
npm run cpp:configure    # Configure CMake
npm run cpp:build        # Build project
npm run cpp:test         # Run tests
npm run cpp:clean        # Clean build

# Build specific target
npm run cpp:build -- build dbal_daemon

# Debug build
npm run cpp:build -- build --debug
```

### Direct usage

```bash
# JavaScript version
node tools/cpp-build-assistant.js check
node tools/cpp-build-assistant.js full

# TypeScript version (requires ts-node)
ts-node tools/cpp-build-assistant.ts check
```

## Commands

| Command | Description |
|---------|-------------|
| `check` | Verify all dependencies are installed |
| `init` | Create conanfile.txt if missing |
| `install` | Install Conan dependencies |
| `configure` | Configure CMake with Ninja |
| `build [target]` | Build project (default: all) |
| `test` | Run CTest suite |
| `clean` | Remove build directory |
| `rebuild` | Clean + configure + build |
| `full` | Complete workflow from scratch |
| `help` | Show help message |

## Options

- `--debug` - Use Debug build type
- `--release` - Use Release build type (default)
- `--jobs=N` - Number of parallel build jobs (default: CPU count)

## Workflow

The typical development workflow:

```bash
# First time setup
npm run cpp:full

# After changing code
npm run cpp:build

# After changing dependencies
npm run cpp:install
npm run cpp:configure
npm run cpp:build

# Clean rebuild
npm run cpp:rebuild
```

## Integration

The build assistant can be integrated into CI/CD pipelines:

```yaml
# .github/workflows/cpp-build.yml
- name: Check C++ dependencies
  run: npm run cpp:check

- name: Build C++ project
  run: npm run cpp:full

- name: Run C++ tests
  run: npm run cpp:test
```

## Generated Files

The assistant creates/manages:

- `cpp/conanfile.txt` - Conan dependency specification
- `cpp/build/` - Build directory (gitignored)
- `cpp/build/conan_toolchain.cmake` - Conan CMake toolchain
- `cpp/build/compile_commands.json` - Compilation database

## Conanfile Template

The assistant generates a standard conanfile.txt with:

```txt
[requires]
sqlite3/3.45.0
fmt/10.2.1
spdlog/1.13.0
nlohmann_json/3.11.3

[generators]
CMakeDeps
CMakeToolchain

[options]
sqlite3:shared=False

[layout]
cmake_layout
```

You can customize this by editing `cpp/conanfile.txt` after generation.

## Troubleshooting

### Conan profile not found
```bash
conan profile detect --force
```

### CMake can't find Ninja
```bash
# Ensure Ninja is in PATH
which ninja  # Unix
where ninja  # Windows
```

### Build failures
```bash
# Clean and rebuild
npm run cpp:clean
npm run cpp:full
```

## Architecture

```
dbal/
├── cpp/
│   ├── CMakeLists.txt
│   ├── conanfile.txt          # Generated by assistant
│   ├── build/                 # Generated by Conan/CMake
│   │   ├── conan_toolchain.cmake
│   │   └── compile_commands.json
│   ├── include/
│   └── src/
└── tools/
    ├── cpp-build-assistant.js  # Node.js version
    ├── cpp-build-assistant.ts  # TypeScript version
    └── README.md              # This file
```

## API

The assistant can also be used programmatically:

```javascript
const { CppBuildAssistant } = require('./tools/cpp-build-assistant');

const assistant = new CppBuildAssistant('/path/to/dbal');

// Check dependencies
const depsOk = assistant.checkDependencies();

// Run full workflow
if (depsOk) {
  assistant.createConanfile();
  assistant.installConanDeps();
  assistant.configureCMake('Release');
  assistant.build('all', 8);
}
```

## License

See LICENSE file in the repository root.
