PVS-Studio

This commit is contained in:
Andrei Astafev 2024-04-08 22:33:09 +03:00
parent 358a03401b
commit 3b9e0373b5

View File

@ -3,8 +3,7 @@
# 2020-2022 (c) PVS-Studio LLC
# Version 12
cmake_minimum_required(VERSION 3.0.0)
cmake_policy(SET CMP0051 NEW)
cmake_minimum_required(VERSION 3.6)
cmake_policy(SET CMP0054 NEW)
if (PVS_STUDIO_AS_SCRIPT)
@ -60,7 +59,7 @@ function (pvs_studio_log TEXT)
endfunction()
function (pvs_studio_relative_path VAR ROOT FILEPATH)
if (WIN32)
if (CMAKE_HOST_WIN32)
STRING(REGEX REPLACE "\\\\" "/" ROOT ${ROOT})
STRING(REGEX REPLACE "\\\\" "/" FILEPATH ${FILEPATH})
endif()
@ -105,6 +104,8 @@ macro (pvs_studio_append_standard_flag FLAGS STANDARD)
if ("${STANDARD}" MATCHES "^(99|11|14|17|20)$")
if ("${PVS_STUDIO_PREPROCESSOR}" MATCHES "gcc|clang")
list(APPEND "${FLAGS}" "-std=c++${STANDARD}")
elseif("${PVS_STUDIO_PREPROCESSOR}" MATCHES "visualcpp")
list(APPEND "${FLAGS}" "/std:c++${STANDARD}")
endif()
endif()
endmacro()
@ -184,7 +185,7 @@ function (pvs_studio_analyze_file SOURCE SOURCE_DIR BINARY_DIR)
pvs_studio_relative_path(SOURCE_RELATIVE "${SOURCE_DIR}" "${SOURCE}")
pvs_studio_join_path(SOURCE "${SOURCE_DIR}" "${SOURCE}")
set(LOG "${BINARY_DIR}/PVS-Studio/${SOURCE_RELATIVE}.plog")
set(LOG "${BINARY_DIR}/PVS-Studio/${TARGET}/${SOURCE_RELATIVE}.log")
get_filename_component(LOG "${LOG}" REALPATH)
get_filename_component(PARENT_DIR "${LOG}" DIRECTORY)
@ -343,7 +344,7 @@ function (pvs_studio_add_target)
set(PATHS)
if (WIN32)
if (CMAKE_HOST_WIN32)
# The registry value is only read when you do some cache operation on it.
# https://stackoverflow.com/questions/1762201/reading-registry-values-with-cmake
GET_FILENAME_COMPONENT(ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\ProgramVerificationSystems\\PVS-Studio;installDir]" ABSOLUTE CACHE)
@ -521,18 +522,38 @@ function (pvs_studio_add_target)
pvs_studio_relative_path(LOG_RELATIVE "${CMAKE_BINARY_DIR}" "${PVS_STUDIO_LOG}")
if (PVS_STUDIO_PLOGS OR PVS_STUDIO_COMPILE_COMMANDS)
if (WIN32)
if (CMAKE_HOST_WIN32)
string(REPLACE / \\ PVS_STUDIO_PLOGS "${PVS_STUDIO_PLOGS}")
endif()
if (WIN32)
set(COMMANDS COMMAND type ${PVS_STUDIO_PLOGS} ${PVS_STUDIO_PLOGS_LOGS} > "${PVS_STUDIO_LOG}" 2>nul || cd .)
if (CMAKE_GENERATOR MATCHES "NMake")
set(COMMAND_TYPE_FILE "${CMAKE_BINARY_DIR}/PVSConcatAllLogs.cmd")
# The number of files that will be merged in one call to the type command
set(STEP_SIZE 30)
set(BEGIN 0)
list(APPEND PVS_STUDIO_PLOGS ${PVS_STUDIO_PLOGS_LOGS})
list(LENGTH PVS_STUDIO_PLOGS END)
# Creating a bat file to call the 'type' command
file(WRITE ${COMMAND_TYPE_FILE} "@echo off\nbreak > ${PVS_STUDIO_LOG}\n")
while(BEGIN LESS END)
list(SUBLIST PVS_STUDIO_PLOGS ${BEGIN} ${STEP_SIZE} NEW_LIST)
file(APPEND ${COMMAND_TYPE_FILE} "type ${NEW_LIST} >> ${PVS_STUDIO_LOG} 2>nul || cd .\n")
math(EXPR BEGIN "${BEGIN} + ${STEP_SIZE}")
endwhile()
list(APPEND COMMANDS COMMAND call ${COMMAND_TYPE_FILE})
else()
set(COMMANDS COMMAND type ${PVS_STUDIO_PLOGS} ${PVS_STUDIO_PLOGS_LOGS} > "${PVS_STUDIO_LOG}" 2>nul || cd .)
endif()
else()
set(COMMANDS COMMAND cat ${PVS_STUDIO_PLOGS} ${PVS_STUDIO_PLOGS_LOGS} > "${PVS_STUDIO_LOG}" 2>/dev/null || true)
endif()
set(COMMENT "Generating ${LOG_RELATIVE}")
if (NOT "${PVS_STUDIO_FORMAT}" STREQUAL "" OR PVS_STUDIO_OUTPUT)
if ("${PVS_STUDIO_FORMAT}" STREQUAL "")
set(PVS_STUDIO_FORMAT "errorfile")
set(PVS_STUDIO_FORMAT "errorfile")
endif()
if (PVS_STUDIO_HIDE_HELP)
set(PVS_STUDIO_CONVERTER_ARGS ${PVS_STUDIO_CONVERTER_ARGS} --noHelpMessages)
@ -553,7 +574,7 @@ function (pvs_studio_add_target)
set(COMMENT "Generating ${LOG_RELATIVE}: no sources found")
endif()
if (WIN32)
if (CMAKE_HOST_WIN32)
string(REPLACE / \\ PVS_STUDIO_LOG "${PVS_STUDIO_LOG}")
endif()