46 lines
2.1 KiB
CMake
46 lines
2.1 KiB
CMake
function(add_clazy_check target)
|
|
find_program(CLAZY_EXE NAMES clazy-standalone)
|
|
set(_sources ${ARGN})
|
|
set(_clazy_checks
|
|
"container-inside-loop,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast"
|
|
)
|
|
set(_args -checks=level2,${_clazy_checks} -extra-arg="-Wno-unknown-warning-option" -export-fixes=clazy-fixes-file.yaml)
|
|
|
|
if(CLAZY_EXE)
|
|
if(NOT TARGET clazy-check)
|
|
add_custom_target(clazy-check)
|
|
endif()
|
|
add_custom_target(clazy-check-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
COMMAND ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
|
add_dependencies(clazy-check-${target} ${target})
|
|
add_dependencies(clazy-check clazy-check-${target})
|
|
|
|
option(CMLIB_CLAZY_FIX_STRING_ALLOCATIONS "Clazy allocations" OFF)
|
|
option(CMLIB_CLAZY_FIX_OLD_STYLE_CONNECT "Clazy old style connect" OFF)
|
|
|
|
if (CMLIB_CLAZY_FIX_STRING_ALLOCATIONS OR CMLIB_CLAZY_FIX_OLD_STYLE_CONNECT)
|
|
if(NOT TARGET clazy-fix)
|
|
add_custom_target(clazy-fix)
|
|
endif()
|
|
if(CMLIB_CLAZY_FIX_STRING_ALLOCATIONS)
|
|
add_custom_target(clazy-fix-string-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
COMMAND ${CMAKE_COMMAND} -E env "CLAZY_FIXIT=fix-qlatin1string-allocations"
|
|
${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
|
add_dependencies(clazy-fix-string-${target} ${target})
|
|
add_dependencies(clazy-fix clazy-fix-string-${target})
|
|
endif()
|
|
if(CMLIB_CLAZY_FIX_OLD_STYLE_CONNECT)
|
|
add_custom_target(clazy-fix-old-style-connect-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
COMMAND ${CMAKE_COMMAND} -E env "CLAZY_FIXIT=fix-old-style-connect"
|
|
${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
|
add_dependencies(clazy-fix-old-style-connect-${target} ${target})
|
|
add_dependencies(clazy-fix clazy-fix-old-style-connect-${target})
|
|
endif()
|
|
endif()
|
|
|
|
else()
|
|
message(STATUS "CMLIB warning:")
|
|
message(STATUS " Clazy standalone analyzer is not found")
|
|
endif()
|
|
endfunction()
|