clangformat-cmake
clangformat-cmake copied to clipboard
A simple CMake module for clang-format support
ClangFormat.cmake module
ClangFormat.cmake is a simple CMake module for clang-format support.
Requirements
The module requires CMake 3.0 or higher and some version of clang-format installed.
Integration
-
Obtain the module and add it into your project's CMake modules path:
-
Copy approach:
$ wget https://raw.githubusercontent.com/zemasoft/clangformat-cmake/master/cmake/ClangFormat.cmake -P cmake# CMakeLists.txt list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -
Submodule approach:
$ git submodule add https://github.com/zemasoft/clangformat-cmake# CMakeLists.txt list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/clangformat-cmake/cmake)
-
-
Include the module:
# CMakeLists.txt include(ClangFormat) -
Setup the module:
# CMakeLists.txt clangformat_setup( src/hello.hpp src/hello.cpp )or:
# CMakeLists.txt target_clangformat_setup(sometarget)
Usage
-
Generate the build system:
$ cmake -S . -Bbuild -
Format sources anytime using
clangformattarget:$ cmake --build build --target clangformator:
$ cd build $ make clangformat
Example
See an example here.