This is a cmake
project template that makes it easy to quickly start working on a C++23 project on Unix platforms.
Easiest is with nix
. Install it, invoke nix-shell
and in that shell run ./setup.sh
.
Building Release targets:
mkdir build_rel
cd build_rel
cmake -DCMAKE_BUILD_TYPE=Release ../
CMAKE_BUILD_TYPE
can be Debug
(default)/Release
.
To make this your own, replace all occurences of TEMPLATE
with your project's name.
- Statically links against minimal version of Boost with the most useful libraries. Add new
ones in
build_boost.sh
and link against them incmake/libboost.cmake
. - Statically links against Google Benchmark and Google Test.
- (optional) Statically links against fmt.
- Sets up the Simple Binary Encoding generator to generate C++
headers from a given schema. The headers can be generated with
make sbe
in the build dir. They'll be placed undersbe/include/sbe
. The schema to generate code from can be changed on the cmdline:cmake -DSBE_SCHEMA=/path/to/my/schema.xml ../
. - Uses
clang++
andC++23
for everything. It works out of the box on Linux and BSD systems. It is also possible to build the dependencies and project itself withg++
. Just setCXX
andCC
accordingly. - Provides an easy way to setup tests and benchmarks:
- If you want to write a test for
file.cpp
, then createfile.test.cpp
, write your tests and then run them from./build/src/test
. All project tests are run by./build/src/test
that is built fromsrc/main.test.cpp
. - If you want to write a benchmark for
file.cpp
, then createfile.bm.cpp
,link_benchmark
against it and then you can run it after building the project. All benchmarks have a separate binary i.e. there is a target built for each*.bm.cpp
file. Seelib/CMakeLists.txt
for an example.
- If you want to write a test for
- Supports both
Release
andDebug
targets and ensures that the statically linked libraries are built in the same way. That means we are actually building two versions of each library:libname-release.a
andlibname-debug.a
. - Adheres to most of Google's C++ Style Guide. See
.clang-format
. - Allows you to build and install libraries from a custom directory. This is done through the
LIB_INSTALL_PREFIX
andLIB_BUILD_PREFIX
environment variables. Checkbuild_boost.sh
andcmake/libboost.cmake
for examples. If theLIB_INSTALL_*_PREFIX
andLIB_BUILD_*_PREFIX
are not set, libraries are built in/tmp
and installed in/usr/local
.
- linking with mold:
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=mold"
- checking toolchain:
readelf -p .comment src/test