2022-05-06 09:49:46 +00:00
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
|
|
|
|
2021-12-08 11:32:04 +00:00
|
|
|
if(CMAKE_EXPORT_COMPILE_COMMANDS)
|
|
|
|
include(PVS-Studio)
|
2021-12-21 11:44:43 +00:00
|
|
|
find_program(PVS_STUDIO_ANALYZER_EXE pvs-studio-analyzer)
|
|
|
|
find_program(PVS_STUDIO_CONVERTER_EXE plog-converter)
|
2021-12-08 11:32:04 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "MyxCMake: CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.")
|
|
|
|
endif()
|
|
|
|
|
2021-12-13 13:21:08 +00:00
|
|
|
function(myx_cmake_analyze_pvs_studio target)
|
2021-12-21 11:44:43 +00:00
|
|
|
if(PVS_STUDIO_ANALYZER_EXE AND PVS_STUDIO_CONVERTER_EXE)
|
2021-12-20 08:34:41 +00:00
|
|
|
set(options)
|
|
|
|
set(oneValueArgs CHECKS)
|
|
|
|
set(multiValueArgs)
|
|
|
|
if(NOT TARGET myx-cmake-analyze-pvs-studio)
|
|
|
|
set(PVS_STUDIO_HEADER "${CMAKE_BINARY_DIR}/include/myx_cmake_pvs_studio_header_p.hpp")
|
|
|
|
file(WRITE ${PVS_STUDIO_HEADER}
|
|
|
|
"#ifndef MYX_CMAKE_PVS_STUDIO_HEADER_HPP_\n"
|
|
|
|
"#define MYX_CMAKE_PVS_STUDIO_HEADER_HPP_\n"
|
|
|
|
"#pragma once\n"
|
|
|
|
"//-V813_MINSIZE=33\n"
|
|
|
|
"#endif // MYX_CMAKE_PVS_STUDIO_HEADER_HPP_\n")
|
2021-12-08 11:32:04 +00:00
|
|
|
|
2021-12-21 14:21:12 +00:00
|
|
|
pvs_studio_add_target(TARGET myx-cmake-analyze-pvs-studio
|
|
|
|
LOG
|
|
|
|
COMPILE_COMMANDS
|
|
|
|
HIDE_HELP
|
|
|
|
OUTPUT FORMAT errorfile
|
|
|
|
ARGS --exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${target}_autogen
|
|
|
|
MODE GA:1,2,3;64:1;OP:1,2;CS:1,2)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
2021-12-20 08:34:41 +00:00
|
|
|
get_target_property(__target_type ${target} TYPE)
|
|
|
|
if(${__target_type} STREQUAL INTERFACE_LIBRARY)
|
|
|
|
set(__target_type INTERFACE)
|
|
|
|
else()
|
|
|
|
set(__target_type PRIVATE)
|
|
|
|
endif()
|
|
|
|
if(MSVC)
|
|
|
|
target_compile_options(${target} BEFORE ${__target_type} /FI ${PVS_STUDIO_HEADER})
|
|
|
|
else() # GCC/Clang
|
|
|
|
target_compile_options(${target} BEFORE ${__target_type} -include ${PVS_STUDIO_HEADER})
|
|
|
|
endif()
|
2021-12-12 14:49:46 +00:00
|
|
|
|
2021-12-20 08:34:41 +00:00
|
|
|
add_dependencies(myx-cmake-analyze-pvs-studio ${target})
|
|
|
|
get_target_property(__target_source_dir "${target}" SOURCE_DIR)
|
|
|
|
pvs_studio_analyze_target("${target}" "${__target_source_dir}")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(STATUS "MyxCMake: pvs-studio-analyzer not found.")
|
2021-12-08 11:32:04 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|