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

if ( CPPCHECK_EXECUTABLE )

5
6
7
8
  # We must export the compile commands for cppcheck to be able to check
  # everything correctly
  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  configure_file(${CMAKE_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt.in ${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt)
9
10

  # setup the standard arguments
11
12
13
  set ( CPPCHECK_ARGS --enable=all --inline-suppr --max-configs=120
  --suppressions-list=${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt
  --project=${CMAKE_BINARY_DIR}/compile_commands.json
14
15
16
  # Force cppcheck to check when we use project-wide macros
  -DDLLExport=
  -DMANTID_ALGORITHMS_DLL=
17
18
19
  # Undefine problematic macros:
  #   Causes errors such as there was an internal error: bad macro syntax"
  -UQT_TESTCASE_BUILDDIR
20
21
  )

22
  set (_cppcheck_args "${CPPCHECK_ARGS}")
23
    list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} )
24
25
26
27
28
29
30
    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
31
    list( APPEND _cppcheck_xml_args  --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
32
33
34
35
  else (CPPCHECK_GENERATE_XML)
    list( APPEND _cppcheck_xml_args  ${_cppcheck_source_dirs} )
  endif (CPPCHECK_GENERATE_XML)

36

37

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