This is a minimalistic C++ project which demonstrates the use of ClangFormat.cmake module which can be found here.
The module itself requires CMake 3.0 or higher and any version of clang-format installed. You will also need a C++ compiler for CMake to be able to generate the build system.
-
Obtain the project:
$ git clone https://github.com/zemasoft/clangformat-cmake-example $ cd clangformat-cmake-example $ git submodule update --init --recursive
-
Generate the build system:
$ cmake -S . -Bbuild
-
Format sources anytime using
clangformat
target:$ cmake --build build --target clangformat
or:
$ cd build $ make clangformat
-
Build the project:
$ cmake --build build
or:
$ cd build $ make
-
Sources to play with:
-
Format style configuration:
-
If you want to use clang-format that is not on your search path, you have to supply CMake with
-DCLANGFORMAT_EXECUTABLE=/path/to/clang-format
.