Skip to content

A capable template for C++ projects using CI, Building, Testing, Formatting, Documenting and more

License

Notifications You must be signed in to change notification settings

dimanikulin/capable-cpp-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Your Logo

GitHub contributors GitHub followers Commit activity Last commit
GitHub release (latest by date including pre-releases) GitHub all releases GitHub Release Date
Main flow GitHub code size in bytes GitHub repo size
GitHub issues GitHub closed issues GitHub pull requests GitHub closed pull requests
GitHub Discussions License

Quick Links

Description

A template for C++ projects featuring CI, building, testing, formatting, documentation, and more.

Designed as a starting point with a wide range of features that can be easily included or excluded based on your needs.

This template reflects my personal approach, so you may have different preferences regarding its implementation.

Any feedback is greatly appreciated!

Features

# Feature CI Description
License N/A Fully open license. The project is licensed under the Unlicense
MD templates N/A Attractive main README (Logo, Badges, Quick Links, Tables, Diagrams, References)
Static analysis Yes By CppCheck GitHub Action
Code Checks Yes By Python scripts: TBD
Building Yes Build with Ninja and CMake, Use of Ccache to speed up the rebuilds
Testing Yes Unit testing with GTest and CTests (with an option to enable), uploading results to GitHub
Coverage Yes Using GCov and LCov, ziping by 7xip, uploading report to GitHub
Formatting Yes Using clang-format and Google code style configuration - to format C and CPP code
Packaging Yes Stripping binaries, ziping by 7xip, uploading binaries to GitHub, Windows package by WiX
Documentation Yes Using Doxygen, Publishing documentation on GitHub Pages
CI Yes Using GitHub Actions CI workflows for Windows, Linux and MacOS operation systems
gitignore N/A Uses well known ignore file from this repo
QT Yes Installed on CI only

What is important - you can easialy disable the things you don't use.

Initialization

There are two ways to install the project:

If you would like to clone the repository please run:

git clone https://github.com/dimanikulin/capable-cpp-template/

Readme.md

You need to provide an icon at ./resources/icons/main.png if you wish to include an icon in this README file.

Update the href in badges to point to your repository (note: the repository must be public to use badges)

GitHub supports Mermaid.js for creating diagrams, such as:

flowchart LR
    B -->|Multimedia data| C(Online Multimedia IR system)
    B -->|Multimedia data| D(Offline Multimedia IR system)
    A(Photo Album owner) --> B(FVA Solution)
    A(Photo Album owner) --> D1
    A(Photo Album owner) --> D2
    A(Photo Album owner) --> D3
    D1(fa:fa-tablet Tablet) -->|Multimedia data| B(FVA Solution)
    D2(fa:fa-phone Phone) -->|Multimedia data| B(FVA Solution)
    D3(fa:fa-hdd-o External Disk) -->|Multimedia data| B(FVA Solution)
Loading

Building

Then please update "Project" in CMakeLists.txt

project(
  "Project"
  VERSION 0.1.0
  LANGUAGES CXX
)

with your project name.

Building

To build the project you will need to run CMake routine like to the one below:

mkdir build/ && cd build/
cmake --build . 

You can build it locally and in a CI environment.

Testing

The template uses Google Test for unit testing. Unit testing is enabled by default via the BUILD_TESTS option. To run tests, use CTest from the build directory:

cd build          
ctest -C Release

Tests can be executed both locally and in a CI environment.

Code coverage

Make sure to have the same version of g++ and gcov, otherwize you will see a report creation issue. Use sudo update-alternatives to fix that.

First of all you will need to install coverage tool by

sudo apt-get update
sudo apt-get -y install lcov

Then you will need to run the capture for coverage

lcov --capture --directory ./build --output-file ./build/coverage.info --ignore-errors mismatch

Cause the coverage report must be clear it is suggested to run filtering

lcov --remove ./build/coverage.info --directory ./build -o ./build/filtered_coverage.info \
'/usr/include/*' \
'/include/gtest/*' \
'*/test/*' \
'*/googletest/*'

Last but not least there will be translation coverage report to html format

genhtml ./build/filtered_coverage.info --output-directory coverage_report

Packaging

Windows is supported now only by using Wix.

Formatting

Prerequisites - clang-format 17 or later and its configuration in file .clang-format

Installing clang-format

wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 17
sudo apt install clang-format-17
rm ./llvm.sh

For reformatting please run following cmds:

find tests -regex '.*\.\(cpp\|h\|cc\|cxx\)' -exec clang-format-17 -i {} \;
find src -regex '.*\.\(cpp\|h\|cc\|cxx\)' -exec clang-format-17 -i {} \;

Documentation

Please see releaseDocs.yml for more details

Using QT

Now supported on CI only.

Static analyzers

Please refer to codeChecks.yml to see implementation for CppCheck

Also this code might be used for static analyzing based on clang

clang-tidy:
  stage: clang-tidy
  script:
    - cmake -Bbuild_stat_analyser -H. -D CMAKE_EXPORT_COMPILE_COMMANDS=ON -D BUILD_TESTING=OFF
    - cd build_stat_analyser
    - run-clang-tidy-17 -warnings-as-errors='*' -config-file ../.clang-tidy
  allow_failure: true

Coming features

  • QT support (CI and local)
  • Package manager support for Mac and Linux
  • CMake formatting
  • Versioning
  • Codes
  • MarkDown Lint
  • Dockerfile
  • Qt-oriented static code analyzer based on the Clang framework
  • find merging symbols like "<<<"
  • clang-tidy
  • code checks

Code checks

Check for boilerplate

You will need to update in boilerplate.txt to start using this check. Also please uncomment run of boilerplate_check.py in codeChecks.yml

Contributing

TBD

Author

Dmytro Nikulin

License

This project is licensed under the Unlicense - see the LICENSE file for details

References

# Name Source Release date Author Description
1 gitignore repository GitHub Repo TBD TBD TBD
2 QT Static analizer repository GitHub Repo TBD TBD TBD
3 Cpp project template repository GitHub Repo TBD TBD TBD
4 Google Tests repository GitHub Repo TBD TBD TBD

Made with Markdown