From 765360a0de2e5bd2f00c49c1c68e0958c3978e77 Mon Sep 17 00:00:00 2001 From: Christoph Cullmann Date: Sun, 17 Jan 2021 20:25:11 +0100 Subject: fix issues with too long command line length --- kde-modules/KDEClangFormat.cmake | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/kde-modules/KDEClangFormat.cmake b/kde-modules/KDEClangFormat.cmake index 057433c8..6d4ef0f4 100644 --- a/kde-modules/KDEClangFormat.cmake +++ b/kde-modules/KDEClangFormat.cmake @@ -40,24 +40,26 @@ endif() # formatting target function(KDE_CLANG_FORMAT) - # add target only if clang-format available + # add target without specific commands first, we add the real calls file-per-file to avoid command line length issues + add_custom_target(clang-format COMMENT "Formatting sources in ${CMAKE_CURRENT_SOURCE_DIR} with ${KDE_CLANG_FORMAT_EXECUTABLE}...") + + # run clang-format only if available, else signal the user what is missing if(KDE_CLANG_FORMAT_EXECUTABLE) - add_custom_target(clang-format - COMMAND - ${KDE_CLANG_FORMAT_EXECUTABLE} - -style=file - -i - ${ARGV} - WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT - "Formatting sources in ${CMAKE_CURRENT_SOURCE_DIR} with ${KDE_CLANG_FORMAT_EXECUTABLE}..." - ) + foreach(_file ${ARGV}) + add_custom_command(TARGET clang-format + COMMAND + ${KDE_CLANG_FORMAT_EXECUTABLE} + -style=file + -i + ${_file} + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR} + ) + endforeach() else() - add_custom_target(clang-format - COMMAND - ${CMAKE_COMMAND} -E echo - "Could not set up the clang-format target as the clang-format executable is missing." - ) + add_custom_command(TARGET clang-format + COMMAND + ${CMAKE_COMMAND} -E echo "Could not set up the clang-format target as the clang-format executable is missing." + ) endif() endfunction() -- cgit v1.2.1