Skip to content

Coditary/CPP-Default-Project

Repository files navigation

Modern C++ Starter Template

Language Build License

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.

🚀 Features

  • Modern Standard: Configured for C++20.
  • Build System: CMake (3.20+) wrapped in a convenient Makefile for 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 cppcheck and flawfinder.
    • 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 .dmg installers.

🛠 Prerequisites

To use the full feature set of this template, ensure you have the following installed:

  • C++ Compiler: clang and clang++ (Recommended) or GCC.
  • Build Tools: cmake, make (or ninja).
  • Quality Tools: clang-tidy, clang-format, cppcheck.
  • Python Tools: pip install flawfinder.
  • Security (Optional): snyk CLI (for dependency vulnerability scanning).

⚡ Quick Start

  1. Clone the repository: ```bash git clone https://github.com/yourusername/your-project.git cd your-project ```

  2. Build and Run (One command): ```bash make run ``` This will configure the project, compile it, and execute the binary.

  3. Run Tests: ```bash make test ```

🎮 Development Commands

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).

Code Quality & Security

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.

📂 Project Structure

.
├── 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

📦 Adding Dependencies

To add external libraries:

  1. Open Dependencies.cmake.
  2. Use FetchContent or find_package to locate the library.
  3. Append the library target to the EXTERNAL_LIBS list variable.
  4. Run make reconfig.

🚀 CI/CD Pipelines

This project includes two GitHub Actions workflows:

  1. 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_TOKEN to your repository Secrets.
  2. 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
    • Creates a GitHub Release and attaches the artifacts.

📝 Customization

To make this template your own:

  1. Edit CMakeLists.txt: Change project(MyProject ...) to your project name.
  2. Edit Makefile: Change BINARY_NAME = MyProject.

📄 License

Distributed under the MIT License. See LICENSE for more information.

About

A Default Project for C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published