Home
Softono

CppProjectTemplate

Open source MIT CMake
301
Stars
110
Forks
5
Issues
13
Watchers
2 years
Last Commit

 About CppProjectTemplate

C++ project template with unit-tests, documentation, ci-testing and workflows.

Platforms

Web Self-hosted

Languages

CMake

Links

Need Help Installing CppProjectTemplate?

We provide expert installation service for this software. Our team will install, configure, and secure CppProjectTemplate on your server. plans start at just $30.

CppProjectTemplate

View on GitHub

Template For C++ Projects

C++ License Linux Build

This is the final project of my Udemy Course. See here to get the full discount to all of my Udemy Courses: Link

This is a template for modern C++ projects. What you get is:

  • Library, executable and test code separated in distinct folders
  • Use of modern CMake for building and compiling
  • External libraries installed and managed by
    • CPM Package Manager OR
    • Conan Package Manager OR
    • VCPKG Package Manager
  • Unit testing using Catch2 v2
  • General purpose libraries: JSON, spdlog, cxxopts and fmt
  • Continuous integration testing with Github Actions and pre-commit
  • Code documentation with Doxygen and Github Pages
  • Tooling: Clang-Format, Cmake-Format, Clang-tidy, Sanitizers

Structure

├── CMakeLists.txt
├── app
│   ├── CMakesLists.txt
│   └── main.cc
├── cmake
│   └── cmake modules
├── docs
│   ├── Doxyfile
│   └── html/
├── external
│   ├── CMakesLists.txt
│   ├── ...
├── src
│   ├── CMakesLists.txt
│   ├── foo/...
│   └── bar/...
└── tests
    ├── CMakeLists.txt
    └── test_*.cc

Library code goes into src/, main program code in app/ and tests go in tests/.

Software Requirements

  • CMake 3.21+
  • GNU Makefile
  • Doxygen
  • Conan or VCPKG
  • MSVC 2017 (or higher), G++9 (or higher), Clang++9 (or higher)
  • Optional: Code Coverage (only on GNU|Clang): gcovr
  • Optional: Makefile, Doxygen, Conan, VCPKG

Building

First, clone this repo and do the preliminary work:

git clone --recursive https://github.com/franneck94/CppProjectTemplate
mkdir build
  • App Executable
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release --target main
cd app
./main
  • Unit testing
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE="Debug"
cmake --build build --config Debug
cd build
ctest .
  • Documentation
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --config Debug --target docs
  • Code Coverage (Unix only)
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=On
cmake --build build --config Debug --target coverage -j4
cd build
ctest .

For more info about CMake see here.