2020-12-01 10:12:24 +00:00
|
|
|
find_program(
|
|
|
|
CLANG_TIDY_EXE
|
|
|
|
NAMES
|
|
|
|
clang-tidy-13
|
|
|
|
clang-tidy-12
|
|
|
|
clang-tidy-11
|
|
|
|
clang-tidy-10
|
|
|
|
clang-tidy-9
|
|
|
|
clang-tidy)
|
2019-10-09 06:12:42 +00:00
|
|
|
if(CLANG_TIDY_EXE)
|
2020-04-18 15:57:42 +00:00
|
|
|
option(CMLIB_CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF)
|
2019-10-09 06:12:42 +00:00
|
|
|
endif()
|
|
|
|
|
2020-04-13 16:44:42 +00:00
|
|
|
function(add_clang_tidy_check target)
|
2019-06-15 11:55:12 +00:00
|
|
|
set(_sources ${ARGN})
|
2020-04-18 15:57:42 +00:00
|
|
|
set(_args -extra-arg="-Wno-unknown-warning-option")
|
2019-06-15 11:55:12 +00:00
|
|
|
|
|
|
|
if(CLANG_TIDY_EXE)
|
2020-04-18 15:57:42 +00:00
|
|
|
if(CMLIB_CLANG_TIDY_FIX)
|
2020-04-18 19:01:23 +00:00
|
|
|
list(APPEND _args "--fix")
|
2020-04-18 15:57:42 +00:00
|
|
|
endif()
|
2019-06-27 02:18:29 +00:00
|
|
|
if(NOT TARGET clang-tidy-check)
|
|
|
|
add_custom_target(clang-tidy-check)
|
|
|
|
endif()
|
2020-04-18 16:40:13 +00:00
|
|
|
add_custom_target(clang-tidy-check-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
COMMAND ${CLANG_TIDY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
2020-04-13 16:44:42 +00:00
|
|
|
add_dependencies(clang-tidy-check-${target} ${target})
|
|
|
|
add_dependencies(clang-tidy-check clang-tidy-check-${target})
|
2019-06-15 11:55:12 +00:00
|
|
|
else()
|
2019-08-10 07:30:01 +00:00
|
|
|
message(STATUS "CMLIB warning:")
|
|
|
|
message(STATUS " ClangTidy analyzer is not found")
|
2019-06-15 11:55:12 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|