2022-10-06 04:57:47 +00:00
|
|
|
find_program(PVS_STUDIO_ANALYZER_EXE pvs-studio-analyzer)
|
|
|
|
find_program(PVS_STUDIO_CONVERTER_EXE plog-converter)
|
|
|
|
|
2022-10-06 18:07:22 +00:00
|
|
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
|
|
|
set(MYXX_CMAKE_LIB_PVS_DIR_BACKPORT ${CMAKE_CURRENT_LIST_DIR})
|
|
|
|
endif()
|
|
|
|
|
2022-10-09 18:15:35 +00:00
|
|
|
function(myxx_analyze_pvs_studio TARGET_NAME)
|
2022-10-06 18:07:22 +00:00
|
|
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
|
|
|
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYXX_CMAKE_LIB_PVS_DIR_BACKPORT})
|
|
|
|
endif()
|
2022-10-09 18:15:35 +00:00
|
|
|
|
2022-10-19 13:59:18 +00:00
|
|
|
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
|
|
|
return()
|
|
|
|
endif()
|
2022-10-09 18:15:35 +00:00
|
|
|
|
2022-10-06 18:07:22 +00:00
|
|
|
if(NOT PVS_STUDIO_ANALYZER_EXE)
|
2022-10-06 04:57:47 +00:00
|
|
|
message(STATUS "MyxxCMake: pvs-studio-analyzer not found.")
|
|
|
|
return()
|
|
|
|
endif()
|
2022-10-06 18:07:22 +00:00
|
|
|
if(NOT PVS_STUDIO_CONVERTER_EXE)
|
2022-10-06 04:57:47 +00:00
|
|
|
message(STATUS "MyxxCMake: pvs-studio-converter not found.")
|
|
|
|
return()
|
|
|
|
endif()
|
2022-10-06 18:07:22 +00:00
|
|
|
if(NOT TARGET myxx-analyze-pvs-studio)
|
|
|
|
add_custom_target(myxx-analyze-pvs-studio)
|
2022-10-06 04:57:47 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(options)
|
2022-10-06 18:07:22 +00:00
|
|
|
set(oneValueArgs HEADER MODE)
|
|
|
|
set(multiValueArgs ARGS)
|
2022-10-06 04:57:47 +00:00
|
|
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
|
2022-10-06 18:07:22 +00:00
|
|
|
if(NOT ARG_HEADER)
|
|
|
|
set(ARG_HEADER ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/pvs-studio/pvs_studio.hpp.in)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ARG_MODE)
|
2022-10-08 14:25:50 +00:00
|
|
|
set(ARG_MODE "GA:1,2,3;64:1,2;OP:1,2,3;CS:1,2;OWASP:1,2")
|
2022-10-06 18:07:22 +00:00
|
|
|
endif()
|
|
|
|
|
2022-10-19 13:59:18 +00:00
|
|
|
get_target_property(__target_sources ${TARGET_NAME} SOURCES)
|
|
|
|
foreach(__iter ${__target_sources})
|
|
|
|
string(FIND ${__iter} ${CMAKE_BINARY_DIR} __pos)
|
|
|
|
if(__pos EQUAL -1)
|
|
|
|
list(APPEND __filtered_sources ${__iter})
|
2022-10-08 14:25:50 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2022-10-09 18:15:35 +00:00
|
|
|
pvs_studio_add_target(TARGET ${TARGET_NAME}-analyze-pvs-studio
|
|
|
|
ANALYZE ${TARGET_NAME}
|
2022-10-08 14:25:50 +00:00
|
|
|
COMPILE_COMMANDS
|
2022-10-06 04:57:47 +00:00
|
|
|
HIDE_HELP
|
2022-10-06 18:07:22 +00:00
|
|
|
OUTPUT
|
|
|
|
FORMAT errorfile
|
|
|
|
ARGS --exclude-path ${CMAKE_CURRENT_BINARY_DIR} ${ARG_ARGS}
|
|
|
|
MODE ${ARG_MODE})
|
2022-10-06 04:57:47 +00:00
|
|
|
|
2022-10-09 18:15:35 +00:00
|
|
|
get_target_property(__target_type ${TARGET_NAME} TYPE)
|
|
|
|
if(${__target_type} STREQUAL INTERFACE_LIBRARY)
|
|
|
|
set(__target_type INTERFACE)
|
2022-10-06 04:57:47 +00:00
|
|
|
else()
|
2022-10-09 18:15:35 +00:00
|
|
|
set(__target_type PRIVATE)
|
2022-10-06 04:57:47 +00:00
|
|
|
endif()
|
|
|
|
if(MSVC)
|
2022-10-09 18:15:35 +00:00
|
|
|
target_compile_options(${TARGET_NAME} BEFORE ${__target_type} /FI ${ARG_HEADER})
|
2022-10-06 04:57:47 +00:00
|
|
|
else() # GCC/Clang
|
2022-10-09 18:15:35 +00:00
|
|
|
target_compile_options(${TARGET_NAME} BEFORE ${__target_type} -include ${ARG_HEADER})
|
2022-10-06 04:57:47 +00:00
|
|
|
endif()
|
|
|
|
|
2022-10-09 18:15:35 +00:00
|
|
|
add_dependencies(${TARGET_NAME}-analyze-pvs-studio ${TARGET_NAME})
|
|
|
|
add_dependencies(myxx-analyze-pvs-studio ${TARGET_NAME}-analyze-pvs-studio)
|
2022-10-06 04:57:47 +00:00
|
|
|
endfunction()
|