Проверка PVS Studio

This commit is contained in:
Andrei Astafev 2021-12-12 17:49:46 +03:00
parent 9f6551c259
commit 475afb8070

View File

@ -1,51 +1,31 @@
if(CMAKE_EXPORT_COMPILE_COMMANDS) if(CMAKE_EXPORT_COMPILE_COMMANDS)
find_program(PVS_STUDIO_ANALYZER_EXE NAMES pvs-studio-analyzer)
include(PVS-Studio) include(PVS-Studio)
else() else()
message(STATUS "MyxCMake: CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.") message(STATUS "MyxCMake: CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.")
endif() endif()
function(myx_cmake_pvs_studio_analyze target) function(myx_cmake_pvs_studio_analyze target)
if(PVS_STUDIO_ANALYZER_EXE) set(options)
if(NOT TARGET myx-cmake-pvs-studio-analyze) set(oneValueArgs CHECKS)
add_custom_target(myx-cmake-pvs-studio-analyze) set(multiValueArgs)
endif() if(NOT TARGET myx-cmake-pvs-studio-analyze)
set(PVS_STUDIO_HEADER "${CMAKE_BINARY_DIR}/include/myx_cmake_pvs_studio_header.hpp")
set(PVS_STUDIO_CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${target}.cfg")
set(PVS_STUDIO_CONFIG_COMMAND "${CMAKE_COMMAND}" -E echo "sourcetree-root=${CMAKE_SOURCE_DIR}" > "${PVS_STUDIO_CONFIG}")
add_custom_command(OUTPUT "${PVS_STUDIO_CONFIG}"
COMMAND ${PVS_STUDIO_CONFIG_COMMAND}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Generating PVS-Studio.cfg")
set(PVS_STUDIO_HEADER "${CMAKE_BINARY_DIR}/include/pvs_studio_suppression_${target}.hpp")
file(WRITE ${PVS_STUDIO_HEADER} file(WRITE ${PVS_STUDIO_HEADER}
"#ifndef PVS_STUDIO_HPP_\n" "#ifndef MYX_CMAKE_PVS_STUDIO_HEADER_HPP_\n"
"#define PVS_STUDIO_HPP_\n" "#define MYX_CMAKE_PVS_STUDIO_HEADER_HPP_\n"
"#pragma once\n" "#pragma once\n"
"//-V813_MINSIZE=33\n" "//-V813_MINSIZE=33\n"
"#endif // PVS_STUDIO_HPP_\n" "#endif // MYX_CMAKE_PVS_STUDIO_HEADER_HPP_\n")
)
get_target_property(__sources ${target} SOURCES) pvs_studio_add_target(TARGET myx-cmake-pvs-studio-analyze
list(FILTER __sources EXCLUDE REGEX "qrc_.*\\.cpp$")
list(FILTER __sources EXCLUDE REGEX "moc_.*\\.cpp$")
list(FILTER __sources EXCLUDE REGEX "ui_.*\\.h$")
pvs_studio_add_target(
TARGET ${target}-pvs-studio-analyze
CONFIG ${PVS_STUDIO_CONFIG} CONFIG ${PVS_STUDIO_CONFIG}
DEPENDS ${PVS_STUDIO_CONFIG} DEPENDS ${PVS_STUDIO_CONFIG}
LOG "${CMAKE_BINARY_DIR}/PVS-Studio-${target}.log" COMPILE_COMMANDS
SOURCES ${__sources} HIDE_HELP
COMPILE_COMMANDS HIDE_HELP
OUTPUT FORMAT errorfile OUTPUT FORMAT errorfile
ARGS --exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${target}_autogen ARGS --exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${target}_autogen
MODE GA:1,2,3;64:1;OP:1,2;CS:1,2) MODE GA:1,2,3;64:1;OP:1,2;CS:1,2)
add_dependencies(myx-cmake-pvs-studio-analyze ${target}-pvs-studio-analyze)
get_target_property(__target_type ${target} TYPE) get_target_property(__target_type ${target} TYPE)
if(${__target_type} STREQUAL INTERFACE_LIBRARY) if(${__target_type} STREQUAL INTERFACE_LIBRARY)
set(__target_type INTERFACE) set(__target_type INTERFACE)
@ -57,7 +37,11 @@ function(myx_cmake_pvs_studio_analyze target)
else() # GCC/Clang else() # GCC/Clang
target_compile_options(${target} BEFORE ${__target_type} -include ${PVS_STUDIO_HEADER}) target_compile_options(${target} BEFORE ${__target_type} -include ${PVS_STUDIO_HEADER})
endif() endif()
else() endif()
message(STATUS "MyxCMake: PVS-Studio analyzer is not found")
if(EXISTS PVS_STUDIO_BIN_PATH AND EXISTS PVS_STUDIO_CONVERTER_PATH AND TARGET myx-cmake-pvs-studio-analyze)
add_dependencies(myx-cmake-pvs-studio-analyze ${target})
get_target_property(__target_source_dir "${target}" SOURCE_DIR)
pvs_studio_analyze_target("${target}" "${__target_source_dir}")
endif() endif()
endfunction() endfunction()