CppCheckSetup.cmake 2 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
10
11
12
  if(ENABLE_MANTIDPLOT)
    set(MANTIDPLOT_CPPCHECK_SUPPRESSIONS "*:${CMAKE_SOURCE_DIR}/MantidPlot/src/zlib123/*
*:${CMAKE_SOURCE_DIR}/MantidPlot/src/origin/tree.hh
*:${CMAKE_SOURCE_DIR}/MantidPlot/src/nrutil.cpp")
  endif()
13
  configure_file(${CMAKE_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt.in ${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt)
14
15

  # setup the standard arguments
16
17
18
  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
19
20
21
  # Force cppcheck to check when we use project-wide macros
  -DDLLExport=
  -DMANTID_ALGORITHMS_DLL=
22
23
24
  # Undefine problematic macros:
  #   Causes errors such as there was an internal error: bad macro syntax"
  -UQT_TESTCASE_BUILDDIR
25
26
  )

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

41

42

43
44
45
  # generate the target
  if (NOT TARGET cppcheck)
    add_custom_target ( cppcheck
46
                        COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_xml_args}
47
48
49
50
51
52
                        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                        COMMENT "Running cppcheck"
                      )
    set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE)
  endif()
endif ( CPPCHECK_EXECUTABLE )