48 lines
1.7 KiB
CMake
48 lines
1.7 KiB
CMake
if(CMAKE_EXPORT_COMPILE_COMMANDS)
|
|
include(PVS-Studio)
|
|
else()
|
|
message(STATUS "MyxCMake: CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.")
|
|
endif()
|
|
|
|
function(myx_cmake_pvs_studio_analyze target)
|
|
set(options)
|
|
set(oneValueArgs CHECKS)
|
|
set(multiValueArgs)
|
|
if(NOT TARGET myx-cmake-pvs-studio-analyze)
|
|
set(PVS_STUDIO_HEADER "${CMAKE_BINARY_DIR}/include/myx_cmake_pvs_studio_header.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")
|
|
|
|
pvs_studio_add_target(TARGET myx-cmake-pvs-studio-analyze
|
|
CONFIG ${PVS_STUDIO_CONFIG}
|
|
DEPENDS ${PVS_STUDIO_CONFIG}
|
|
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)
|
|
|
|
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()
|
|
endif()
|
|
|
|
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()
|
|
endfunction()
|