35 lines
1.2 KiB
CMake
35 lines
1.2 KiB
CMake
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)
|
|
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$")
|
|
|
|
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()
|