Skip to content

dstrebkov/cpp-cmake-project-template

Repository files navigation

cpp-cmake-project-template

github-actions codecov language repo size

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 (v2.4.9) for unit testing + FakeIt (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