A template repository designed for medium to large C++ projects with multiple subprojects/executables. Includes
- CMake build system
- Automatic semantic versioning
- spdlog logging library
- Google Test framework
- Clang-format and clang-tidy
- Multiple target executables for main program, installer, auto-updater, tester, etc.
- Doxygen documentation
- Modern C/C++ compiler
- git 2.17+ installed
- CMake 3.13+ installed
- Clang tools 7.0+ namely clang-format and clang-tidy
- Python 3.6+ for tools
- Doxygen 1.8.17+ for documentation generation
Recommended IDE is VSCode with the following extensions
- C/C++ language support
- Clang-Format integration
- CMake language support
- CMake Tools
- Code Spell Checker
- Doxygen Documentation Generator
On Windows I recommend using vcpkg
- spdlog logging library
- Google Test framework
Clone the repository
> mkdir workspace
> cd workspace
> git clone https://github.com/WattsUp/CppProjectTemplate myProject
Configure the project with default compiler and compile
> cmake . -B build
> cmake --build build
- Open the project folder in VSCode with the recommended extensions
- Open the CMake Tools tab
- Select
Configure All Projects
, select appropriate compiler - Click
Build All Projects
bin
Binary folder, output directory for executables, add runtime resources here (icons, etc.)common
Common code shared amongst projects: logging, utilities, etc.docs
Documentation folderdocs\www
Documentation webpage root folder, ignored, clone of repository's gh-pages branchinclude
Public include folder for librarieslibraries
Third party librariestools
Helper code such as check coding conventions script
installer-win
Self-extracting installer executable which sets up directories, variables, etc.project-fractal
Application to draw a fractal to the consoleproject-library
Library to add two numbers together
- Clone the repository, see Git Clone. (Or download manually)
- Run the python script
tools/SetupProject.py
from the top level folder. It will guide you through the process. The script checks for all software dependencies (prompts for their installation), modifies top-level project name, modifies targets, resets the git repository to an initial commit, and tags the commit v0.0.0. The only dependency is the ability to run python scripts.
Note: Target names cannot have spaces in CMake. To have spaces in the output files uncomment the following in ./CMakeLists.txt
and duplicate as needed:
set_target_properties([TargetNoSpaces] PROPERTIES OUTPUT_NAME "Target With Spaces")
The docs/www
folder contains the documentation branch of this repo (gh-pages
for GitHub). Once the repository has a remote, clone that branch into that folder and use it to build a documentation website.
git clone [URL] -b gh-pages docs/www
- Updates to resource files are not detected by the generator. Perform a clean build if those change. Always perform a clean build for release.