Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom command line arguments to clang-tidy #10

Merged
merged 2 commits into from
Jul 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions ClangTidy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@
# This function must be called with one of the above options, or it must be able to
# find a custom script in the file system otherwise it will throw an error.
#
# The option EXTRA_ARGS may be used to pass command line options directly to the
# clang-tidy command. This can be useful or even required when a compiler other
# than clang is used to configure the project. clang-tidy will use the compile_commands.json
# database to work out how to analyse files, but some GNU options are not understood.
#
# swift_setup_clang_tidy(EXTRA_ARGS '-extra-arg=-Wno-unknown-warning-option')
#
# will disable a clang-tidy error when it encounters a compiler warning switch it
# doesn't support, such as -Wno-psabi (GNU does understand this one)
#
# All commands are run from ${CMAKE_CURRENT_SOURCE_DIR}. It is highly recommended
# that this module only be included from the top level CMakeLists.txt of a project,
# using it from a subdirectory may not work as expected.
Expand Down Expand Up @@ -163,7 +173,7 @@ endmacro()
function(swift_setup_clang_tidy)
set(argOption "REQUIRED")
set(argSingle "SCRIPT")
set(argMulti "CLANG_TIDY_NAMES" "TARGETS" "PATTERNS")
set(argMulti "CLANG_TIDY_NAMES" "TARGETS" "PATTERNS" "EXTRA_ARGS")

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

Expand Down Expand Up @@ -262,14 +272,15 @@ function(swift_setup_clang_tidy)
if(NOT srcs)
early_exit(WARNING "Couldn't find any source/header files to tidy in ${PROJECT_NAME}")
else()
message(WARNING "$$$$ ${x_EXTRA_ARGS}")
create_targets(
TOP_LEVEL ${top_level_project}
ALL_COMMAND
${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml
${${PROJECT_NAME}_CLANG_TIDY} ${x_EXTRA_ARGS} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml
`git ls-files ${srcs}`
DIFF_COMMAND
git diff --diff-filter=ACMRTUXB --quiet -- ${srcs} ||
${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml
${${PROJECT_NAME}_CLANG_TIDY} ${x_EXTRA_ARGS} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml
`git diff --diff-filter=ACMRTUXB --name-only master -- ${srcs}`
)
endif()
Expand Down