Skip to content

e-gleba/cmake_template

cmake_template

cmake_template logo

CI C++ Standard CMake License Stars Contributing Guide

The only CMake template with Android NDK, Linux→Windows cross-compilation, and Gradle Managed Devices — out of the box.

Use this template


Production-ready C++ template for cross-platform projects. Targets C++23/26. Ninja Multi-Config, CPM, clang-tidy, clang-format, pre-commit hooks. Packages with CPack. Tests with doctest β€” instrumented on Android via Gradle Managed Devices. Zero friction from clone to package on Linux, Windows, Android, and macOS.

# Desktop β€” full pipeline in one command
cmake --workflow --preset=gcc-full

# Android β€” configure + build for arm64
cmake --workflow --preset=android-arm64-full

# Linux β†’ Windows ARM64 β€” cross-compile + package
cmake --workflow --preset=llvm-mingw-aarch64-full

Why this template?

Most CMake starters stop at "it builds on my machine." This one ships to production.

You need Most templates This template
Android NDK ❌ Not even mentioned βœ… 4 presets (arm64, arm32, x64, x86), API 24, c++_shared, Prefab
Android instrumentation tests ❌ βœ… AndroidJUnitRunner, Gradle Managed Devices (Pixel 6 ATD), doctest JNI bridge, #23 native GTest strategy
Linux β†’ Windows cross-compile ❌ βœ… llvm-mingw toolchain: x86_64, i686, aarch64
CMake Presets Basic or none βœ… 10+ configure presets, 15+ build presets, workflow presets, schema v10
Packaging ❌ βœ… CPack: tar.gz, zip, txz per platform
Reproducible CI Manual Docker βœ… Docker images + GitHub Actions matrix
Code quality Maybe clang-format βœ… clang-tidy, clang-format, .cmake-format.yaml, pre-commit hooks, .editorconfig
C++ Standard 17 βœ… 23 / 26

Unique capabilities

  • Android NDK out of the box β€” not just a toolchain file. A full Gradle project with externalNativeBuild, prefab = true, managed virtual devices, and connectedCheck test harness. Builds .so or .aar. See android-project/.
  • Cross-compile from Linux to Windows β€” llvm-mingw toolchain included in cmake/toolchains/. Build .exe binaries for x86_64, i686, and aarch64 Windows β€” no Windows machine needed.
  • One-command workflows β€” cmake --workflow --preset=gcc-full runs configure β†’ build β†’ test β†’ package. No glue scripts.
  • Professional CMake architecture β€” CMAKE_CURRENT_LIST_DIR everywhere (safe for add_subdirectory/FetchContent), cross-compilation-aware CMAKE_FIND_ROOT_PATH, build-type-safe flag management.
  • Honest roadmap β€” every missing feature is a tracked issue, not a hidden gap. See open issues.

Quick Start

1. Create your repo from this template

🎯 Click here: Use this template β†’ Create new repository

Then clone your new repo:

git clone https://github.com/YOUR_USER/YOUR_PROJECT
cd YOUR_PROJECT

2. Build and test (desktop)

# GCC β€” full pipeline
cmake --workflow --preset=gcc-full

# Or step by step:
cmake --preset=gcc
cmake --build --preset=gcc-release
ctest --preset=gcc-release

# Clang
cmake --workflow --preset=clang-full

# MSVC (Windows only)
cmake --workflow --preset=msvc-full

3. Cross-compile for Android

# Requires: ANDROID_NDK_HOME or ANDROID_HOME set
cmake --preset=android-arm64
cmake --build --preset=android-arm64

# Run instrumented tests on device/emulator
cd android-project
./gradlew pixel_6_aosp_atd_30DebugAndroidTest
./gradlew connectedCheck

4. Cross-compile for Windows (from Linux)

# Requires: llvm-mingw installed
cmake --workflow --preset=llvm-mingw-x86_64-full
# β†’ build/llvm-mingw-x86_64/package/cxx_project-*.zip

Platform Matrix

Platform Preset Generator Test runner Package
Linux (native) gcc, clang Ninja Multi-Config ctest .tar.gz
Windows (native) msvc Visual Studio 17 2022 ctest .zip
Windows (cross) llvm-mingw-x86_64, llvm-mingw-i686, llvm-mingw-aarch64 Ninja Multi-Config β€” (cross-compiled) .tar.xz
Android arm64 android-arm64 Ninja Multi-Config gradlew connectedCheck β€”
Android arm32 android-arm32 Ninja Multi-Config gradlew connectedCheck β€”
Android x64 android-x64 Ninja Multi-Config gradlew connectedCheck β€”
Android x86 android-x86 Ninja Multi-Config gradlew connectedCheck β€”
macOS clang (native) Ninja Multi-Config ctest .tar.gz
iOS / macOS Xcode planned #20 Xcode xctest / xcodebuild test β€”
WebAssembly planned #2 Emscripten β€” β€”

Comparison: Competitive Landscape

Feature cmake_template cpp-best-practices modern-cpp-template cmake-init
C++ Standard 23 / 26 17 / 20 17 11+
CMake Presets βœ… 10+ with workflows ❌ ❌ ❌
Android NDK βœ… 4 ABI ❌ ❌ ❌
Android instrumented tests βœ… GMD + doctest JNI ❌ ❌ ❌
Linux β†’ Windows cross βœ… llvm-mingw (3 arch) ❌ ❌ ❌
WebAssembly ❌ #2 βœ… + Pages deploy ❌ ❌
Docker / CI βœ… + Actions matrix βœ… Docker + Actions βœ… GitHub Actions βœ…
CPack packaging βœ… tar.gz / zip / txz ❌ ❌ ❌
Sanitizers ❌ #9 βœ… ASan/UBSan βœ… ❌
Fuzz testing ❌ βœ… libFuzzer ❌ ❌
Code coverage ❌ #10 βœ… codecov βœ… codecov ❌
macOS/iOS (Xcode) ❌ #20 Limited ❌ ❌
vcpkg ❌ #3 ❌ ❌ ❌
GitHub Stars ⭐ you are here 1,700+ 1,900+ 900+
Age ~1 year 3 years 5 years 11 years
License MIT Unlicense Unlicense MIT

Honest assessment: This template leads in cross-compilation engineering (Android NDK, Linux→Win, Presets, CPack). It trails in sanitizers, fuzz testing, and code coverage — all actively tracked in the roadmap. It does not include Qt, OpenGL, or JUCE scaffolding — those are well covered by specialized templates.


Project Structure

.
β”œβ”€β”€ CMakeLists.txt           # Root: project(), CPM, code quality, CTest, CPack
β”œβ”€β”€ CMakePresets.json        # 10+ configure, 15+ build, workflow presets
β”œβ”€β”€ cmake/
β”‚   β”œβ”€β”€ toolchains/          # llvm-mingw.cmake, future ios.cmake
β”‚   β”œβ”€β”€ code_quality/        # clang-tidy, clang-format, cpplint configs
β”‚   └── description/         # package_description.cmake
β”œβ”€β”€ src/                     # Library sources
β”‚   └── CMakeLists.txt
β”œβ”€β”€ tests/                   # doctest-based tests
β”‚   β”œβ”€β”€ CMakeLists.txt       # Shared lib on Android, executable on desktop
β”‚   β”œβ”€β”€ doctest_android_jni.cpp  # JNI bridge for Android instrumentation
β”‚   └── doctest_example.cpp
β”œβ”€β”€ android-project/         # Gradle project with AGP, GMD, AndroidJUnitRunner
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ build.gradle     # externalNativeBuild β†’ ../../CMakeLists.txt
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ main/        # NativeActivity entry point
β”‚   β”‚       └── androidTest/ # Instrumented test wrappers
β”‚   β”œβ”€β”€ build.gradle
β”‚   └── settings.gradle
β”œβ”€β”€ docker/                  # Dockerfiles for CI reproducibility
β”œβ”€β”€ scripts/                 # Build helpers
β”œβ”€β”€ docs/                    # Architecture, presets, Docker guides
└── tools/                   # IWYU mappings, code quality configs

Documentation

Document What it covers
Presets & Platforms All CMake presets, platform support, cross-compilation details
Architecture CMake design decisions, directory structure, PROJECT_IS_TOP_LEVEL pattern
Docker Guide Docker images for CI, local reproducible builds
Contributing How to contribute, code style, pre-commit setup
References Professional CMake, modern CMake, toolchain references
Issue: Android native testing strategy GTest vs doctest, Activity lifecycle, XCTest, CI/CD β€” research-backed

Consulting

I help teams reduce C++ build friction and ship cross-platform products faster.

Services:

  • CMake architecture audits and modernisation
  • Android NDK toolchain setup and Gradle integration
  • CI/CD pipeline design for C++ (GitHub Actions, GitLab CI, Docker)
  • Cross-compilation pipelines (Linuxβ†’Windows, Linuxβ†’Android, macOSβ†’iOS)
  • CPack packaging and distribution
  • Team onboarding workshops

Why work with me:

  • This template is the public portfolio β€” it demonstrates real engineering depth in CMake, NDK, cross-compilation, and CI
  • I focus exclusively on build engineering β€” not general software consulting
  • Every engagement starts with a concrete deliverable, not a roadmap document

🌐 Website e-gleba.github.io
πŸ“§ Email i@egleba.ru β€” fastest response
πŸ’¬ Discussions GitHub Discussions
πŸ’Ό Rate Up to $150/hr depending on scope
πŸ“ Location Remote-first, worldwide


Roadmap

All planned features are tracked as GitHub issues with the enhancement label.

Priority Issue Feature
πŸ”΄ P0 #20 macOS/iOS Xcode presets + XCTest
πŸ”΄ P0 #9 Sanitizers (ASan/UBSan/TSan)
🟑 P1 #10 Code coverage (codecov/CodeQL)
🟑 P1 #2 WebAssembly (Emscripten)
🟑 P1 #3 vcpkg compatibility
🟒 P2 #5 C++20 modules
🟒 P2 #11 Steam Runtime / Steam Deck
🟒 P2 #8 Prebuilt / air-gapped dependency mode

View all issues β†’


License

MIT β€” see license.md.

This is not a "source available" or dual-licensed project. Use it for anything β€” commercial products, internal tools, or as a base for your own template. Attribution appreciated but not required.

About

Production-ready C++ project template with modern standards, cross-platform builds, and integrated tooling

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors