Code Formatting

C/C++

The sources have a uniform coding formatting based on the Google Style.

The style is defined in the .clang-format file which when used by clang-format produces a correctly formatted source file.

Since the 5.10 release all source file modifications must be processed by clang-format to be accepted. The recommended way to do this is using a git pre-commit hook which applies formatting when committing changes

To do this, just install the pre-commit program from https://pre-commit.com/:

$ pip install pre-commit

and then, in the project top directory

$ pre-commit install

which will pick up the configuration from .pre-commit-config.yaml which is part of the project.

CMake

Cmake file uses formatting defined by the .cmake-format.yaml which when used with cmake-format produces correctly formatted files. This has been applied to all cmake/*.cmake files and CMakeLists.txt.

Using clang-format

clang is part of the llvm tools. These are usually installed using package managers like choco (Windows), brew (MacOS) or apt (Debian/Ubuntu).

To format a C, C++ or header file with clang-format with the project’s default configuration use:

clang-format -i  <filename>

Using cmake-format

Install cmake-format as described in https://github.com/cheshirekow/cmake_format. To format a single file use

cmake-format -i  <filename>

Editor and IDE configuration

There is a .editorconfig file in the top directory. This file could be used by most editors to define basic settings.

There are no standard configurations available for IDEs like Visual Studio Code, Eclipse or CLion.