Skip to content

About

Repository template for a basic modern C++ project with CMake as the build system and vcpkg for dependency management.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

C++ CMake + vcpkg Template

A modern C++23 project template using:

  • CMake
  • vcpkg (Manifest Mode)
  • Ninja
  • clangd
  • clang-format
  • clang-tidy

The template is Linux-first but fully supports Windows.

Important

In case VSCode or another editor is acting up in regards to files not being found or classes not existing, make sure to restart the clangd language server, that should fix the issue. Also note that you should first run one of the build scripts (build.sh for Unix systems, build.bat for Windows) to generate the compiler commands.


Features

  • C++23
  • vcpkg dependency management
  • CMake Presets
  • clangd-ready
  • VS Code ready
  • Neovim friendly
  • GCC, Clang and MSVC support

Requirements

Fedora

sudo dnf install \
git \
gcc-c++ \
clang \
clang-tools-extra \
cmake \
ninja-build \
lldb \
python3

Ubuntu / Debian

sudo apt install \
git \
build-essential \
clang \
clang-tools \
cmake \
ninja-build \
lldb \
python3

Arch Linux

sudo pacman -S \
git \
base-devel \
clang \
cmake \
ninja \
lldb \
python

openSUSE

sudo zypper install \
git \
gcc-c++ \
clang \
clang-tools \
cmake \
ninja \
lldb \
python3

Windows

Install:

  • Visual Studio 2022 Build Tools (Desktop development with C++)
  • CMake
  • Ninja
  • Git
  • LLVM (clang, clang-format, clang-tidy, lldb)

Install vcpkg

Clone vcpkg somewhere permanent.

git clone https://github.com/microsoft/vcpkg.git ~/Development/tools/vcpkg

Bootstrap it.

Linux/macOS:

cd ~/Development/tools/vcpkg
./bootstrap-vcpkg.sh

Windows:

bootstrap-vcpkg.bat

Configure VCPKG_ROOT

Linux:

export VCPKG_ROOT=$HOME/Development/tools/vcpkg

Add that to your shell configuration (~/.bashrc, ~/.zshrc, etc.).

Windows:

setx VCPKG_ROOT C:\Development\vcpkg

Restart your terminal afterwards.


Usage

To use this template you have 2 options

  1. Clone the Repository
mkdir your-cpp-project
cd your-cpp-project
git clone https://github.com/TheVolpeDev/cpp-vcpkg-cmake-template.git .
  1. Create a repository based on this template

For this you can either click the "Use This Template" button on the Github web interface, or use this link for quick creation


Build

Debug

./build.sh

Release

./build.sh release

Windows

build.bat
build.bat release

Adding Dependencies

Edit vcpkg.json.

Example:

{
  "dependencies": ["fmt", "spdlog", "entt"]
}

Re-run the build script.

vcpkg will automatically install any missing dependencies.


Recommended VS Code Extensions

  • clangd
  • CMake Tools
  • CodeLLDB

The repository already recommends these extensions automatically.


Neovim & Other Editors

The template generates compile_commands.json, allowing clangd to work without any additional configuration.


About

Repository template for a basic modern C++ project with CMake as the build system and vcpkg for dependency management.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages