CppCheckSetup.cmake 1.66 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
  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
15
16
17
  # Force cppcheck to check when we use project-wide macros
  -DDLLExport=
  -DMANTID_ALGORITHMS_DLL=
18
19
  )

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

34
35
  

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