Skip to content

maxim0x2929/cpp-project-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Project Template

A simple and minimalistic C++ project template to kickstart your C++ development. Includes a basic structure, style enforcement, static analysis, unit testing, and a convenient Makefile workflow.


📚 Style Guide

This project follows the Google C++ Style Guide to maintain consistent and clean code.


✅ Prerequisites

Before using this template, install the following tools:

sudo apt-get install -y astyle
sudo apt-get install -y cppcheck

🚀 Usage

Initialize the Project

Sets up the initial folder structure (e.g., build directory, etc.)

make init

Compile the Code

make build

Run the Executable

make run

Clean Build Files

make clean

🧪 Unit Tests

Unit tests are written using a simple macro-based testing framework included in the template.

Creating a Test File

  1. Create a new file named Test_<YourTestName>.hpp.

  2. Include the base test header:

    #include "TestBase.hpp"
  3. Define your test suite using the UNIT_TEST(<TestName>) macro.

  4. Add your test cases using the TEST(<FunctionName>) macro.

    • Names must be valid function names and must be unique.

Example

UNIT_TEST(MyMathTest)

TEST(Addition) {
    assert(2 + 2 == 4);
}

TEST(Subtraction) {
    assert(5 - 3 == 2);
}
  1. Include your test file in main.cpp at the top:
#include "Test_MyMathTest.hpp"

Run Unit Tests

make unit-test

🎨 Format Code

Automatically format all source files using AStyle:

make format

🔍 Analyze Code

Run static analysis with Cppcheck:

make analyse

🌱 Git Workflow

Create a Branch

git checkout -b "dev/<branch-name>"

or

git branch dev/<branch-name>
git checkout dev/<branch-name>

Commit Changes

git add <file(s)>
git commit -m "<commit message>"
git push

Update Local Repository

git pull

Merge a Branch

git checkout main
git pull
git merge -m "<merge message>" dev/<branch-name>
git push

🧾 Naming Conventions

  • Branches: dev/<feature-or-topic-name>
  • Files: Use lowercase and underscore for filenames (e.g., hello_world.hpp)
  • Classes: PascalCase (e.g., HelloWorld)
  • Variables/Functions: camelCase (e.g., printMessage, messageText)
  • Constants: UPPER_CASE_WITH_UNDERSCORES (e.g., MAX_BUFFER_SIZE)

About

Simple and minimalistic C++ project templet to kickstart a project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published