Обновление PVS

This commit is contained in:
Andrei Astafev 2021-11-28 12:31:54 +03:00
parent a2ae14a6e8
commit e11dd38dd0

View File

@ -33,8 +33,9 @@ if (PVS_STUDIO_AS_SCRIPT)
endforeach () endforeach ()
execute_process(COMMAND ${PVS_STUDIO_COMMAND} ${additional_args} execute_process(COMMAND ${PVS_STUDIO_COMMAND} ${additional_args}
ERROR_VARIABLE error RESULT_VARIABLE result
RESULT_VARIABLE result) OUTPUT_VARIABLE output
ERROR_VARIABLE error)
set(stderr_type "") set(stderr_type "")
@ -42,7 +43,7 @@ if (PVS_STUDIO_AS_SCRIPT)
set(stderr_type FATAL_ERROR) set(stderr_type FATAL_ERROR)
endif () endif ()
if (result OR error) if (NOT error STREQUAL "" OR (result AND NOT output STREQUAL "No compilation units were found.\n"))
message(${stderr_type} "${error}") message(${stderr_type} "${error}")
endif () endif ()
@ -126,6 +127,11 @@ function (pvs_studio_set_target_flags TARGET CXX C)
set(CXX_FLAGS "${${CXX}}") set(CXX_FLAGS "${${CXX}}")
set(C_FLAGS "${${C}}") set(C_FLAGS "${${C}}")
if (NOT MSVC)
list(APPEND CXX_FLAGS "$<$<BOOL:${CMAKE_SYSROOT}>:--sysroot=${CMAKE_SYSROOT}>")
list(APPEND C_FLAGS "$<$<BOOL:${CMAKE_SYSROOT}>:--sysroot=${CMAKE_SYSROOT}>")
endif ()
set(prop_incdirs "$<TARGET_PROPERTY:${TARGET},INCLUDE_DIRECTORIES>") set(prop_incdirs "$<TARGET_PROPERTY:${TARGET},INCLUDE_DIRECTORIES>")
list(APPEND CXX_FLAGS "$<$<BOOL:${prop_incdirs}>:-I$<JOIN:${prop_incdirs},$<SEMICOLON>-I>>") list(APPEND CXX_FLAGS "$<$<BOOL:${prop_incdirs}>:-I$<JOIN:${prop_incdirs},$<SEMICOLON>-I>>")
list(APPEND C_FLAGS "$<$<BOOL:${prop_incdirs}>:-I$<JOIN:${prop_incdirs},$<SEMICOLON>-I>>") list(APPEND C_FLAGS "$<$<BOOL:${prop_incdirs}>:-I$<JOIN:${prop_incdirs},$<SEMICOLON>-I>>")
@ -134,6 +140,10 @@ function (pvs_studio_set_target_flags TARGET CXX C)
list(APPEND CXX_FLAGS "$<$<BOOL:${prop_compdefs}>:-D$<JOIN:${prop_compdefs},$<SEMICOLON>-D>>") list(APPEND CXX_FLAGS "$<$<BOOL:${prop_compdefs}>:-D$<JOIN:${prop_compdefs},$<SEMICOLON>-D>>")
list(APPEND C_FLAGS "$<$<BOOL:${prop_compdefs}>:-D$<JOIN:${prop_compdefs},$<SEMICOLON>-D>>") list(APPEND C_FLAGS "$<$<BOOL:${prop_compdefs}>:-D$<JOIN:${prop_compdefs},$<SEMICOLON>-D>>")
set(prop_compopt "$<TARGET_PROPERTY:${TARGET},COMPILE_OPTIONS>")
list(APPEND CXX_FLAGS "$<$<BOOL:${prop_compopt}>:$<JOIN:${prop_compopt},$<SEMICOLON>>>")
list(APPEND C_FLAGS "$<$<BOOL:${prop_compopt}>:$<JOIN:${prop_compopt},$<SEMICOLON>>>")
set("${CXX}" "${CXX_FLAGS}" PARENT_SCOPE) set("${CXX}" "${CXX_FLAGS}" PARENT_SCOPE)
set("${C}" "${C_FLAGS}" PARENT_SCOPE) set("${C}" "${C_FLAGS}" PARENT_SCOPE)
endfunction () endfunction ()
@ -211,7 +221,7 @@ function (pvs_studio_analyze_file SOURCE SOURCE_DIR BINARY_DIR)
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${LOG}" COMMAND "${CMAKE_COMMAND}" -E remove_directory "${LOG}"
COMMAND ${pvscmd} COMMAND ${pvscmd}
WORKING_DIRECTORY "${BINARY_DIR}" WORKING_DIRECTORY "${BINARY_DIR}"
DEPENDS "${SOURCE}" "${PVS_STUDIO_CONFIG}" "${PVS_STUDIO_SUPPRESS_BASE}" DEPENDS "${SOURCE}" "${PVS_STUDIO_SUPPRESS_BASE}" "${PVS_STUDIO_DEPENDS}"
IMPLICIT_DEPENDS "${PVS_STUDIO_LANGUAGE}" "${SOURCE}" IMPLICIT_DEPENDS "${PVS_STUDIO_LANGUAGE}" "${SOURCE}"
${depCommandArg} ${depCommandArg}
VERBATIM VERBATIM
@ -303,6 +313,7 @@ option(PVS_STUDIO_DEBUG OFF "Add debug info")
# C_FLAGS flags... additional C_FLAGS # C_FLAGS flags... additional C_FLAGS
# CXX_FLAGS flags... additional CXX_FLAGS # CXX_FLAGS flags... additional CXX_FLAGS
# ARGS args... additional pvs-studio-analyzer/CompilerCommandsAnalyzer.exe flags # ARGS args... additional pvs-studio-analyzer/CompilerCommandsAnalyzer.exe flags
# CONVERTER_ARGS args... additional plog-converter/HtmlGenerator.exe flags
function (pvs_studio_add_target) function (pvs_studio_add_target)
macro (default VAR VALUE) macro (default VAR VALUE)
if ("${${VAR}}" STREQUAL "") if ("${${VAR}}" STREQUAL "")
@ -319,19 +330,12 @@ function (pvs_studio_add_target)
set(DEFAULT_PREPROCESSOR "gcc") set(DEFAULT_PREPROCESSOR "gcc")
endif () endif ()
set(OPTIONAL OUTPUT ALL RECURSIVE HIDE_HELP KEEP_COMBINED_PLOG COMPILE_COMMANDS) set(OPTIONAL OUTPUT ALL RECURSIVE HIDE_HELP KEEP_COMBINED_PLOG COMPILE_COMMANDS KEEP_INTERMEDIATE_FILES)
set(SINGLE LICENSE CONFIG TARGET LOG FORMAT BIN CONVERTER PLATFORM PREPROCESSOR CFG_TEXT SUPPRESS_BASE) set(SINGLE LICENSE CONFIG TARGET LOG FORMAT BIN CONVERTER PLATFORM PREPROCESSOR CFG_TEXT SUPPRESS_BASE)
set(MULTI SOURCES C_FLAGS CXX_FLAGS ARGS DEPENDS ANALYZE MODE) set(MULTI SOURCES C_FLAGS CXX_FLAGS ARGS DEPENDS ANALYZE MODE CONVERTER_ARGS)
cmake_parse_arguments(PVS_STUDIO "${OPTIONAL}" "${SINGLE}" "${MULTI}" ${ARGN}) cmake_parse_arguments(PVS_STUDIO "${OPTIONAL}" "${SINGLE}" "${MULTI}" ${ARGN})
if ("${PVS_STUDIO_CONFIG}" STREQUAL "" OR NOT "${PVS_STUDIO_CFG_TEXT}" STREQUAL "")
set(PVS_STUDIO_EMPTY_CONFIG ON)
else ()
set(PVS_STUDIO_EMPTY_CONFIG OFF)
endif ()
default(PVS_STUDIO_CFG_TEXT "analysis-mode=31")
default(PVS_STUDIO_CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio.cfg")
default(PVS_STUDIO_C_FLAGS "") default(PVS_STUDIO_C_FLAGS "")
default(PVS_STUDIO_CXX_FLAGS "") default(PVS_STUDIO_CXX_FLAGS "")
default(PVS_STUDIO_TARGET "pvs") default(PVS_STUDIO_TARGET "pvs")
@ -378,17 +382,18 @@ function (pvs_studio_add_target)
string(REPLACE ";" "+" PVS_STUDIO_MODE "${PVS_STUDIO_MODE}") string(REPLACE ";" "+" PVS_STUDIO_MODE "${PVS_STUDIO_MODE}")
if (PVS_STUDIO_EMPTY_CONFIG) if ("${PVS_STUDIO_CONFIG}" STREQUAL "" AND NOT "${PVS_STUDIO_CFG_TEXT}" STREQUAL "")
set(PVS_STUDIO_CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio.cfg")
set(PVS_STUDIO_CONFIG_COMMAND "${CMAKE_COMMAND}" -E echo "${PVS_STUDIO_CFG_TEXT}" > "${PVS_STUDIO_CONFIG}") set(PVS_STUDIO_CONFIG_COMMAND "${CMAKE_COMMAND}" -E echo "${PVS_STUDIO_CFG_TEXT}" > "${PVS_STUDIO_CONFIG}")
else ()
set(PVS_STUDIO_CONFIG_COMMAND "${CMAKE_COMMAND}" -E touch "${PVS_STUDIO_CONFIG}") add_custom_command(OUTPUT "${PVS_STUDIO_CONFIG}"
COMMAND ${PVS_STUDIO_CONFIG_COMMAND}
WORKING_DIRECTORY "${BINARY_DIR}"
COMMENT "Generating PVS-Studio.cfg")
list(APPEND PVS_STUDIO_DEPENDS "${PVS_STUDIO_CONFIG}")
endif () endif ()
add_custom_command(OUTPUT "${PVS_STUDIO_CONFIG}"
COMMAND ${PVS_STUDIO_CONFIG_COMMAND}
WORKING_DIRECTORY "${BINARY_DIR}"
COMMENT "Generating PVS-Studio.cfg")
if (NOT "${PVS_STUDIO_PREPROCESSOR}" MATCHES "^${PVS_STUDIO_SUPPORTED_PREPROCESSORS}$") if (NOT "${PVS_STUDIO_PREPROCESSOR}" MATCHES "^${PVS_STUDIO_SUPPORTED_PREPROCESSORS}$")
message(FATAL_ERROR "Preprocessor ${PVS_STUDIO_PREPROCESSOR} isn't supported. Available options: ${PVS_STUDIO_SUPPORTED_PREPROCESSORS}.") message(FATAL_ERROR "Preprocessor ${PVS_STUDIO_PREPROCESSOR} isn't supported. Available options: ${PVS_STUDIO_SUPPORTED_PREPROCESSORS}.")
endif () endif ()
@ -397,12 +402,14 @@ function (pvs_studio_add_target)
pvs_studio_set_directory_flags("${CMAKE_CURRENT_SOURCE_DIR}" PVS_STUDIO_CXX_FLAGS PVS_STUDIO_C_FLAGS) pvs_studio_set_directory_flags("${CMAKE_CURRENT_SOURCE_DIR}" PVS_STUDIO_CXX_FLAGS PVS_STUDIO_C_FLAGS)
if (NOT "${PVS_STUDIO_LICENSE}" STREQUAL "") if (NOT "${PVS_STUDIO_LICENSE}" STREQUAL "")
pvs_studio_join_path(PVS_STUDIO_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}" "${PVS_STUDIO_LICENSE}")
list(APPEND PVS_STUDIO_ARGS --lic-file "${PVS_STUDIO_LICENSE}") list(APPEND PVS_STUDIO_ARGS --lic-file "${PVS_STUDIO_LICENSE}")
endif () endif ()
list(APPEND PVS_STUDIO_ARGS --cfg "${PVS_STUDIO_CONFIG}" if (NOT ${PVS_STUDIO_CONFIG} STREQUAL "")
--platform "${PVS_STUDIO_PLATFORM}" list(APPEND PVS_STUDIO_ARGS --cfg "${PVS_STUDIO_CONFIG}")
endif ()
list(APPEND PVS_STUDIO_ARGS --platform "${PVS_STUDIO_PLATFORM}"
--preprocessor "${PVS_STUDIO_PREPROCESSOR}") --preprocessor "${PVS_STUDIO_PREPROCESSOR}")
if (NOT "${PVS_STUDIO_SUPPRESS_BASE}" STREQUAL "") if (NOT "${PVS_STUDIO_SUPPRESS_BASE}" STREQUAL "")
@ -418,6 +425,15 @@ function (pvs_studio_add_target)
list(APPEND PVS_STUDIO_ARGS --cc "${CMAKE_C_COMPILER}") list(APPEND PVS_STUDIO_ARGS --cc "${CMAKE_C_COMPILER}")
endif () endif ()
if (PVS_STUDIO_KEEP_INTERMEDIATE_FILES)
list(APPEND PVS_STUDIO_ARGS --dump-files)
endif()
string(REGEX REPLACE [123,:] "" ANALYZER_MODE ${PVS_STUDIO_MODE})
if (NOT "$ANALYZER_MODE" STREQUAL "GA")
list (APPEND PVS_STUDIO_ARGS -a "${ANALYZER_MODE}")
endif ()
set(PVS_STUDIO_PLOGS "") set(PVS_STUDIO_PLOGS "")
set(PVS_STUDIO_RECURSIVE_TARGETS_NEW) set(PVS_STUDIO_RECURSIVE_TARGETS_NEW)
@ -482,7 +498,7 @@ function (pvs_studio_add_target)
${PVS_STUDIO_ARGS} ${PVS_STUDIO_ARGS}
COMMENT "Analyzing with PVS-Studio" COMMENT "Analyzing with PVS-Studio"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
DEPENDS "${PVS_STUDIO_CONFIG}" "${PVS_STUDIO_SUPPRESS_BASE}" DEPENDS "${PVS_STUDIO_SUPPRESS_BASE}" "${PVS_STUDIO_DEPENDS}"
) )
list(APPEND PVS_STUDIO_PLOGS_LOGS "${COMPILE_COMMANDS_LOG}.always") list(APPEND PVS_STUDIO_PLOGS_LOGS "${COMPILE_COMMANDS_LOG}.always")
list(APPEND PVS_STUDIO_PLOGS_DEPENDENCIES "${COMPILE_COMMANDS_LOG}") list(APPEND PVS_STUDIO_PLOGS_DEPENDENCIES "${COMPILE_COMMANDS_LOG}")
@ -494,9 +510,9 @@ function (pvs_studio_add_target)
string(REPLACE / \\ PVS_STUDIO_PLOGS "${PVS_STUDIO_PLOGS}") string(REPLACE / \\ PVS_STUDIO_PLOGS "${PVS_STUDIO_PLOGS}")
endif () endif ()
if (WIN32) if (WIN32)
set(COMMANDS COMMAND type ${PVS_STUDIO_PLOGS} ${PVS_STUDIO_PLOGS_LOGS} > "${PVS_STUDIO_LOG}" 2>nul) set(COMMANDS COMMAND type ${PVS_STUDIO_PLOGS} ${PVS_STUDIO_PLOGS_LOGS} > "${PVS_STUDIO_LOG}" 2>nul || cd .)
else () else ()
set(COMMANDS COMMAND cat ${PVS_STUDIO_PLOGS} ${PVS_STUDIO_PLOGS_LOGS} > "${PVS_STUDIO_LOG}") set(COMMANDS COMMAND cat ${PVS_STUDIO_PLOGS} ${PVS_STUDIO_PLOGS_LOGS} > "${PVS_STUDIO_LOG}" 2>/dev/null || true)
endif () endif ()
set(COMMENT "Generating ${LOG_RELATIVE}") set(COMMENT "Generating ${LOG_RELATIVE}")
if (NOT "${PVS_STUDIO_FORMAT}" STREQUAL "" OR PVS_STUDIO_OUTPUT) if (NOT "${PVS_STUDIO_FORMAT}" STREQUAL "" OR PVS_STUDIO_OUTPUT)
@ -506,7 +522,7 @@ function (pvs_studio_add_target)
list(APPEND COMMANDS list(APPEND COMMANDS
COMMAND "${CMAKE_COMMAND}" -E remove -f "${PVS_STUDIO_LOG}.pvs.raw" COMMAND "${CMAKE_COMMAND}" -E remove -f "${PVS_STUDIO_LOG}.pvs.raw"
COMMAND "${CMAKE_COMMAND}" -E rename "${PVS_STUDIO_LOG}" "${PVS_STUDIO_LOG}.pvs.raw" COMMAND "${CMAKE_COMMAND}" -E rename "${PVS_STUDIO_LOG}" "${PVS_STUDIO_LOG}.pvs.raw"
COMMAND "${PVS_STUDIO_CONVERTER}" -t "${PVS_STUDIO_FORMAT}" "${PVS_STUDIO_LOG}.pvs.raw" -o "${PVS_STUDIO_LOG}" -a "${PVS_STUDIO_MODE}" COMMAND "${PVS_STUDIO_CONVERTER}" "${PVS_STUDIO_CONVERTER_ARGS}" -t "${PVS_STUDIO_FORMAT}" "${PVS_STUDIO_LOG}.pvs.raw" -o "${PVS_STUDIO_LOG}" -a "${PVS_STUDIO_MODE}"
) )
if(NOT PVS_STUDIO_KEEP_COMBINED_PLOG) if(NOT PVS_STUDIO_KEEP_COMBINED_PLOG)
list(APPEND COMMANDS COMMAND "${CMAKE_COMMAND}" -E remove -f "${PVS_STUDIO_LOG}.pvs.raw") list(APPEND COMMANDS COMMAND "${CMAKE_COMMAND}" -E remove -f "${PVS_STUDIO_LOG}.pvs.raw")
@ -545,7 +561,9 @@ function (pvs_studio_add_target)
set(COMMANDS "") set(COMMANDS "")
endif () endif ()
add_custom_target("${PVS_STUDIO_TARGET}" ${ALL} ${COMMANDS} WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" DEPENDS ${PVS_STUDIO_DEPENDS} "${PVS_STUDIO_LOG}") add_custom_target("${PVS_STUDIO_TARGET}" ${ALL} ${COMMANDS}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
DEPENDS ${PVS_STUDIO_DEPENDS} "${PVS_STUDIO_LOG}")
# A workaround to add implicit dependencies of source files from include directories # A workaround to add implicit dependencies of source files from include directories
set_target_properties("${PVS_STUDIO_TARGET}" PROPERTIES INCLUDE_DIRECTORIES "${inc_path}") set_target_properties("${PVS_STUDIO_TARGET}" PROPERTIES INCLUDE_DIRECTORIES "${inc_path}")