myx-cmake/MyxCMake/modules/MyxCMakeCodeAnalyzeClazy.cmake

45 lines
1.7 KiB
CMake
Raw Normal View History

2021-12-08 11:32:04 +00:00
find_program(CLAZY_EXE NAMES clazy-standalone)
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$")
2022-01-25 17:49:02 +00:00
set(_args -checks=${ARG_CHECKS}
-extra-arg=-Wno-unknown-warning-option
2021-12-12 16:44:29 +00:00
-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)
2022-01-25 17:49:02 +00:00
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()
2022-01-25 17:49:02 +00:00
add_custom_target(${target}-analyze-clazy
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources})
2021-12-08 11:32:04 +00:00
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()