From cf4270c052dd5c59c336a78231319d57c7d2b24c Mon Sep 17 00:00:00 2001 From: Christoph Cullmann Date: Thu, 21 Jan 2021 21:55:10 +0000 Subject: ignore source files in CMAKE_BINARY_DIR for clang-format target --- kde-modules/KDEClangFormat.cmake | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/kde-modules/KDEClangFormat.cmake b/kde-modules/KDEClangFormat.cmake index 7f85508b..6cdbd2b5 100644 --- a/kde-modules/KDEClangFormat.cmake +++ b/kde-modules/KDEClangFormat.cmake @@ -45,18 +45,24 @@ function(KDE_CLANG_FORMAT) # run clang-format only if available, else signal the user what is missing if(KDE_CLANG_FORMAT_EXECUTABLE) + get_filename_component(_binary_dir ${CMAKE_BINARY_DIR} REALPATH) foreach(_file ${ARGV}) - add_custom_command(TARGET clang-format - COMMAND - ${KDE_CLANG_FORMAT_EXECUTABLE} - -style=file - -i - ${_file} - WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT - "Formatting ${_file}..." - ) + # check if the file is inside the build directory => ignore such files + get_filename_component(_full_file_path ${_file} REALPATH) + string(FIND ${_full_file_path} ${_binary_dir} _index) + if(NOT _index EQUAL 0) + add_custom_command(TARGET clang-format + COMMAND + ${KDE_CLANG_FORMAT_EXECUTABLE} + -style=file + -i + ${_full_file_path} + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT + "Formatting ${_full_file_path}..." + ) + endif() endforeach() else() add_custom_command(TARGET clang-format -- cgit v1.2.1