A production-ready, opinionated C++20 project template designed for speed and quality. It comes pre-configured with Clang, CMake, GoogleTest, Sanitizers, Static Analysis, and a CI/CD pipeline that automates testing, security scanning, and multi-platform packaging.
- Modern Standard: Configured for C++20.
- Build System: CMake (3.20+) wrapped in a convenient
Makefilefor one-command workflows. - Compiler: Optimized for Clang (default) with GCC support available.
- Quality & Safety:
- Sanitizers: AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan) enabled in Debug mode.
- Linting: Pre-configured
.clang-tidy. - Static Analysis: Integration with
cppcheckandflawfinder. - Formatting: Auto-formatting via
clang-format.
- Testing: GoogleTest (GTest) integration via
FetchContent(no manual installation required). - Code Coverage: LLVM Source-based Code Coverage exporting to LCOV.
- Dependency Management: Clean separation in
Dependencies.cmake. - CI/CD (GitHub Actions):
- Automated testing and linting on push/PR.
- Snyk vulnerability scanning.
- Auto-Release: Pushing a tag (e.g.,
v1.0.0) automatically builds and uploads.deb,.rpm,.tar.gz,.zip, and.dmginstallers.
To use the full feature set of this template, ensure you have the following installed:
- C++ Compiler:
clangandclang++(Recommended) or GCC. - Build Tools:
cmake,make(orninja). - Quality Tools:
clang-tidy,clang-format,cppcheck. - Python Tools:
pip install flawfinder. - Security (Optional):
snykCLI (for dependency vulnerability scanning).
-
Clone the repository: ```bash git clone https://github.com/yourusername/your-project.git cd your-project ```
-
Build and Run (One command): ```bash make run ``` This will configure the project, compile it, and execute the binary.
-
Run Tests: ```bash make test ```
The included Makefile simplifies day-to-day development.
| Command | Description |
|---|---|
make |
Configures and builds the project (Debug mode). |
make run |
Builds and runs the main executable. |
make test |
Builds and runs unit tests (with output on failure). |
make format |
Auto-formats all .cpp and .h files using clang-format. |
make clean |
Removes the build directory. |
make reconfig |
Forces CMake to re-run (useful if you added new files). |
| Command | Description |
|---|---|
make lint |
Runs clang-tidy in strict mode (warnings treated as errors). |
make analyze |
Runs cppcheck deep static analysis. |
make security-code |
Scans source code for vulnerabilities using flawfinder. |
make security-check |
Scans dependencies using snyk (Requires Snyk CLI). |
make coverage |
Generates a code coverage report (coverage.lcov) using LLVM. |
.
├── CMakeLists.txt # Main CMake configuration
├── Dependencies.cmake # External library management
├── Makefile # Developer shortcuts
├── src
│ ├── cpp # Source files (.cpp)
│ │ ├── main.cpp # Entry point
│ │ └── MyProgram # Module implementation
│ ├── include # Header files (.h / .hpp)
│ └── tests # GoogleTest unit tests
└── .github/workflows # CI/CD definitions
To add external libraries:
- Open
Dependencies.cmake. - Use
FetchContentorfind_packageto locate the library. - Append the library target to the
EXTERNAL_LIBSlist variable. - Run
make reconfig.
This project includes two GitHub Actions workflows:
-
C++ Professional CI:
- Runs on every Push and Pull Request to
main. - Steps: Build, Lint (Clang-Tidy), Static Analysis (Cppcheck), Security Scan (Flawfinder & Snyk), Unit Tests, and Format Check.
- Note: To enable Snyk, add
SNYK_TOKENto your repository Secrets.
- Runs on every Push and Pull Request to
-
Build & Release Packages:
- Triggered when you push a tag starting with
v(e.g.,git tag v1.0.0 && git push --tags). - Builds the project in Release mode.
- Generates artifacts via CPack:
- 🐧 Linux:
.deb,.rpm,.tar.gz - 🪟 Windows:
.zip - 🍎 macOS:
.dmg
- 🐧 Linux:
- Creates a GitHub Release and attaches the artifacts.
- Triggered when you push a tag starting with
To make this template your own:
- Edit
CMakeLists.txt: Changeproject(MyProject ...)to your project name. - Edit
Makefile: ChangeBINARY_NAME = MyProject.
Distributed under the MIT License. See LICENSE for more information.