A modern C++ template repository with CMake build system, integrated dependencies, and comprehensive tooling support.
- Modern C++ Standards: Built with C++23 support
- CMake Build System: Clean, modular build configuration
- Integrated Dependencies: Pre-configured popular C++ libraries
- Development Tools: Built-in code analysis with cppcheck
- Flexible Build Options: Debug, release, and examples modes
- Submodule Management: Automated dependency setup
This template includes the following pre-configured libraries:
- Prometheus C++: Metrics and monitoring library
- spdlog: Fast C++ logging library
- glaze: High-performance JSON library
- CMake 3.23.3 or higher
- C++23 compatible compiler (GCC/Clang)
- Git (for submodule management)
- cppcheck (for static analysis)
git clone https://github.com/ShinyMacadamia/cpp-template.git
cd cpp-template
make configureThe configure step will:
- Initialize and update all git submodules
- Build and install Prometheus C++ library
- Build spdlog library
- Build and install glaze library
# Debug build (default)
make build
# Release build
make build-release
# Build and run immediately
make run
# (Optionally) Make compile definitions for clangd
make definitions- Add source files to the
src/directory - Update the
target_sources()section inCMakeLists.txtto include your files - Add example programs in the
examples/directory
| Command | Description |
|---|---|
make configure |
Set up dependencies and submodules |
make build |
Build in debug mode |
make build-release |
Build in release mode |
make run |
Build and run the executable |
make definitions |
Generate compile definitions |
make check |
Run static analysis with cppcheck |
make clean |
Remove build artifacts and dependencies |
cpp-template/
├── src/ # Source files
│ └── main.cpp # Main entry point
├── examples/ # Example programs
├── vendor/ # Dependencies
│ ├── prometheus-cpp/ # Metrics library
│ ├── spdlog/ # Logging library
│ ├── glaze/ # JSON library
│ └── include/ # Installed headers
├── build/ # Build output (generated)
├── CMakeLists.txt # Main CMake configuration
├── Makefile # Build automation
├── build.sh # Build script
└── configure # Dependency setup script
- Add the dependency as a git submodule in the
vendor/directory - Update the
configurescript to build and install the dependency - Modify
vendor/CMakeLists.txtto link the new library - Update the
INCLUDE_LIBSvariable if needed
Build example programs instead of the main executable:
./build.sh examplesEnable AddressSanitizer by uncommenting the relevant lines in CMakeLists.txt:
target_compile_options(cpp-template PRIVATE -fsanitize=address)
target_link_options(cpp-template PRIVATE -fsanitize=address)- Initial Setup: Run
make configureonce to set up all dependencies - Development: Use
make buildfor quick debug builds - Testing: Use
make runto build and test immediately - Quality Assurance: Use
make checkfor static analysis - Release: Use
make build-releasefor optimized builds
The template includes cppcheck configuration for comprehensive static analysis:
make checkThis runs cppcheck with the following options:
- All checks enabled
- Inconclusive results included
- Missing system includes suppressed
- Inline suppressions allowed