2021-12-08 11:32:04 +00:00
|
|
|
set(CLANG_CHECK_NAMES clang-check)
|
|
|
|
foreach(V RANGE 9 15)
|
|
|
|
list(INSERT CLANG_CHECK_NAMES 0 "clang-check-${V}")
|
|
|
|
endforeach()
|
2021-12-20 11:33:14 +00:00
|
|
|
unset(V)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
|
|
|
find_program(CLANG_CHECK_EXE NAMES ${CLANG_CHECK_NAMES})
|
|
|
|
if(CLANG_CHECK_EXE)
|
|
|
|
option(MYX_CMAKE_CLANG_CHECK_FIX "MyxCMake: perform fixes for Clang Check" OFF)
|
|
|
|
endif()
|
|
|
|
unset(CLANG_CHECK_NAMES)
|
|
|
|
|
2021-12-13 13:21:08 +00:00
|
|
|
function(myx_cmake_analyze_clang_check target)
|
2021-12-08 11:32:04 +00:00
|
|
|
if(CLANG_CHECK_EXE)
|
2022-01-25 17:49:02 +00:00
|
|
|
set(_args --analyze --extra-arg=-Wno-unknown-warning-option)
|
2021-12-12 16:44:29 +00:00
|
|
|
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-20 11:33:14 +00:00
|
|
|
if(MYX_CMAKE_CLANG_CHECK_FIX)
|
2021-12-08 11:32:04 +00:00
|
|
|
list(APPEND _args "--fixit")
|
|
|
|
endif()
|
2021-12-13 13:21:08 +00:00
|
|
|
if(NOT TARGET myx-cmake-analyze-clang-check)
|
|
|
|
add_custom_target(myx-cmake-analyze-clang-check)
|
2021-12-08 11:32:04 +00:00
|
|
|
endif()
|
2022-01-25 17:49:02 +00:00
|
|
|
add_custom_target(${target}-analyze-clang-check
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
COMMAND ${CLANG_CHECK_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources})
|
2021-12-13 13:21:08 +00:00
|
|
|
add_dependencies(${target}-analyze-clang-check ${target})
|
|
|
|
add_dependencies(myx-cmake-analyze-clang-check ${target}-analyze-clang-check)
|
2021-12-08 11:32:04 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "MyxCMake: Clang Check analyzer is not found")
|
|
|
|
endif()
|
|
|
|
endfunction()
|