krypty / Format.cmake

πŸ’… Stylize your code! Automatic clang-format and cmake-format targets for CMake.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Actions Status Actions Status

Format.cmake

clang-format and cmake-format for CMake

About

Format.cmake adds three additional targets to your CMake project.

  • format Shows which files are affected by clang-format
  • check-format Errors if files are affected by clang-format (for CI integration)
  • fix-format Applies clang-format to all affected files

To run the targets, invoke CMake with cmake --build <build directory> --target <target name>.

To disable using cmake_format to format CMake files, set the cmake option FORMAT_SKIP_CMAKE to a truthy value, e.g. by invoking CMake with -DFORMAT_SKIP_CMAKE=YES, or enabling the option when adding the dependency (recommended).

Demo

How to integrate

Using CPM.cmake (recommended)

Basic configuration

After adding CPM.cmake, add the following line to the project's CMakeLists.txt after calling project(...).

include(cmake/CPM.cmake)
CPMAddPackage("gh:TheLartians/Format.cmake@1.7.3")

Advanced configuration

This package supports optional parameters that you can specify in the CPM.cmake OPTIONS argument.

CPMAddPackage(
  NAME Format.cmake
  VERSION 1.7.3
  GITHUB_REPOSITORY TheLartians/Format.cmake
  OPTIONS 
      # set to yes skip cmake formatting
      "FORMAT_SKIP_CMAKE NO"
      # path to exclude (optional, supports regular expressions)
      "CMAKE_FORMAT_EXCLUDE cmake/CPM.cmake"
)

Using git submodules (not suited for libraries)

Run the following from the project's root directory.

git submodule add https://github.com/TheLartians/Format.cmake

In add the following lines to the project's CMakeLists.txt after calling project(...).

add_subdirectory(Format.cmake)

Dependencies

Format.cmake requires CMake, clang-format, python 2.7 or python 3, and cmake-format (optional).

About

πŸ’… Stylize your code! Automatic clang-format and cmake-format targets for CMake.

License:Apache License 2.0


Languages

Language:Python 78.1%Language:CMake 21.0%Language:C++ 0.9%