myxx/MyxxCMake/lib/AnalyzeClazy.cmake
2022-10-19 16:59:18 +03:00

65 lines
2.2 KiB
CMake

include_guard(GLOBAL)
find_program(CLAZY_EXE NAMES clazy-standalone)
if(CLAZY_EXE AND CLANG_APPLY_REPLACEMENTS_EXE)
option(MYXX_CMAKE_CLAZY_FIX "MyxCMake: perform fixes for Clazy" OFF)
endif()
function(myxx_analyze_clazy TARGET_NAME)
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
return()
endif()
if(NOT CLAZY_EXE)
message(STATUS "MyxCMake: Clazy standalone analyzer is not found")
return()
endif()
if(TARGET ${TARGET_NAME}-analyze-clazy)
message(STATUS "MyxxCMake: target ${TARGET_NAME}-analyze-clazy already exists")
return()
endif()
set(options FIX)
set(oneValueArgs CHECKS)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_CHECKS)
set(ARG_CHECKS
"level2,container-inside-loop,detaching-member,heap-allocated-small-trivial-type,\
isempty-vs-count,qproperty-type-mismatch,qstring-varargs,qt6-deprecated-api-fixes,\
qt6-fwd-fixes,qt6-qlatin1stringchar-to-u,qt-keywords,signal-with-return-value,\
thread-with-slots,tr-non-literal,unneeded-cast,use-chrono-in-qtimer")
endif()
set(__cmd_args -checks=${ARG_CHECKS}
-extra-arg=-Wno-unknown-warning-option
-export-fixes=clazy-fixes-file.yaml)
get_target_property(__sources ${TARGET_NAME} SOURCES)
foreach(__iter ${__sources})
string(FIND ${__iter} ${CMAKE_BINARY_DIR} __pos)
if(__pos EQUAL -1)
list(APPEND __filtered_sources ${__iter})
endif()
endforeach()
if(NOT TARGET myxx-analyze-clazy)
add_custom_target(myxx-analyze-clazy)
endif()
if(ARG_FIX)
add_custom_target(${TARGET_NAME}-analyze-clazy
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLAZY_EXE} ${__cmd_args} -p ${CMAKE_BINARY_DIR} ${__filtered_sources}
COMMAND ${CLANG_APPLY_REPLACEMENTS_EXE} ${CMAKE_BINARY_DIR})
else()
add_custom_target(${TARGET_NAME}-analyze-clazy
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLAZY_EXE} ${__cmd_args} -p ${CMAKE_BINARY_DIR} ${__filtered_sources})
endif()
add_dependencies(${TARGET_NAME}-analyze-clazy ${TARGET_NAME})
add_dependencies(myxx-analyze-clazy ${TARGET_NAME}-analyze-clazy)
endfunction()