Quick Start
# Desktop
cmake -S . -B cmake-build-desktop -G "Ninja Multi-Config"
cmake --build cmake-build-desktop --config Debug
ctest --test-dir cmake-build-desktop -C Debug --output-on-failure
# Emscripten
emcmake cmake -S . -B cmake-build-emscripten -G "Ninja Multi-Config" -D CMAKE_CXX_FLAGS="-fno-exceptions"
cmake --build cmake-build-emscripten --config Debug
ctest --test-dir cmake-build-emscripten -C Debug --output-on-failure
# AVR
cmake -S . -B cmake-build-avr-gcc -G "Ninja Multi-Config" -D CMAKE_TOOLCHAIN_FILE="cmake/toolchain/atmega328p.cmake"
cmake --build cmake-build-avr-gcc --config Debug
Project Layout
├── benchmarks # Compile-time benchmarks
├── cmake # Compiler config
├── docs # Documentation
├── examples # Simple demos which only require libc & tetl
├── fuzzing # LLVM libFuzzer runner
├── include # Source code
├── scripts # Coverage & clang-tidy
└── tests # Unit tests
Tests
Boilerplate for unit tests:
#include "testing/testing.hpp"
namespace {
template <typename T>
constexpr auto test() -> bool
{
return true;
}
constexpr auto test_all() -> bool
{
CHECK(test<signed char>());
CHECK(test<signed short>());
CHECK(test<signed int>());
CHECK(test<signed long>());
CHECK(test<signed long long>());
CHECK(test<unsigned char>());
CHECK(test<unsigned short>());
CHECK(test<unsigned int>());
CHECK(test<unsigned long>());
CHECK(test<unsigned long long>());
return true;
}
}
auto main() -> int
{
STATIC_CHECK(test_all());
return 0;
}
constexpr auto cmp_equal(T t, U u) noexcept -> bool
Compare the values of two integers t and u. Unlike builtin comparison operators, negative signed inte...
Definition cmp_equal.hpp:21
Tools
CMake Presets
cmake --list-presets=all .
cmake --preset desktop
cmake --build --preset desktop
ctest --preset desktop
clang-tidy
cmake -S . -B cmake-build-tidy -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug
cmake --build cmake-build-tidy --parallel 8
run-clang-tidy -fix -j 8 -quiet -p cmake-build-tidy -header-filter $(realpath .) $(realpath .)
coverage
# build with coverage flags
cmake -S . -B cmake-build-coverage -G Ninja -D CMAKE_BUILD_TYPE=Debug -D CMAKE_CXX_STANDARD=23 -D TETL_BUILD_COVERAGE=ON
cmake --build cmake-build-coverage --parallel 8
# run gcov
gcovr --html-details -e ".*_3rd_party*" --exclude-unreachable-branches -r . -s cmake-build-coverage -o cmake-build-coverage/coverage.html -j 4
# or grcov (faster)
grcov . -s . --binary-path ./cmake-build-coverage/bin/ -t html --ignore-not-existing -o ./cmake-build-coverage/html/ --ignore '*_3rd_party/*' --threads 4
pre-commit
pre-commit install
pre-commit run -a
doxygen
doxygen Doxyfile
open build-doxygen/html/index.html
VS Code
Enable one of the following options in .vscode/settings.json
:
"cmake.useCMakePresets": "always"
"cmake.useCMakePresets": "never"
Coding Style
- Trailing return type is used everywhere:
auto func() {}
auto func() -> void;
auto func() -> double;
auto func() -> auto&;
auto func() -> decltype(auto);
- Keyword
class
is banned:
struct foo {};
enum struct foo { baz, baz };
template<typename T>
- Naming conventions:
- Public interface matches the STL conventions
- Checked via
clang-tidy
. See .clang-tidy config.
- Local variables & parameters are
camelBack
- Template arguments are
CamelCase
- Private members have a "\_" prefix. e.g.
int _val;