CppCheckSetup.cmake 4.83 KB
Newer Older
1
2
3
4
5
6
find_package ( Cppcheck )

if ( CPPCHECK_EXECUTABLE )
  set ( CPPCHECK_SOURCE_DIRS
        Framework
        MantidPlot
7
        qt
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
      )

  set ( CPPCHECK_USE_INCLUDE_DIRS OFF CACHE BOOL "Use specified include directories. WARNING: cppcheck will run significantly slower." )

  set ( CPPCHECK_INCLUDE_DIRS
        Framework/Algorithms/inc
        Framework/PythonInterface/inc
        Framework/Nexus/inc
        Framework/MPIAlgorithms/inc
        Framework/MDAlgorithms/inc
        Framework/DataHandling/inc
        Framework/WorkflowAlgorithms/inc
        Framework/MDEvents/inc
        Framework/DataObjects/inc
        Framework/Geometry/inc
        Framework/ICat/inc
        Framework/CurveFitting/inc
        Framework/API/inc
        Framework/TestHelpers/inc
        Framework/Crystal/inc
        Framework/Kernel/inc
29
30
31
        qt/paraview_ext/VatesAPI/inc
        qt/paraview_ext/VatesSimpleGui/ViewWidgets/inc
        qt/paraview_ext/VatesSimpleGui/QtWidgets/inc
32
33
34
35
36
37
38
39
40
        qt/widgets/common/inc
        qt/widgets/factory/inc
        qt/widgets/instrumentview/inc
        qt/widgets/refdetectrview/inc
        qt/widgets/sliceviewer/inc
        qt/widgets/spectrumviewer/inc
        qt/widgets/plugins/algorithm_dialogs/inc
        qt/widgets/plugins/designer/inc
        qt/scientific_interfaces
41
42
43
      )

  set ( CPPCHECK_EXCLUDES
Martyn Gigg's avatar
Martyn Gigg committed
44
        Framework/LiveData/src/ISIS/DAE/
45
46
        Framework/LiveData/src/ISIS/private/flatbuffers/
        Framework/LiveData/src/ISIS/private/schema/
47
48
49
        Framework/DataHandling/src/LoadRaw/
        Framework/ICat/inc/MantidICat/ICat3/GSoapGenerated/
        Framework/ICat/src/ICat3/GSoapGenerated/
50
51
52
53
        Framework/ICat/src/ICat3/ICat3GSoapGenerated.cpp
        Framework/ICat/inc/MantidICat/ICat4/GSoapGenerated/
        Framework/ICat/src/ICat4/GSoapGenerated/
        Framework/ICat/src/ICat4/ICat4GSoapGenerated.cpp
54
55
56
57
58
59
60
        Framework/ICat/src/GSoap/
        Framework/ICat/src/GSoap.cpp
        Framework/Kernel/src/ANN/
        Framework/Kernel/src/ANN_complete.cpp
        Framework/Kernel/src/Math/Optimization/SLSQPMinimizer.cpp
        MantidPlot/src/nrutil.cpp
        MantidPlot/src/origin/OPJFile.cpp
Nick Draper's avatar
Nick Draper committed
61
62
        MantidPlot/src/zlib123/minigzip.c
        Framework/SINQ/src/PoldiPeakFit.cpp
Roman Tolchenov's avatar
Roman Tolchenov committed
63
64
        qt/widgets/common/src/QtPropertyBrowser/
        qt/widgets/common/inc/MantidQtWidgets/Common/QtPropertyBrowser/
65
66
67
68
69
      )

  # Header files to be ignored require different handling
  set ( CPPCHECK_HEADER_EXCLUDES
        MantidPlot/src/origin/OPJFile.h
70
        MantidPlot/src/origin/tree.hh
71
72
73
74
      )

  # setup the standard arguments
  set (_cppcheck_args "${CPPCHECK_ARGS}")
75
    list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} "--inline-suppr")
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    if ( CPPCHECK_NUM_THREADS GREATER 0)
        list ( APPEND _cppcheck_args -j ${CPPCHECK_NUM_THREADS} )
  endif ( CPPCHECK_NUM_THREADS GREATER 0)

  # process list of include/exclude directories
  set (_cppcheck_source_dirs)
  foreach (_dir ${CPPCHECK_SOURCE_DIRS} )
    set ( _tmpdir "${CMAKE_SOURCE_DIR}/${_dir}" )
    if ( EXISTS ${_tmpdir} )
      list ( APPEND _cppcheck_source_dirs ${_tmpdir} )
    endif ()
  endforeach()

  set (_cppcheck_includes)
  foreach( _dir ${CPPCHECK_INCLUDE_DIRS} )
    set ( _tmpdir "${CMAKE_SOURCE_DIR}/${_dir}" )
    if ( EXISTS ${_tmpdir} )
      list ( APPEND _cppcheck_includes -I ${_tmpdir} )
    endif ()
  endforeach()
  if (CPPCHECK_USE_INCLUDE_DIRS)
    list ( APPEND _cppcheck_args ${_cppcheck_includes} )
  endif (CPPCHECK_USE_INCLUDE_DIRS)

  set (_cppcheck_excludes)
  foreach( _file ${CPPCHECK_EXCLUDES} )
    set ( _tmp "${CMAKE_SOURCE_DIR}/${_file}" )
    if ( EXISTS ${_tmp} )
      list ( APPEND _cppcheck_excludes -i ${_tmp} )
    endif ()
  endforeach()
  list ( APPEND _cppcheck_args ${_cppcheck_excludes} )

  # Handle header files in the required manner
  set (_cppcheck_header_excludes)
  foreach( _file ${CPPCHECK_HEADER_EXCLUDES} )
    set ( _tmp "${CMAKE_SOURCE_DIR}/${_file}" )
    if ( EXISTS ${_tmp} )
      list ( APPEND _cppcheck_header_excludes --suppress=*:${_tmp} )
    endif()
  endforeach()
  list ( APPEND _cppcheck_args ${_cppcheck_header_excludes} )

  # put the finishing bits on the final command call
  set (_cppcheck_xml_args)
  if (CPPCHECK_GENERATE_XML)
Nick Draper's avatar
Nick Draper committed
122
    list( APPEND _cppcheck_xml_args  --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  else (CPPCHECK_GENERATE_XML)
    list( APPEND _cppcheck_xml_args  ${_cppcheck_source_dirs} )
  endif (CPPCHECK_GENERATE_XML)

  # generate the target
  if (NOT TARGET cppcheck)
    add_custom_target ( cppcheck
                        COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_header_excludes} ${_cppcheck_xml_args}
                        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                        COMMENT "Running cppcheck"
                      )
    set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE)
  endif()
endif ( CPPCHECK_EXECUTABLE )