Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-boilerplate

This is a very simple boilerplate for C++ compilation that does the following things:

  • Uses a package manager for dependency management.
  • Works on different OS-es: Linux, Windows
  • Can use different compilers: Clang, GCC, MSVC, etc.
  • Can use different generators: GNU Makefule, Ninja, etc.

I have created this boilerplate because I see a lot of C++ programmers who:

  • Manually copy-paste libraries around and get stuck with dependency management.
  • Use complex configurations in non-standard tools like Bash files and vendor-specific IDE configurations
  • Make their C++ code unnecessarily OS-dependent.

In practice, it is actually not that difficult to compile C++ projects in a professional way. That is what this boilerplate seeks to show.

Step 1: Install the prerequisites

  1. Install CMake (e.g. pip install -U cmake).
  2. Install Conan (e.g. pip install -U conan).
  3. Install a generator (e.g. Ninja, GNU Makefile).
  4. Install a C++ compiler (e.g. Visual Studio / MSVC, GCC, Clang).

See Appendix A for the versions that I currently use.

Step 2: Set your profile

conan profile detect

See Appendix B for the profiles that I currently use.

Step 3: Install the dependencies

${buildType} must match one of the build types in CMakePresets.json:

  • Debug
  • Release
conan install . -b missing -of build -s build_type=${buildType}

Step 4: Generate the build

${presetName} must match one of the presets in CMakePresets.json:

  • linux-debug
  • linux-release
  • windows-debug
  • windows-release
cmake --preset ${presetName}

Step 5: Build the binaries

cmake --build --preset ${presetName}

Step 6: Run the tools

On Linux:

./build/${presetName}/main

On Windows:

.\build\${presetName}\main.exe

Appendix A: Versions of tools

These are the versions of the tools that I use in Windows 11 and Ubuntu 24.04 (WSL):

Tool Version OS
Clang 20.1.2 Ubuntu 24.04
CMake 4.3.2 Ubuntu 24.04, Windows 11
Conan 2.29.1 Ubuntu 24.04, Windows 11
GCC 14.2.0 Ubuntu 24.04
Ninja 1.13.2 Ubuntu 24.04
Visual Studio 19.51.36248.0 Windows 11

Your versions may be different.

Appendix B: Conan profiles

The is my Conan profile on Windows 11:

[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=23
compiler.runtime=dynamic
compiler.version=195
os=Windows

[conf]
tools.cmake.cmaketoolchain:generator=Ninja
tools.cmake.cmaketoolchain:user_presets=

This is my Conan profile on Ubuntu 24.04 (WSL):

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++11
compiler.version=14
os=Linux

[conf]
tools.cmake.cmaketoolchain:generator=Ninja
tools.cmake.cmaketoolchain:user_presets=

You profile may be different.

About

A very simple boilerplate for cross-OS C++ compilation with dependency management.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages