myx-cmake/MyxCMake/modules/MyxCMakeCodeAnalyzeClazy.cmake

56 lines
2.1 KiB
CMake

find_program(CLAZY_EXE NAMES clazy-standalone)
set(CLANG_APPLY_REPLACEMENTS_NAMES clang-apply-replacements)
foreach(V RANGE 9 15)
list(INSERT CLANG_APPLY_REPLACEMENTS 0 "clang-apply-replacements-${V}")
endforeach()
find_program(CLANG_APPLY_REPLACEMENTS_EXE NAMES ${CLANG_APPLY_REPLACEMENTS_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)
if(CLAZY_EXE AND CLANG_APPLY_REPLACEMENTS_EXE)
option(MYX_CMAKE_CLAZY_FIX "MyxCMake: perform fixes for Clazy" OFF)
endif()
function(myx_cmake_clazy_analyze target)
if(CLAZY_EXE)
set(options)
set(oneValueArgs CHECKS)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_CHECKS)
set(ARG_CHECKS "level2,container-inside-loop,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast")
endif()
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$")
set(_args -checks=${ARG_CHECKS} -extra-arg="-Wno-unknown-warning-option"
-export-fixes=clazy-fixes-file.yaml)
if(NOT TARGET myx-cmake-clazy-analyze)
add_custom_target(myx-cmake-clazy-analyze)
endif()
if(MYX_CMAKE_CLAZY_FIX)
add_custom_target(
${target}-clazy-analyze
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources}
COMMAND ${CLANG_APPLY_REPLACEMENTS_EXE} ${CMAKE_BINARY_DIR})
else()
add_custom_target(${target}-clazy-analyze WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources})
endif()
add_dependencies(${target}-clazy-analyze ${target})
add_dependencies(myx-cmake-clazy-analyze ${target}-clazy-analyze)
else()
message(STATUS "MyxCMake: Clazy standalone analyzer is not found")
endif()
endfunction()