myx-cmake/MyxCMake/modules/MyxCMakeCodeAnalyzeClangCheck.cmake

35 lines
1.3 KiB
CMake
Raw Normal View History

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()
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(V)
unset(CLANG_CHECK_NAMES)
function(myx_cmake_clang_check_analyze target)
if(CLANG_CHECK_EXE)
2021-12-12 16:44:29 +00:00
set(_args --analyze --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_ANALYZE_FIX)
list(APPEND _args "--fixit")
endif()
if(NOT TARGET myx-cmake-clang-check-analyze)
add_custom_target(myx-cmake-clang-check-analyze)
endif()
add_custom_target(${target}-clang-check-analyze WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLANG_CHECK_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources})
add_dependencies(${target}-clang-check-analyze ${target})
add_dependencies(myx-cmake-clang-check-analyze ${target}-clang-check-analyze)
else()
message(STATUS "MyxCMake: Clang Check analyzer is not found")
endif()
endfunction()