myx-cmake/MyxCMake/modules/MyxCMakeCodeAnalyzeClangCheck.cmake

35 lines
1.3 KiB
CMake

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_analyze_clang_check target)
if(CLANG_CHECK_EXE)
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$")
if(MYX_CMAKE_CLANG_ANALYZE_FIX)
list(APPEND _args "--fixit")
endif()
if(NOT TARGET myx-cmake-analyze-clang-check)
add_custom_target(myx-cmake-analyze-clang-check)
endif()
add_custom_target(${target}-analyze-clang-check WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLANG_CHECK_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources})
add_dependencies(${target}-analyze-clang-check ${target})
add_dependencies(myx-cmake-analyze-clang-check ${target}-analyze-clang-check)
else()
message(STATUS "MyxCMake: Clang Check analyzer is not found")
endif()
endfunction()