https://github.com/dstrebkov/cpp-cmake-project-template
CMake based C++ Project Template
https://github.com/dstrebkov/cpp-cmake-project-template
c-plus-plus cmake cpp doctest fakeit gcov gcovr testing unit-testing
Last synced: 3 months ago
JSON representation
CMake based C++ Project Template
- Host: GitHub
- URL: https://github.com/dstrebkov/cpp-cmake-project-template
- Owner: dstrebkov
- License: mit
- Created: 2023-02-06T13:21:44.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-13T17:03:47.000Z (about 2 years ago)
- Last Synced: 2024-10-24T02:30:32.420Z (8 months ago)
- Topics: c-plus-plus, cmake, cpp, doctest, fakeit, gcov, gcovr, testing, unit-testing
- Language: CMake
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
cpp-cmake-project-template
================
[](https://codecov.io/gh/dstrebkov/cpp-cmake-project-template)

CMake based C++ project template that could be used as a starting point for a new C++ project.
CMake ≥ `3.14.0` is required.
## Contents
- static library `factorial` configured with unit testing framework(s);
- application `app_factorial` that links with the library to run some code.
## Unit testing
The library is configured with [Doctest](https://github.com/doctest/doctest) ([`v2.4.9`](https://github.com/doctest/doctest/releases/tag/v2.4.9)) for unit testing + [FakeIt](https://github.com/eranpeer/FakeIt) ([`2.3.2`](https://github.com/eranpeer/FakeIt/releases/tag/2.3.2)) for mocking.
These frameworks are obtained from GitHub using CMake's functions `FetchContent_Declare()` and `FetchContent_MakeAvailable()`.
## Project structure
```
.
│
├── app_factorial/ # Factorial application binary
│ ├── include # Application includes
│ ├── src # Application sources
│ │ └── main.cpp # Main entry of the sample factorial application
│ ├── test/ # Application test folder
│ └── CMakeLists.txt # Compile script for application
│
├── include # Place for built library includes
│
├── factorial # Static library
│ ├── include # Library includes
│ │ └── factorial.h # Library header
│ ├── src # Library sources
│ │ └── factorial.cpp # Library source
│ ├── test/ # Library tests
│ │ ├── factorial_test.cpp # Tests for the library
│ │ └── CMakeLists.txt # Compile script for tests of library
│ └── CMakeLists.txt # Library compile script
│
├── libs # Place for built library binaries
└── CMakeLists.txt # Main compile script
```## Instructions
Compile and make:
```
mkdir cmake-build
cd cmake-build/
cmake ..
make
```Run `app_factorial` application:
```
cd app_factorial/
./app_factorial
```Run unit tests (called from `cmake-build` folder):
```
cd ..
ctest
```## Useful Links
* [Doctest Tutorial](https://github.com/doctest/doctest/blob/master/doc/markdown/tutorial.md)
* [FakeIt Quickstart](https://github.com/eranpeer/FakeIt/wiki/Quickstart)