A template C++ repository, using CMake and Catch

Overview

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 - 
   

   

Just replace 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 [email protected]:joshpeterson/cpp-template.git
> ./build

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

> brew install cmake ninja
> git clone [email protected]:joshpeterson/cpp-template.git
> ./build

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

> git clone [email protected]: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:

  • The src directory is the location of all of the project's source code (header files and source files). The main.cpp file is built into the final executable, all other source files in this directory are built into a static library. Only code in this static library will be tested.
  • The test directory contains the unit tests. The unit test executable links with the static library built from src directory.
  • The thirdparty directory contains external code used by this project, namely, Catch and the CMake sanitizer integration.
  • The tools directory contains a number of scripts used for building and other tool integration with the project.

Other tool integration

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

  • The clang-format utility is used to enforce common source code formatting. The tools/format script can be used locally to update code formatting to match the style in the .clang-format file. The tools/run-clang-format.py script is used on Travis CI to check formatting.
  • The clang-tidy utility is used to run static analysis on the source code. The tools/tidy script can be used locally and on Travis CI to run clang-tidy.
  • The clang address, thread, and undefined behavior sanitizers are run on the unit tests. The tools/sanitize script can be used to run them locally.

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.

You might also like...
cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Make CMake less painful when trying to write Modern Flexible CMake
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

A template for projects using both libPeConv and MS Detours

A CMake template for projects using MS Detours along with libPeConv.

Example library that shows best practices and proper usage of CMake by using targets

Modern CMake Sample Sample project that shows proper modern CMake usage on a dummy library and an executable that uses it. Accompanying code to my blo

A toolchain file and examples using cmake for iOS development

ios-cmake A toolchain file and examples using cmake for iOS development. This is a fork of a similar project found on https://code.google.com/p/ios-cm

CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp

FindIDL CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp. Introduction Requirements Usage find_package() add_idl() ad

NeoWorld is a resampler using the CMake build system

NeoWorld is a resampler using the CMake build system. It's designed for utsu, OpenUTAU, and UTAU.

Simple library for embedding static resources into C++ binaries using CMake

libromfs libromfs is an easy way to bundle resources directly into any C++ application and access them through a simple interface. The main advantage

Owner
Joshua Peterson
A software developer with @UnityTechnologies leading the .NET VM Team (IL2CPP, Mono, CoreCLR)
Joshua Peterson
Template for reliable, cross-platform C++ project setup using cmake.

The C++ CMake Project Template cmake-init is a sophisticated copy & paste template for modern C and C++ projects. The main goals include support of al

CG Internals 811 Jan 3, 2023
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

Jose Luis Blanco-Claraco 395 Dec 24, 2022
CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

HPC 82 Nov 30, 2022
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 74 Dec 26, 2022
An OS-agnostic C++ library template in plain CMake.

?? How to export C++ library This repository provides an OS-agnostic C++ library template with plain CMake files with the following features: distribu

Robotology 302 Dec 17, 2022
A small c++ template with modern CMake

C++/CMake modern boilerplate This is a template for new projects, gives a good CMake base and a few dependencies you most likely want in your project.

Clément Grégoire 276 Jan 3, 2023
A minimal CMake template for Qt 5 & 6 projects

Minimal CMake Template for Qt 6 Projects This project is updated for Qt 6. Visit qt5 branch if you are looking for the Qt 5 template. This is a minima

Vincent Lee 180 Sep 21, 2022
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.6k Jan 9, 2023
CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

Cristian Adam 65 Dec 6, 2022
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

Anders Lindgren 39 Oct 2, 2022