myxx/MyxxCMake/lib/AnalyzeClazy.cmake

63 lines
2.1 KiB
CMake
Raw Normal View History

2022-10-06 04:57:47 +00:00
include_guard(GLOBAL)
find_program(CLAZY_EXE NAMES clazy-standalone)
if(CLAZY_EXE AND CLANG_APPLY_REPLACEMENTS_EXE)
2022-10-06 23:22:43 +00:00
option(MYXX_CMAKE_CLAZY_FIX "MyxCMake: perform fixes for Clazy" OFF)
2022-10-06 04:57:47 +00:00
endif()
2022-10-09 18:15:35 +00:00
function(myxx_analyze_clazy TARGET_NAME)
myx_skip_external_target(${TARGET_NAME})
2022-10-06 04:57:47 +00:00
if(NOT CLAZY_EXE)
message(STATUS "MyxCMake: Clazy standalone analyzer is not found")
return()
endif()
2022-10-09 18:15:35 +00:00
if(TARGET ${TARGET_NAME}-analyze-clazy)
message(STATUS "MyxxCMake: target ${TARGET_NAME}-analyze-clazy already exists")
2022-10-06 04:57:47 +00:00
return()
endif()
set(options FIX)
set(oneValueArgs CHECKS)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_CHECKS)
2022-10-08 14:25:50 +00:00
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")
2022-10-06 04:57:47 +00:00
endif()
2022-10-09 18:15:35 +00:00
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})
2022-10-06 04:57:47 +00:00
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
if(pos EQUAL -1)
2022-10-09 18:15:35 +00:00
list(APPEND __filtered_sources ${iter})
2022-10-06 04:57:47 +00:00
endif()
endforeach()
if(NOT TARGET myxx-analyze-clazy)
add_custom_target(myxx-analyze-clazy)
endif()
if(ARG_FIX)
2022-10-09 18:15:35 +00:00
add_custom_target(${TARGET_NAME}-analyze-clazy
2022-10-06 04:57:47 +00:00
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
2022-10-09 18:15:35 +00:00
COMMAND ${CLAZY_EXE} ${__cmd_args} -p ${CMAKE_BINARY_DIR} ${__filtered_sources}
2022-10-06 04:57:47 +00:00
COMMAND ${CLANG_APPLY_REPLACEMENTS_EXE} ${CMAKE_BINARY_DIR})
else()
2022-10-09 18:15:35 +00:00
add_custom_target(${TARGET_NAME}-analyze-clazy
2022-10-06 04:57:47 +00:00
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
2022-10-09 18:15:35 +00:00
COMMAND ${CLAZY_EXE} ${__cmd_args} -p ${CMAKE_BINARY_DIR} ${__filtered_sources})
2022-10-06 04:57:47 +00:00
endif()
2022-10-09 18:15:35 +00:00
add_dependencies(${TARGET_NAME}-analyze-clazy ${TARGET_NAME})
add_dependencies(myxx-analyze-clazy ${TARGET_NAME}-analyze-clazy)
2022-10-06 04:57:47 +00:00
endfunction()