This template serves as a foundation for designing and developing projects in C++, fully equipped for immediate use. It includes features for build management, unit testing, continuous integration, static analysis, code style adherence, automated documentation generation, and component specification.
Before building the project, ensure you have CMake and Ninja installed on your system. These tools are essential for configuring, building, and managing dependencies.
This project requires the Clang compiler and related LLVM tools for compilation, static analysis, and code coverage:
- Windows: Download the LLVM installer from the LLVM Releases page. During installation, select the option to add LLVM to your system PATH.
- macOS: Install via Homebrew with
brew install llvm. You may need to update your PATH to use the Homebrew-installed version instead of the system version. - Linux: Install via package manager. For Ubuntu, you can use: sudo apt-get install clang clang-tidy llvm
CMake is a cross-platform build system generator. To install CMake:
- Windows: Download the installer from the CMake Downloads page and follow the installation prompts. Ensure you select the option to add CMake to your system PATH.
- macOS: Use Homebrew by running
brew install cmakein the terminal, or download the macOS binary from the CMake website. - Linux: Most distributions include CMake in their package managers. For example, on Ubuntu, you can install it with
sudo apt-get install cmake.
Ninja is a small build system focused on speed. To install Ninja:
- Windows: Download the latest binary from Ninja's GitHub releases page. Extract the executable and add its location to your system's PATH.
- macOS and Linux: Ninja can be installed through Homebrew on macOS (
brew install ninja) or through the package manager on Linux (for example,sudo apt-get install ninja-buildon Ubuntu).
Doxygen is used to generate project documentation from code comments:
- Windows: Download the installer from the Doxygen Downloads page.
- macOS: Install via Homebrew with
brew install doxygen graphviz. - Linux: Install via package manager, for example:
sudo apt-get install doxygen graphviz.
This project uses CMake as its build system, with Ninja as the preferred generator for efficiency and speed. Follow these steps to build the project:
This repository includes vcpkg as a submodule:
git clone --recurse-submodules https://github.com/yourusername/cpp-template.gitIf you've already cloned the repository without submodules, run:
git clone https://github.com/yourusername/cpp-template.git
git submodule update --init --recursivecd cpp-template/vcpkg
# Windows:
.\bootstrap-vcpkg.bat
# Linux/macOS:
./bootstrap-vcpkg.shcmake -B build -S . \
-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_CXX_COMPILER=clang++ \
-DENABLE_COVERAGE=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE=Debug \
-G Ninjacd build
ninjaThis project uses gtest_discover_tests from CMake's GoogleTest module for automatic test discovery.
cd build
ctest --output-on-failureGenerate HTML documentation from code comments using Doxygen:
# From project root
./scripts/generate_docs.shThe documentation will be available at build/docs/html/index.html.
Generate unified HTML coverage reports:
# From project root, run from build directory
cd build
../scripts/generate_coverage.shThe coverage report will be available at build/coverage_html/index.html.
The scripts/ directory contains helpful utilities:
generate_docs.sh: Generates Doxygen documentationgenerate_coverage.sh: Creates unified coverage reports from test runsformat-code.cmd: Windows batch script for code formatting
This repository includes a CircleCI pipeline to ensure high code quality and maintainability. The pipeline performs the following tasks:
- Dependency Management: Uses
vcpkgfor package management. - Build & Compilation: Uses
clangandNinjafor efficient builds. - Unit Testing: Runs tests via
ctestusingGoogle Test. - Static Analysis: Utilizes
clang-tidyfor code quality checks. - Code Coverage: Uses
llvm-covfor coverage reports. - Documentation Generation: Automatically generates and stores HTML documentation using Doxygen.
Maintaining code consistency is crucial to this project. We enforce strict formatting guidelines using clang-format.
- Windows:
.\scripts\format-code.cmd- Linux/macOS:
find ./src -iname '*.h' -o -iname '*.cpp' -exec clang-format -i {} +find ./src -iname '*.h' -o -iname '*.cpp' -exec clang-format -n -Werror {} +clang-tidy ./src/*.cpp -- -I./includeThis project uses Doxygen to generate comprehensive documentation from source code comments. The documentation includes:
- API documentation for all classes and functions
- Module organization and relationships
- Code examples and usage guidelines
- Automatically generated dependency graphs
To view the documentation, generate it using the script above and open build/docs/html/index.html in your web browser.
This project is licensed under the MIT License - see the LICENSE file for details.