This is a cmake
project template that makes it easy to quickly start working on a C++ project on Unix platforms.
Run ./setup.sh
. This will install all the dependencies and build all the targets in Debug mode.
Building Release targets:
mkdir build_rel
cd build_rel
cmake -DCMAKE_BUILD_TYPE=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 HdrHistogram_c.
- Statically links against Google Benchmark and Google Test.
- Statically links against fmt.
- Uses
clang++
andC++20
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