Skip to content

Commit

Permalink
clang-format call pass all files instead of a file which list the files
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET committed Mar 27, 2024
1 parent 74337bb commit 63fbae5
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions cmake/clang-format.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
find_program(CLANG_FORMAT clang-format)

if(NOT CLANG_FORMAT)
message(WARNING "clang-format not found")
message(WARNING "clang-format not found")
return()
endif()

# list all files to format

set(
FORMAT_PATTERNS
include/*.hpp
Expand All @@ -22,23 +21,16 @@ foreach(PATTERN ${FORMAT_PATTERNS})
list(APPEND ALL_FILES_TO_FORMAT ${FILES_TO_FORMAT})
endforeach()

string(REPLACE ";" "\n" FILES_TO_FORMAT "${ALL_FILES_TO_FORMAT}")

# generate a txt file with one file path per line
message(STATUS "Generating clang-format input file list")
set(CLANG_FORMAT_INPUT_FILES ${CMAKE_BINARY_DIR}/clang-format_input_files.txt)
file(WRITE ${CLANG_FORMAT_INPUT_FILES} ${FILES_TO_FORMAT})

add_custom_target(
clang-format
COMMAND ${CLANG_FORMAT} -i -style=file --files=${CLANG_FORMAT_INPUT_FILES}
COMMAND ${CLANG_FORMAT} -i -style=file ${ALL_FILES_TO_FORMAT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running clang-format on all files"
)

add_custom_target(
clang-format_dry_run
COMMAND ${CLANG_FORMAT} --dry-run -i -style=file --files=${CLANG_FORMAT_INPUT_FILES}
COMMAND ${CLANG_FORMAT} --dry-run -style=file ${ALL_FILES_TO_FORMAT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running dry clang-format on all files"
)

0 comments on commit 63fbae5

Please sign in to comment.