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.
- Install CMake (e.g.
pip install -U cmake). - Install Conan (e.g.
pip install -U conan). - Install a generator (e.g. Ninja, GNU Makefile).
- Install a C++ compiler (e.g. Visual Studio / MSVC, GCC, Clang).
See Appendix A for the versions that I currently use.
conan profile detectSee Appendix B for the profiles that I currently use.
${buildType} must match one of the build types in CMakePresets.json:
DebugRelease
conan install . -b missing -of build -s build_type=${buildType}${presetName} must match one of the presets in CMakePresets.json:
linux-debuglinux-releasewindows-debugwindows-release
cmake --preset ${presetName}cmake --build --preset ${presetName}On Linux:
./build/${presetName}/mainOn Windows:
.\build\${presetName}\main.exeThese 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.
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.