https://github.com/dconco/cpp-template
A modern, blazing-fast C++ template project with CMake and Ninja build system.
https://github.com/dconco/cpp-template
Last synced: 4 months ago
JSON representation
A modern, blazing-fast C++ template project with CMake and Ninja build system.
- Host: GitHub
- URL: https://github.com/dconco/cpp-template
- Owner: dconco
- Created: 2025-07-28T19:36:30.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-07-30T18:18:34.000Z (10 months ago)
- Last Synced: 2025-09-10T08:37:56.011Z (9 months ago)
- Language: CMake
- Homepage:
- Size: 4.88 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ C++ Template Project



_A modern, blazing-fast C++ template project with CMake and Ninja build system_
[๐ Features](#-features) โข [๐ ๏ธ Setup](#-setup) โข [๐ง Building](#-building) โข [โก Quick Commands](#-quick-commands)
---
## โจ Features
- ๐๏ธ **Modern CMake** configuration
- โก **Ninja build system** for lightning-fast builds
- ๐ **Debug & Release** configurations
- ๐ **Auto-rebuild** on file changes
- ๐ **Multi-core** compilation support
- ๐ฆ **Ready-to-use** project structure
## ๐ ๏ธ Setup
### Prerequisites
| Tool | Ubuntu/Debian | macOS | Windows |
| ----------------- | ---------------------------------- | ------------------------ | ---------------------------------------------------------------- |
| **Build Tools** | `sudo apt install build-essential` | `xcode-select --install` | Visual Studio |
| **CMake** | `sudo apt install cmake` | `brew install cmake` | [cmake.org](https://cmake.org) |
| **Ninja** | `sudo apt install ninja-build` | `brew install ninja` | [GitHub Releases](https://github.com/ninja-build/ninja/releases) |
| **File Watching** | `sudo apt install inotify-tools` | Built-in | Built-in |
### Quick Install (Ubuntu/Debian)
```bash
sudo apt update && sudo apt install -y build-essential cmake ninja-build inotify-tools
```
## ๐ง Building
### ๐ Initial Setup
```bash
# Clone your project
git clone https://github.com/dconco/cpp-template.git
cd cpp-template
# Create build directory
mkdir build && cd build
```
### ๐โโ๏ธ Build Commands
๐ฏ First Time Build
```bash
cmake -G Ninja .. && ninja -j$(nproc) && ./app
```
**What this does:**
- ๐ง Configures project with Ninja generator
- ๐๏ธ Builds using all CPU cores
- โถ๏ธ Runs your application
_Use this for initial setup or when CMakeLists.txt changes_
โก Quick Rebuild
```bash
ninja -j$(nproc) && ./app
```
**What this does:**
- ๐ Rebuilds only changed files
- โถ๏ธ Runs your application
_Fastest option for regular development_
๐ Debug Build
```bash
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug .. && ninja -j$(nproc) && ./app
```
**What this does:**
- ๐ Enables debug symbols
- ๐ซ Disables optimizations
- ๐ Perfect for debugging with GDB/IDE
๐ Release Build
```bash
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release .. && ninja -j$(nproc) && ./app
```
**What this does:**
- โก Full optimizations enabled
- ๐ฆ Smaller executable size
- ๐๏ธ Maximum performance
๐งน Clean Build
```bash
ninja clean && ninja -j$(nproc) && ./app
```
**What this does:**
- ๐๏ธ Removes all build artifacts
- ๐ Forces complete rebuild
- ๐ฉน Fixes corrupted build cache
๐ Watch Mode
```bash
while inotifywait -e modify,move,create,delete ../src/; do ninja -j$(nproc) && ./app; done
```
**What this does:**
- ๐๏ธ Monitors `src/` directory
- ๐ Auto-rebuilds on file changes
- ๐โโ๏ธ Automatically runs your app
_Perfect for rapid development cycles_
## โก Quick Commands
Want to make your life easier? Add these aliases to your `~/.bashrc` or `~/.zshrc`:
```bash
# ๐ ๏ธ C++ Development Aliases
alias cpp-start="cmake -G Ninja .. && ninja -j\$(nproc) && ./app"
alias cpp-serve="ninja -j\$(nproc) && ./app"
alias cpp-debug="cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug .. && ninja -j\$(nproc) && ./app"
alias cpp-release="cmake -G Ninja -DCMAKE_BUILD_TYPE=Release .. && ninja -j\$(nproc) && ./app"
alias cpp-clean="ninja clean && ninja -j\$(nproc) && ./app"
alias cpp-watch="while inotifywait -e modify,move,create,delete ../src/; do ninja -j\$(nproc) && ./app; done"
```
**Reload your shell:**
```bash
source ~/.bashrc # or ~/.zshrc
```
**Now you can use:**
- `cpp-start` โ ๐ฏ Initial build and run
- `cpp-serve` โ โก Quick rebuild and run
- `cpp-debug` โ ๐ Debug build and run
- `cpp-release` โ ๐ Optimized build and run
- `cpp-clean` โ ๐งน Clean rebuild and run
- `cpp-watch` โ ๐ Auto-rebuild on changes
## ๐ฏ Customizing Your Executable
If your executable isn't named `app`, replace `./app` with your actual name:
**Find your executable name in CMakeLists.txt:**
```cmake
add_executable(my-awesome-app src/main.cpp) # Your exe is "my-awesome-app"
```
**Then use:**
```bash
ninja -j$(nproc) && ./my-awesome-app
```
## ๐จ Troubleshooting
โ "ninja: command not found"
**Solution:** Install ninja for your platform
```bash
# Ubuntu/Debian
sudo apt install ninja-build
# macOS
brew install ninja
```
โ "Permission denied: ./app"
**Solution:**
- โ
Ensure build completed successfully
- โ
Check executable exists in build directory
- โ
Try: `ls -la app` to verify permissions
โ CMake configuration fails
**Solution:**
- โ
Verify `CMakeLists.txt` exists in project root
- โ
Check all dependencies are installed
- โ
Try deleting build folder and recreating
โ File watching doesn't work
**Solution:**
- โ
Install `inotify-tools` (Linux)
- โ
Ensure `../src/` path exists from build directory
- โ
Check file permissions on src directory
## ๐ค Contributing
1. ๐ด Fork the repository
2. ๐ฟ Create a feature branch (`git checkout -b amazing-feature`)
3. โ๏ธ Make your changes
4. ๐งช Test with both debug and release builds
5. ๐ค Submit a pull request
---
**Made with โค๏ธ and lots of โ**
_Happy Coding! ๐_