2020-04-13 16:44:42 +00:00
|
|
|
function(add_pvs_check target)
|
2019-10-07 10:52:50 +00:00
|
|
|
if(CMAKE_EXPORT_COMPILE_COMMANDS)
|
2019-06-26 08:46:53 +00:00
|
|
|
include(PVS-Studio)
|
|
|
|
find_program(PVS_STUDIO_ANALYZER_EXE NAMES pvs-studio-analyzer)
|
|
|
|
if(PVS_STUDIO_ANALYZER_EXE)
|
2019-06-27 02:18:29 +00:00
|
|
|
if(NOT TARGET pvs-check)
|
|
|
|
add_custom_target(pvs-check)
|
|
|
|
endif()
|
2019-12-03 16:23:14 +00:00
|
|
|
pvs_studio_add_target(
|
2020-04-13 16:44:42 +00:00
|
|
|
TARGET pvs-check-${target}
|
|
|
|
DEPENDS ${target}
|
2019-12-03 16:23:14 +00:00
|
|
|
COMPILE_COMMANDS HIDE_HELP OUTPUT
|
|
|
|
FORMAT errorfile
|
2020-04-13 16:44:42 +00:00
|
|
|
CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${target}.cfg"
|
|
|
|
ARGS --analysis-mode 29 --exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${target}_autogen
|
2019-12-03 16:23:14 +00:00
|
|
|
MODE GA:1,2,3;64:1;OP:1,2;CS:1,2)
|
2020-04-13 16:44:42 +00:00
|
|
|
add_dependencies(pvs-check pvs-check-${target})
|
2020-10-02 05:37:25 +00:00
|
|
|
configure_file("${CMLIB_MODULE_DIR}/hpp/pvs_studio.hpp.in" "${CMAKE_BINARY_DIR}/include/pvs_studio.hpp")
|
2020-10-02 08:31:18 +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()
|
2020-10-02 05:37:25 +00:00
|
|
|
if(MSVC)
|
2020-10-02 08:38:14 +00:00
|
|
|
target_compile_options(${target} BEFORE ${target_type} /FI "${CMAKE_BINARY_DIR}/include/pvs_studio.hpp")
|
2020-10-02 05:37:25 +00:00
|
|
|
else() # GCC/Clang
|
2020-10-02 08:38:14 +00:00
|
|
|
target_compile_options(${target} BEFORE ${target_type} -include "${CMAKE_BINARY_DIR}/include/pvs_studio.hpp")
|
2020-10-02 05:37:25 +00:00
|
|
|
endif()
|
2019-06-26 08:46:53 +00:00
|
|
|
else()
|
2019-08-10 07:30:01 +00:00
|
|
|
message(STATUS "CMLIB warning:")
|
|
|
|
message(STATUS " PVS-Studio analyzer is not found")
|
2019-06-26 08:46:53 +00:00
|
|
|
endif()
|
2019-02-15 21:00:53 +00:00
|
|
|
else()
|
2019-08-13 19:09:42 +00:00
|
|
|
message(STATUS "CMLIB warning:")
|
2020-04-01 18:42:59 +00:00
|
|
|
message(STATUS " Option CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.")
|
2019-02-15 21:00:53 +00:00
|
|
|
endif()
|
2019-06-15 14:54:40 +00:00
|
|
|
endfunction()
|