This project aims to provide a quick and easy way to integrate clang-format into your CMake project hosted in a git repository, it consists of three elements.
CMakeLists.txtprovides the custom
git-pre-commit-hookblocks commits of unformatted C/C++ files
git-cmake-format.pyis called by the
formattarget or the
pre-commithook, it queries git for edited files, then block the commit or formats the sources
There are three dependencies:
To make use of this project you can either add it as a submodule to your existing project, or copy the files into your repository. Now add the following to your
Next you can generate your build system, assuming the required dependencies are available on your path.
cd build cmake ..
The installation of the
pre-commit hook is done at CMake time during the generation of the build system, if you have followed these steps it is already installed at
It is possible to specify the path to any of the executables this project depends upon using the following CMake variables.
It is also possible to set the
-style= command line argument for
clang-format with the following options, the default is