find_program(PVS_STUDIO_ANALYZER_EXE pvs-studio-analyzer) find_program(PVS_STUDIO_CONVERTER_EXE plog-converter) if(${CMAKE_VERSION} VERSION_LESS "3.17.0") set(MYXX_CMAKE_LIB_PVS_DIR_BACKPORT ${CMAKE_CURRENT_LIST_DIR}) endif() function(myxx_analyze_pvs_studio target) if(${CMAKE_VERSION} VERSION_LESS "3.17.0") set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYXX_CMAKE_LIB_PVS_DIR_BACKPORT}) endif() if(NOT PVS_STUDIO_ANALYZER_EXE) message(STATUS "MyxxCMake: pvs-studio-analyzer not found.") return() endif() if(NOT PVS_STUDIO_CONVERTER_EXE) message(STATUS "MyxxCMake: pvs-studio-converter not found.") return() endif() if(NOT TARGET myxx-analyze-pvs-studio) add_custom_target(myxx-analyze-pvs-studio) endif() set(options) set(oneValueArgs HEADER MODE) set(multiValueArgs ARGS) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(NOT ARG_HEADER) set(ARG_HEADER ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/pvs-studio/pvs_studio.hpp.in) endif() if(NOT ARG_MODE) set(ARG_MODE "GA:1,2,3;64:1,2,3;OP:1,2,3;CS:1,2,3;OWASP:1,2,3") endif() pvs_studio_add_target(TARGET ${target}-analyze-pvs-studio ANALYZE ${target} HIDE_HELP OUTPUT FORMAT errorfile ARGS --exclude-path ${CMAKE_CURRENT_BINARY_DIR} ${ARG_ARGS} MODE ${ARG_MODE}) 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 ${ARG_HEADER}) else() # GCC/Clang target_compile_options(${target} BEFORE ${target_type} -include ${ARG_HEADER}) endif() add_dependencies(${target}-analyze-pvs-studio ${target}) add_dependencies(myxx-analyze-pvs-studio ${target}-analyze-pvs-studio) endfunction()