myxx/MyxxCMake/lib/AnalyzeClazy.cmake

57 lines
1.8 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()
function(myxx_analyze_clazy target)
if(NOT CLAZY_EXE)
message(STATUS "MyxCMake: Clazy standalone analyzer is not found")
return()
endif()
if(TARGET ${target}-analyze-clazy)
message(STATUS "MyxxCMake: target ${target}-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,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast")
endif()
set(args -checks=${ARG_CHECKS}
-extra-arg=-Wno-unknown-warning-option
-export-fixes=clazy-fixes-file.yaml)
get_target_property(sources ${target} SOURCES)
foreach(iter ${sources})
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
if(pos EQUAL -1)
list(APPEND srcs ${iter})
endif()
endforeach()
if(NOT TARGET myxx-analyze-clazy)
add_custom_target(myxx-analyze-clazy)
endif()
if(ARG_FIX)
add_custom_target(${target}-analyze-clazy
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLAZY_EXE} ${args} -p ${CMAKE_BINARY_DIR} ${srcs}
COMMAND ${CLANG_APPLY_REPLACEMENTS_EXE} ${CMAKE_BINARY_DIR})
else()
add_custom_target(${target}-analyze-clazy
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CLAZY_EXE} ${args} -p ${CMAKE_BINARY_DIR} ${srcs})
endif()
add_dependencies(${target}-analyze-clazy ${target})
add_dependencies(myxx-analyze-clazy ${target}-analyze-clazy)
endfunction()