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()
|
|
|
|
|
|
|
|
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(V)
|
|
|
|
unset(CLANG_TIDY_NAMES)
|
|
|
|
|
|
|
|
function(myx_cmake_clang_tidy_analyze target)
|
|
|
|
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)
|
|
|
|
list(APPEND _args "--fix")
|
|
|
|
endif()
|
|
|
|
if(NOT TARGET myx-cmake-clang-tidy-analyze)
|
|
|
|
add_custom_target(myx-cmake-clang-tidy-analyze)
|
|
|
|
endif()
|
|
|
|
add_custom_target(${target}-clang-tidy-analyze WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
COMMAND ${CLANG_TIDY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources})
|
|
|
|
add_dependencies(${target}-clang-tidy-analyze ${target})
|
|
|
|
add_dependencies(myx-cmake-clang-tidy-analyze ${target}-clang-tidy-analyze)
|
|
|
|
else()
|
|
|
|
message(STATUS "MyxCMake: Clang Tidy analyzer is not found")
|
|
|
|
endif()
|
|
|
|
endfunction()
|