myx-cmake/MyxCMake/modules/MyxCMakeCodeAnalyzeClazy.cmake

56 lines
2.1 KiB
CMake
Raw Normal View History

2021-12-08 11:32:04 +00:00
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_NAMES 0 "clang-apply-replacements-${V}")
2021-12-08 11:32:04 +00:00
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_analyze_clazy target)
2021-12-12 16:44:29 +00:00
if(CLAZY_EXE)
set(options)
set(oneValueArgs CHECKS)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
2021-12-08 11:32:04 +00:00
2021-12-12 16:44:29 +00:00
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()
2021-12-08 11:32:04 +00:00
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$")
set(_args -checks=${ARG_CHECKS} -extra-arg="-Wno-unknown-warning-option"
-export-fixes=clazy-fixes-file.yaml)
2021-12-08 11:32:04 +00:00
if(NOT TARGET myx-cmake-analyze-clazy)
add_custom_target(myx-cmake-analyze-clazy)
2021-12-08 11:32:04 +00:00
endif()
if(MYX_CMAKE_CLAZY_FIX)
add_custom_target(
${target}-analyze-clazy
2021-12-08 11:32:04 +00:00
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}-analyze-clazy WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
2021-12-08 11:32:04 +00:00
COMMAND ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources})
endif()
add_dependencies(${target}-analyze-clazy ${target})
add_dependencies(myx-cmake-analyze-clazy ${target}-analyze-clazy)
2021-12-08 11:32:04 +00:00
else()
message(STATUS "MyxCMake: Clazy standalone analyzer is not found")
endif()
endfunction()