109 lines
5.4 KiB
CMake
109 lines
5.4 KiB
CMake
find_program(
|
|
CLANG_APPLY_REPLACEMENTS_EXE
|
|
NAMES
|
|
clang-apply-replacements-10
|
|
clang-apply-replacements-9
|
|
clang-apply-replacements)
|
|
|
|
find_program(CLAZY_EXE NAMES clazy-standalone)
|
|
|
|
if(CLAZY_EXE AND CLANG_APPLY_REPLACEMENTS_EXE)
|
|
option(CMLIB_CLAZY_FIX "Perform fixes for Clazy" OFF)
|
|
endif()
|
|
|
|
function(add_clazy_check target)
|
|
set(options)
|
|
set(oneValueArgs CHECKS)
|
|
set(multiValueArgs)
|
|
|
|
cmake_parse_arguments(_CLAZY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
set(_sources ${ARGN})
|
|
if(NOT _CLAZY_CHECKS)
|
|
set(_CLAZY_CHECKS "level2,container-inside-loop,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast")
|
|
endif()
|
|
set(_args -checks=${_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()
|
|
if(CMLIB_CLAZY_FIX)
|
|
add_custom_target(clazy-check-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
COMMAND ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources}
|
|
COMMAND ${CLANG_APPLY_REPLACEMENTS_EXE} ${CMAKE_BINARY_DIR})
|
|
else()
|
|
add_custom_target(clazy-check-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
COMMAND ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
|
endif()
|
|
add_dependencies(clazy-check-${target} ${target})
|
|
add_dependencies(clazy-check clazy-check-${target})
|
|
|
|
# option(CMLIB_CLAZY_FIX_QT_KEYWORDS "Fix Qt keywords" OFF)
|
|
# option(CMLIB_CLAZY_FIX_RANGE_LOOP_ADD_REF "Fix range loop add reference" OFF)
|
|
# option(CMLIB_CLAZY_FIX_RANGE_LOOP_ADD_QASCONST "Fix range loop add qAsConst" OFF)
|
|
# option(CMLIB_CLAZY_FIX_FUNCTION_ARGS_BY_REF "Fix function args by reference" OFF)
|
|
# option(CMLIB_CLAZY_FIX_OLD_STYLE_CONNECT "Fix old style connect" OFF)
|
|
# option(CMLIB_CLAZY_FIX_STRING_ALLOCATIONS "Fix string allocations" OFF)
|
|
#
|
|
# if(CMLIB_CLAZY_FIX_QT_KEYWORDS OR
|
|
# CMLIB_CLAZY_FIX_RANGE_LOOP_ADD_REF OR
|
|
# CMLIB_CLAZY_FIX_RANGE_LOOP_ADD_QASCONST OR
|
|
# CMLIB_CLAZY_FIX_FUNCTION_ARGS_BY_REF OR
|
|
# CMLIB_CLAZY_FIX_OLD_STYLE_CONNECT OR
|
|
# CMLIB_CLAZY_FIX_STRING_ALLOCATIONS)
|
|
# if(NOT TARGET clazy-fix)
|
|
# add_custom_target(clazy-fix)
|
|
# endif()
|
|
# if(CMLIB_CLAZY_FIX_QT_KEYWORDS)
|
|
# add_custom_target(clazy-fix-qt-keywords-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
# COMMAND ${CMAKE_COMMAND} -E env "CLAZY_FIXIT=fix-qt-keywords"
|
|
# ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
|
# add_dependencies(clazy-fix-qt-keywords-${target} ${target})
|
|
# add_dependencies(clazy-fix clazy-fix-qt-keywords-${target})
|
|
# endif()
|
|
# if(CMLIB_CLAZY_FIX_RANGE_LOOP_ADD_REF)
|
|
# add_custom_target(clazy-fix-range-loop-add-ref-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
# COMMAND ${CMAKE_COMMAND} -E env "CLAZY_FIXIT=fix-range-loop-add-ref"
|
|
# ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
|
# add_dependencies(clazy-fix-range-loop-add-ref-${target} ${target})
|
|
# add_dependencies(clazy-fix clazy-fix-range-loop-add-ref-${target})
|
|
# endif()
|
|
# if(CMLIB_CLAZY_FIX_RANGE_LOOP_ADD_QASCONST)
|
|
# add_custom_target(clazy-fix-range-loop-add-qasconst-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
# COMMAND ${CMAKE_COMMAND} -E env "CLAZY_FIXIT=fix-range-loop-add-qasconst"
|
|
# ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
|
# add_dependencies(clazy-fix-range-loop-add-qasconst-${target} ${target})
|
|
# add_dependencies(clazy-fix clazy-fix-range-loop-add-qasconst-${target})
|
|
# endif()
|
|
# if(CMLIB_CLAZY_FIX_FUNCTION_ARGS_BY_REF)
|
|
# add_custom_target(clazy-fix-function-args-by-ref-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
# COMMAND ${CMAKE_COMMAND} -E env "CLAZY_FIXIT=fix-function-args-by-ref"
|
|
# ${CLAZY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
|
|
# add_dependencies(clazy-fix-function-args-by-ref-${target} ${target})
|
|
# add_dependencies(clazy-fix clazy-fix-function-args-by-ref-${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()
|
|
# # "fix-qlatin1string-allocations", "qstring-allocations");
|
|
# # "fix-fromLatin1_fromUtf8-allocations", "qstring-allocations");
|
|
# # "fix-fromCharPtrAllocations", "qstring-allocations");
|
|
# 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()
|
|
endif()
|
|
else()
|
|
message(STATUS "CMLIB warning:")
|
|
message(STATUS " Clazy standalone analyzer is not found")
|
|
endif()
|
|
endfunction()
|