diff --git a/cmake/04-targets.cmake b/cmake/04-targets.cmake index d9142fa2..b1d6c3bb 100644 --- a/cmake/04-targets.cmake +++ b/cmake/04-targets.cmake @@ -25,12 +25,15 @@ add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/uninstall.cmake) # }}} + +# folders where the clang tools should operate +set(CLANG_SEARCH_PATHS ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/tests) + # Target: codeformat (clang-format) {{{ add_custom_target(codeformat) add_custom_command(TARGET codeformat - COMMAND ${PROJECT_SOURCE_DIR}/common/clang-format.sh - ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/include) + COMMAND ${PROJECT_SOURCE_DIR}/common/clang-format.sh ${CLANG_SEARCH_PATHS}) # }}} # Target: codecheck (clang-tidy) {{{ @@ -38,7 +41,7 @@ add_custom_command(TARGET codeformat add_custom_target(codecheck) add_custom_command(TARGET codecheck COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh - ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src) + ${PROJECT_BINARY_DIR} ${CLANG_SEARCH_PATHS}) # }}} # Target: codecheck-fix (clang-tidy + clang-format) {{{ @@ -46,7 +49,7 @@ add_custom_command(TARGET codecheck add_custom_target(codecheck-fix) add_custom_command(TARGET codecheck-fix COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh - ${PROJECT_BINARY_DIR} -fix ${PROJECT_SOURCE_DIR}/src) + ${PROJECT_BINARY_DIR} -fix ${CLANG_SEARCH_PATHS}) # }}} diff --git a/common/clang-format.sh b/common/clang-format.sh index a4edfed6..0a912c8e 100755 --- a/common/clang-format.sh +++ b/common/clang-format.sh @@ -2,16 +2,18 @@ main() { if [ $# -lt 1 ]; then - printf "%s DIR...\n" "$0" 1>&2 + echo "$0 DIR..." 1>&2 exit 1 fi + + # Search paths search="${*:-.}" - [ -d "$search" ] || search="$(dirname "$search")" + echo "$0 in $search" # shellcheck disable=2086 find $search -regex ".*.[c|h]pp" \ - -exec printf "\033[32;1m** \033[0mFormatting %s\n" {} \; \ + -exec printf "\\033[32;1m** \\033[0mFormatting %s\\n" {} \; \ -exec clang-format -style=file -i {} \; } diff --git a/common/clang-tidy.sh b/common/clang-tidy.sh index c6c2c791..f0de51fd 100755 --- a/common/clang-tidy.sh +++ b/common/clang-tidy.sh @@ -2,7 +2,7 @@ main() { if [ $# -lt 2 ]; then - echo "$0 [build_path] [-fix] DIR..." 1>&2 + echo "$0 build_path [-fix] DIR..." 1>&2 exit 1 fi @@ -12,12 +12,15 @@ main() { args="${args} -fix"; shift fi + # Search paths + search="${*:-.}" + + echo "$0 in $search" + # shellcheck disable=2086 - find "${@:-.}" -regex ".*.[c|h]pp" \ - -exec printf "\033[32;1m** \033[0mProcessing %s\n" {} \; \ - -exec clang-tidy $args {} \; \ - -exec printf "\033[32;1m** \033[0mFormatting %s\n" {} \; \ - -exec clang-format -style=file -i {} \; + find $search -iname "*.cpp" \ + -exec printf "\\033[32;1m** \\033[0mProcessing %s\\n" {} \; \ + -exec clang-tidy $args {} \; } main "$@"