A production-ready C++20 template for Windows (MSVC/Clang-CL), Linux (GCC/Clang), and MSYS2 (MinGW).
- C++20 Standard: Modern C++ with modules, concepts, and ranges support.
- Multi-Compiler Support: MSVC, Clang-CL, MinGW GCC, MinGW Clang, Linux GCC, Linux Clang.
- CMake Presets: Standardized builds across all compilers and configurations.
- Testing & Benchmarking: Google Test for unit tests, Google Benchmark for performance.
- Quality Tools: Clang-Tidy static analysis, sanitizer support (ASan/UBSan), clang-format.
.
├── apps/ # Executables (e.g., app/main.cpp)
├── libs/ # Modular libraries (Elite::Core)
├── tests/ # Google Test suite
├── benchmarks/ # Google Benchmark suite
├── cmake/ # Modules: CompilerWarnings, Sanitizers, StaticAnalyzers
├── scripts/ # Build automation (build.bat, build.sh, build_all.*)
├── .github/workflows/ # CI/CD pipeline
├── CMakePresets.json # CMake presets for all compilers
└── vcpkg.json # Dependency manifest (Windows)
- Visual Studio 2022+ (Desktop C++ workload).
- vcpkg: Set
VCPKG_ROOTin your environment variables.
In the UCRT64 Terminal, install the toolchain:
pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-clang \
mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-ninja \
mingw-w64-ucrt-x86_64-gtest mingw-w64-ucrt-x86_64-google-benchmark
- WSL Config: In
%USERPROFILE%\.wslconfig, add[wsl2] sparseVhd=true. - Mount Fix: In WSL
/etc/wsl.conf, add[automount] options = "metadata". - Install:
sudo apt update && sudo apt install -y --no-install-recommends \
gcc g++ clang cmake ninja-build libgtest-dev libbenchmark-dev
# Configure with preset
cmake --preset msvc-release # Windows MSVC
cmake --preset linux-gcc-debug # Linux/WSL
# Build
cmake --build build/msvc/release
# Test
ctest --test-dir build/msvc/release --output-on-failure.\scripts\build.bat msvc Release # Windows
./scripts/build.sh linux-gcc Debug # Linux/WSL/MSYS2.\scripts\build_all.bat # Windows
./scripts/build_all.sh # Linux/WSL/MSYS2- Unit Tests: Run via
ctest --test-dir <build-dir> - Benchmarks: Automatically execute in Release mode when using build scripts
- Output: Binaries land in
build/<preset>/<config>/bin/
To reset your environment and clear all build folders:
# VS Code Task: Master: Clean All Builds
if exist build (rd /s /q build)
This file demonstrates how to benchmark the hello function from your Elite::Core library.
#include <benchmark/benchmark.h>
#include <core/hello.hpp> // Assumes your include/core/hello.hpp exists
#include <string>
#include <vector>
// 1. Benchmark a simple function from your library
static void BM_HelloFunction(benchmark::State& state) {
// Optional: Setup code here
for (auto _ : state) {
// This is the code we are measuring
std::string result = get_hello_message();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_HelloFunction);
// 2. Benchmark with Arguments (e.g., measuring performance scaling)
static void BM_StringCopy(benchmark::State& state) {
std::string x = "EliteCppTemplate Performance Test";
for (auto _ : state) {
for (int i = 0; i < state.range(0); ++i) {
std::string copy = x;
benchmark::DoNotOptimize(copy);
}
}
state.SetComplexityN(state.range(0));
}
// Run this benchmark for 10, 100, and 1000 iterations
BENCHMARK(BM_StringCopy)->Arg(10)->Arg(100)->Arg(1000)->Complexity();
// 3. Main entry point provided by Google Benchmark
BENCHMARK_MAIN();
MIT License