5 # Find cppcheck executable.
10 # This module defines the following variables:
14 # ``CPPCHECK_EXECUTABLE``
16 # ``CPPCHECK_VERSION``
21 # .. command:: add_cppcheck
25 # add_cppcheck([OPTIONS opt] [TARGETS tgt ...] [tgt ...])
27 include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
28 find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
29 mark_as_advanced(CPPCHECK_EXECUTABLE)
31 if(EXISTS "${CPPCHECK_EXECUTABLE}")
32 execute_process(COMMAND ${CPPCHECK_EXECUTABLE} --version OUTPUT_VARIABLE CPPCHECK_VERSION)
33 string(REGEX REPLACE ".*check ([^\n ]+).*" "\\1" CPPCHECK_VERSION "${CPPCHECK_VERSION}")
36 find_package_handle_standard_args(cppcheck
46 function(add_cppcheck)
47 if(CMAKE_VERSION VERSION_LESS 3.10)
50 cmake_parse_arguments(CPPCHECK "" "" "TARGETS;OPTIONS" ${ARGN})
51 list(APPEND CPPCHECK_TARGETS ${CPPCHECK_UNPARSED_ARGUMENTS})
52 set_target_properties(${CPPCHECK_TARGETS} PROPERTIES C_CPPCHECK "${CPPCHECK_EXECUTABLE};${CPPCHECK_OPTIONS}")
53 set_target_properties(${CPPCHECK_TARGETS} PROPERTIES CXX_CPPCHECK "${CPPCHECK_EXECUTABLE};${CPPCHECK_OPTIONS}")