include_guard(GLOBAL) 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) if(CLAZY_EXE) set(options) 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() 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$") set(_args -checks=${ARG_CHECKS} -extra-arg=-Wno-unknown-warning-option -export-fixes=clazy-fixes-file.yaml) if(NOT TARGET myx-cmake-analyze-clazy) add_custom_target(myx-cmake-analyze-clazy) endif() if(MYX_CMAKE_CLAZY_FIX) add_custom_target(${target}-analyze-clazy WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources} 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} ${__sources}) endif() add_dependencies(${target}-analyze-clazy ${target}) add_dependencies(myx-cmake-analyze-clazy ${target}-analyze-clazy) else() message(STATUS "MyxCMake: Clazy standalone analyzer is not found") endif() endfunction()