2022-05-06 09:49:46 +00:00
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
|
|
|
|
2021-12-08 11:32:04 +00:00
|
|
|
set(CLANG_TIDY_NAMES clang-tidy)
|
|
|
|
foreach(V RANGE 9 15)
|
|
|
|
list(INSERT CLANG_TIDY_NAMES 0 "clang-tidy-${V}")
|
|
|
|
endforeach()
|
2021-12-20 11:33:14 +00:00
|
|
|
unset(V)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
|
|
|
find_program(CLANG_TIDY_EXE NAMES ${CLANG_TIDY_NAMES})
|
|
|
|
if(CLANG_TIDY_EXE)
|
|
|
|
option(MYX_CMAKE_CLANG_TIDY_FIX "MyxCMake: perform fixes for Clang Tidy" OFF)
|
|
|
|
endif()
|
|
|
|
unset(CLANG_TIDY_NAMES)
|
|
|
|
|
2021-12-13 13:21:08 +00:00
|
|
|
function(myx_cmake_analyze_clang_tidy target)
|
2021-12-08 11:32:04 +00:00
|
|
|
if(CLANG_TIDY_EXE)
|
2021-12-12 16:44:29 +00:00
|
|
|
set(_args -extra-arg="-Wno-unknown-warning-option")
|
|
|
|
get_target_property(__sources ${target} SOURCES)
|
|
|
|
list(FILTER __sources EXCLUDE REGEX "qrc_.*\\.cpp$")
|
|
|
|
list(FILTER __sources EXCLUDE REGEX "moc_.*\\.cpp$")
|
|
|
|
list(FILTER __sources EXCLUDE REGEX "ui_.*\\.h$")
|
|
|
|
|
2021-12-08 11:32:04 +00:00
|
|
|
if(MYX_CMAKE_CLANG_TIDY_FIX)
|
2021-12-21 14:20:38 +00:00
|
|
|
list(APPEND _args "-fix-errors")
|
2021-12-08 11:32:04 +00:00
|
|
|
endif()
|
2021-12-13 13:21:08 +00:00
|
|
|
if(NOT TARGET myx-cmake-analyze-clang-tidy)
|
|
|
|
add_custom_target(myx-cmake-analyze-clang-tidy)
|
2021-12-08 11:32:04 +00:00
|
|
|
endif()
|
2022-01-25 17:49:02 +00:00
|
|
|
add_custom_target(${target}-analyze-clang-tidy
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
COMMAND ${CLANG_TIDY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources})
|
2021-12-13 13:21:08 +00:00
|
|
|
add_dependencies(${target}-analyze-clang-tidy ${target})
|
|
|
|
add_dependencies(myx-cmake-analyze-clang-tidy ${target}-analyze-clang-tidy)
|
2021-12-08 11:32:04 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "MyxCMake: Clang Tidy analyzer is not found")
|
|
|
|
endif()
|
|
|
|
endfunction()
|