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.shand 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 sbein 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++23for 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 setCXXandCCaccordingly. - 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/testthat is built fromsrc/main.test.cpp. - If you want to write a benchmark for
file.cpp, then createfile.bm.cpp,link_benchmarkagainst 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.cppfile. Seelib/CMakeLists.txtfor an example.
- If you want to write a test for
- Supports both
ReleaseandDebugtargets 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.aandlibname-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_PREFIXandLIB_BUILD_PREFIXenvironment variables. Checkbuild_boost.shandcmake/libboost.cmakefor examples. If theLIB_INSTALL_*_PREFIXandLIB_BUILD_*_PREFIXare not set, libraries are built in/tmpand 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