Skip to content

Commit

Permalink
Add clang-format to CMake (not working now)
Browse files Browse the repository at this point in the history
  • Loading branch information
HomesGH committed Sep 23, 2024
1 parent f402ab9 commit c26874c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cmake/modules/clangformat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Find clang-format
find_program(CLANG_FORMAT_BIN clang-format)

if (NOT CLANG_FORMAT_BIN)
message(FATAL_ERROR "clang-format not found!")
endif()

# List of file extensions to format
set(FORMAT_EXTENSIONS cpp h hpp c)

# Recursively find all files with the specified extensions
file(GLOB_RECURSE ALL_SOURCE_FILES
${PROJECT_SOURCE_DIR}/*.[ch]pp
${PROJECT_SOURCE_DIR}/*.[ch])

# Define clang-format target
add_custom_target(clang-format
COMMAND ${CLANG_FORMAT_BIN} -i ${ALL_SOURCE_FILES}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Running clang-format"
)

0 comments on commit c26874c

Please sign in to comment.