Skip to content

duckie/cpp_project_template

Repository files navigation

C++ project template

Travis CI Build Status Appveyor Build Status codecov.io Documentation Status

This is a layout to bootstrap a complete C++ project with several modules, test code and various tooling to get on a sane development workflow. The directory layout looks over engineered for so small a source code, but it aims at being able to scale with a lot of files, modules and 3rdparties while avoiding clutter and name conflicts.

The actual source has three modules:

  • projectlib is the business code of a library, with public headers and compilation units. The projectlib directory name is replicated for public headers to keep consistency with system wide deployment through a package.
  • projectrun contains only compilation units and is a business executable.
  • testlib contains only compilation units (yet) and is supposed to hold test code, objects and tools shared by the other modules.

Non system third parties are supposed to be stored or referenced (either via copy, submodule or CMake external project) in the 3rdparty directory. System third parties may be referenced to directly with CMake modules.

Tooling includes:

  • Automatic configuration for YouCompleteMe
  • Code coverage with gcov and lcov
  • Code formatting with clang-format
  • Code checking with clang-tidy
  • Cloud continuous integration
  • Sanitizers builds
  • A trick to prefix every test executable with your own command, with arguments if you want (ex: valgrind --leak-check=full) without using the strange CMake Dart thing.
  • Documentation generation with Doxygen and Sphinx+Breathe.

This project is distributed under the MIT license.

Simple compilation

mkdir build
cd build
cmake ../
make
ctest
./bin/runcppproject

The cmake output will prompt about detected tools and availabe targets to use them.

clang-tidy

To execute clang-tidy on every file compiled by the project, from the build dir :

./run-clang-tidy.py

It will execute clang-tidy with the same -I and -D options from your CMake files. Any additional argument passed to the script is forwarded. Example:

./run-clang-tidy.py -checks=*

Sanitizer builds

To make a sanitizer build, customize cmake/SanitizerBlacklist.txt.in at your will then

cmake ../ -DPROJECT_BUILD_SANITIZER_TYPE=${sanitizer_type}

Where sanitizer_type is either address, memory, thread or undefined.

Prefixing tests

A function called project_add_test has the exact same signature than the built-in add_test. Tests added with it are prefixed before launch with the content of the PROJECT_TEST_COMMANDS_PREFIX variable. Example:

cmake ../ -DPROJECT_TEST_COMMANDS_PREFIX="valgrind --leak-check=full"

About

A simple template to start quickly a C++ project managed by CMake.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published