Skip to content

e-gleba/cmake_template

Repository files navigation

cxx-skeleton

cxx-skeleton logo

C++ Standard CMake License

Modern C++ project template. Ninja Multi-Config, CPM, CPack, cross-compilation, code quality tooling — zero friction from clone to package.

Quick Start

cmake --preset=gcc
cmake --build --preset=gcc-release
ctest --preset=gcc-release

Full pipeline (configure → build → test → package):

cmake --workflow --preset=gcc-full

Prerequisites

cmake 3.31+
ninja 1.11+
C++23-capable compiler (clang 16+, gcc 13+, msvc 19.35+)

macOS

brew install cmake llvm ninja doxygen

Linux (Fedora)

sudo dnf install cmake gcc-c++ ninja-build doxygen llvm clang-tools-extra

Linux (Ubuntu/Debian)

sudo apt install cmake g++ ninja-build doxygen llvm clang-tools

Windows

choco install cmake llvm ninja doxygen visualstudio2022buildtools

Presets

All presets use Ninja Multi-Config (except msvc → Visual Studio 17 2022).

Configure

Preset Compiler Platform Notes
gcc GCC/G++ Native
clang Clang/Clang++ Native
msvc MSVC (VS 2022) Windows x64 arch, x64 host toolset
android-arm64 NDK Android arm64-v8a, API 24
android-arm32 NDK Android armeabi-v7a, API 24
android-x64 NDK Android x86_64 (emulator)
android-x86 NDK Android x86 (emulator)
llvm-mingw-x86_64 LLVM-MinGW Linux → Windows 64-bit cross-compilation
llvm-mingw-i686 LLVM-MinGW Linux → Windows 32-bit cross-compilation
llvm-mingw-aarch64 LLVM-MinGW Linux → Windows ARM64 cross-compilation

Build

cmake --build --preset=<name>-release
cmake --build --preset=<name>-debug

Available: gcc-release, gcc-debug, clang-release, clang-debug, msvc-release, msvc-debug, android-arm64, android-arm32, android-x64, android-x86, llvm-mingw-x86_64, llvm-mingw-i686, llvm-mingw-aarch64.

Test

ctest --preset=<name>-release

Available: gcc-release, gcc-debug, clang-release, clang-debug, msvc-release, msvc-debug. Tests are disabled for cross-compiled targets.

Package (CPack)

cpack --preset=<name>-package
Preset Format
gcc-package .tar.gz
clang-package .tar.gz
msvc-package .zip
llvm-mingw-*-package .tar.xz

Workflows

Full pipelines (configure → build → test → package) in a single command:

cmake --workflow --preset=gcc-full
cmake --workflow --preset=clang-full
cmake --workflow --preset=msvc-full
cmake --workflow --preset=android-arm64-full    # configure + build only
cmake --workflow --preset=llvm-mingw-x86_64-full # configure + build + package (no test)

Project Structure

.
├── CMakeLists.txt
├── CMakePresets.json
├── cmake/                  # find_package modules (warnings, cpm, code quality)
├── src/                    # application sources
├── tests/                  # doctest + CTest
├── tools/                  # helper scripts
├── docker/                 # Dockerfiles for reproducible builds
├── android-project/        # Android project scaffolding
├── .clang-format           # clang-format config
├── .clang-tidy             # clang-tidy config
├── .cmake-format.yaml      # cmake-format config
├── .editorconfig           # editor defaults
├── .pre-commit-config.yaml # pre-commit hooks
└── license                 # MIT

Code Quality

Format sources and CMake files:

cmake --build build/gcc --target format

Static analysis:

cmake --build build/gcc --target tidy

Lint:

cmake --build build/gcc --target cpplint

Pre-commit hooks enforce formatting on every commit. Install once:

pre-commit install

Documentation

cmake --build build/gcc --target doxygen

Output: build/gcc/docs/doxygen/html.

Docker

docker build -t cxx-skeleton -f docker/fedora.Dockerfile .
docker run --rm -v "$(pwd):/src" cxx-skeleton cmake --workflow --preset=gcc-full

Android

Set ANDROID_NDK_HOME and run:

export ANDROID_NDK_HOME=/path/to/ndk
cmake --workflow --preset=android-arm64-full

Cross-Compilation (Linux → Windows)

Requires llvm-mingw on PATH:

cmake --workflow --preset=llvm-mingw-x86_64-full

Dependencies

Managed via CPM. Add packages in CMakeLists.txt:

CPMAddPackage("gh:fmtlib/fmt#11.1.4")

CPM downloads are verbose (FETCHCONTENT_QUIET=OFF) for CI visibility.

IDE Support

The project generates compile_commands.json and is compatible with CLion, Visual Studio, QtCreator, KDevelop, and any LSP-based editor.

References

Standards

Tools

Performance

Compiler Docs

Learning

About

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

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors