Home

Awesome

C++ Project Template

Build
Status

This is a template project for C++. It uses CMake to build and Catch for unit tests. It is integrated with Travis CI, and builds on Windows, macOS, and Linux. It consists of one static library, one main function, and one test executable.

How to use this project

I like to use this project as a starting point for C++ projects. It has builds, tests, code formatting, static and dynamic analysis, and CI integration set up and ready to go.

Quick start

The cpp-template-installer.py script can be used to quickly create a project (you'll need to have python installed):

> curl https://raw.githubusercontent.com/joshpeterson/cpp-template/master/cpp-template-installer.py | python - <my project name>

Just replace <my project name> with the name of your project.

Manual installation

These are the step the python script above performs. You can do them manually as well:

  1. Clone or download the source code.
  2. Remove the .git/ directory, if is exists.
  3. Search the project for "cpp-template" and replace it with the name of your project.
  4. Replace this README.md file with one for your project.

Building

On Linux, you will need a C++ compiler installed, then run:

> sudo apt install cmake ninja-build
> git clone git@github.com:joshpeterson/cpp-template.git
> ./build

On macOS, you will need to have Xcode installed, then run:

> brew install cmake ninja
> git clone git@github.com:joshpeterson/cpp-template.git
> ./build

On Windows, you will need have Visual Studio installed with C++ tools, then run:

> git clone git@github.com:joshpeterson/cpp-template.git
> build

The build output should live in a directory named artifacts.

Project structure

The project has the following top-level directories:

Other tool integration

The project integrates with a few other tools to aid in development.

These tooling scripts are configured to run on Linux.

License

This project is available in the public domain.

Acknowledgements

The project is based on the Hello CMake project from Arne Mertz.

It uses the sanitizers-cmake for CMake integration of clang's sanitizers.