https://github.com/timkrebs9/cppcmaketemplate
C++ project template with unit-tests, documentation, ci-testing and workflows.
https://github.com/timkrebs9/cppcmaketemplate
cmake cpp ctest unittest
Last synced: 29 days ago
JSON representation
C++ project template with unit-tests, documentation, ci-testing and workflows.
- Host: GitHub
- URL: https://github.com/timkrebs9/cppcmaketemplate
- Owner: timkrebs9
- License: mit
- Created: 2023-11-07T15:23:35.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-07T16:28:28.000Z (almost 2 years ago)
- Last Synced: 2025-01-26T17:28:33.469Z (8 months ago)
- Topics: cmake, cpp, ctest, unittest
- Language: CMake
- Homepage: https://tim-krebs.github.io/CppCmakeTemplate/
- Size: 149 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Template For C++ Projects



[](https://github.com/tim-krebs/CppCmakeTemplate/actions/workflows/macos.yml)
[](https://github.com/tim-krebs/CppCmakeTemplate/actions/workflows/windows.yml)
[](https://github.com/tim-krebs/CppCmakeTemplate/actions/workflows/documentation.yml)This is a template for C++ projects. What you get:
- Library, executable and test code separated in distinct folders
- Use of modern CMake for building and compiling
- External libraries installed and managed by
- [CPM](https://github.com/cpm-cmake/CPM.cmake) Package Manager OR
- [Conan](https://conan.io/) Package Manager OR
- [VCPKG](https://github.com/microsoft/vcpkg) Package Manager
- Unit testing using [Catch2](https://github.com/catchorg/Catch2) v2
- General purpose libraries: [JSON](https://github.com/nlohmann/json), [spdlog](https://github.com/gabime/spdlog), [cxxopts](https://github.com/jarro2783/cxxopts) and [fmt](https://github.com/fmtlib/fmt)
- Continuous integration testing with Github Actions and [pre-commit](https://pre-commit.com/)
- Code coverage reports, including automatic upload to [Codecov](https://codecov.io)
- Code documentation with [Doxygen](https://doxygen.nl/) and [Github Pages](https://franneck94.github.io/CppProjectTemplate/)
- Tooling: Clang-Format, Cmake-Format, Clang-tidy, Sanitizers## Structure
``` text
├── CMakeLists.txt
├── app
│ ├── CMakesLists.txt
│ └── main.cc
├── cmake
│ └── cmake modules
├── docs
│ ├── Doxyfile
│ └── html/
├── external
│ ├── CMakesLists.txt
│ ├── ...
├── src
│ ├── CMakesLists.txt
│ ├── my_lib.h
│ └── my_lib.cc
└── tests
├── CMakeLists.txt
└── main.cc
```Library code goes into [src/](src/), main program code in [app/](app) and tests go in [tests/](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): lcov, gcovr
- Optional: Makefile, Doxygen, Conan, VCPKG## Building
First, clone this repo and do the preliminary work:
```shell
git clone --recursive https://github.com/franneck94/CppProjectTemplate
make prepare
```- App Executable
```shell
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release --target main
cd app
./main
```- Unit testing
```shell
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --config Debug --target unit_tests
cd tests
./unit_tests
```- Documentation
```shell
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --config Debug --target docs
```- Code Coverage (Unix only)
```shell
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON ..
cmake --build . --config Debug --target coverage
```For more info about CMake see [here](./README_cmake.md).