CppCheckSetup.cmake 1.59 KB
Newer Older
1
2
3
4
find_package ( Cppcheck )

if ( CPPCHECK_EXECUTABLE )

5
6
7
  # We must export the compile commands for cppcheck to be able to check
  # everything correctly
  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
8

9
  configure_file(${CMAKE_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt.in ${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt)
10
11

  # setup the standard arguments
12
13
14
15
16
17
  set ( CPPCHECK_ARGS --enable=all --inline-suppr --max-configs=120
  --suppressions-list=${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt
  --suppress=*:*${CMAKE_BINARY_DIR}/*
  --project=${CMAKE_BINARY_DIR}/compile_commands.json
  )

18
  set (_cppcheck_args "${CPPCHECK_ARGS}")
19
    list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} )
20
21
22
23
24
25
26
    if ( CPPCHECK_NUM_THREADS GREATER 0)
        list ( APPEND _cppcheck_args -j ${CPPCHECK_NUM_THREADS} )
  endif ( CPPCHECK_NUM_THREADS GREATER 0)

  # put the finishing bits on the final command call
  set (_cppcheck_xml_args)
  if (CPPCHECK_GENERATE_XML)
Nick Draper's avatar
Nick Draper committed
27
    list( APPEND _cppcheck_xml_args  --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
28
29
30
31
  else (CPPCHECK_GENERATE_XML)
    list( APPEND _cppcheck_xml_args  ${_cppcheck_source_dirs} )
  endif (CPPCHECK_GENERATE_XML)

32
33
  

34
35
36
  # generate the target
  if (NOT TARGET cppcheck)
    add_custom_target ( cppcheck
37
                        COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_xml_args}
38
39
40
41
42
43
                        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                        COMMENT "Running cppcheck"
                      )
    set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE)
  endif()
endif ( CPPCHECK_EXECUTABLE )