diff options
| author | Christoph Cullmann <cullmann@kde.org> | 2021-01-21 21:55:10 +0000 | 
|---|---|---|
| committer | David Faure <faure@kde.org> | 2021-01-21 21:55:10 +0000 | 
| commit | cf4270c052dd5c59c336a78231319d57c7d2b24c (patch) | |
| tree | 757f0451d394a6087e87743f8c2a74ec48047969 | |
| parent | 717dc6eb24716d14cdfb304530045ef91228be19 (diff) | |
| download | extra-cmake-modules-cf4270c052dd5c59c336a78231319d57c7d2b24c.tar.gz extra-cmake-modules-cf4270c052dd5c59c336a78231319d57c7d2b24c.tar.bz2  | |
ignore source files in CMAKE_BINARY_DIR for clang-format target
| -rw-r--r-- | kde-modules/KDEClangFormat.cmake | 28 | 
1 files 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  | 
