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

if ( CPPCHECK_EXECUTABLE )
  set ( CPPCHECK_SOURCE_DIRS
        Framework
        MantidPlot
7
8
9
10
11
        qt/paraview_ext
        qt/scientific_interfaces
        qt/widgets/common
        qt/widgets/instrumentView
        qt/widgets/mplcpp
12
13
      )

14
  option ( CPPCHECK_USE_INCLUDE_DIRS "Use specified include directories. WARNING: cppcheck will run significantly slower." )
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

  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
33
34
35
        qt/paraview_ext/VatesAPI/inc
        qt/paraview_ext/VatesSimpleGui/ViewWidgets/inc
        qt/paraview_ext/VatesSimpleGui/QtWidgets/inc
36
37
38
39
40
41
42
43
44
        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
45
46
47
      )

  set ( CPPCHECK_EXCLUDES
Martyn Gigg's avatar
Martyn Gigg committed
48
        Framework/LiveData/src/ISIS/DAE/
Antti Soininen's avatar
Antti Soininen committed
49
        Framework/LiveData/src/Kafka/private/Schema/
50
51
52
        Framework/DataHandling/src/LoadRaw/
        Framework/ICat/inc/MantidICat/ICat3/GSoapGenerated/
        Framework/ICat/src/ICat3/GSoapGenerated/
53
54
55
56
        Framework/ICat/src/ICat3/ICat3GSoapGenerated.cpp
        Framework/ICat/inc/MantidICat/ICat4/GSoapGenerated/
        Framework/ICat/src/ICat4/GSoapGenerated/
        Framework/ICat/src/ICat4/ICat4GSoapGenerated.cpp
57
58
59
60
61
62
63
        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
64
65
        MantidPlot/src/zlib123/minigzip.c
        Framework/SINQ/src/PoldiPeakFit.cpp
Roman Tolchenov's avatar
Roman Tolchenov committed
66
67
        qt/widgets/common/src/QtPropertyBrowser/
        qt/widgets/common/inc/MantidQtWidgets/Common/QtPropertyBrowser/
68
69
70
71
      )

  # Header files to be ignored require different handling
  set ( CPPCHECK_HEADER_EXCLUDES
Antti Soininen's avatar
Antti Soininen committed
72
73
74
75
76
77
78
79
80
        Framework/LiveData/src/Kafka/private/Schema/ba57_run_info_generated.h
        Framework/LiveData/src/Kafka/private/Schema/df12_det_spec_map_generated.h
        Framework/LiveData/src/Kafka/private/Schema/ev42_events_generated.h
        Framework/LiveData/src/Kafka/private/Schema/fwdi_forwarder_internal_generated.h
        Framework/LiveData/src/Kafka/private/Schema/f142_logdata_generated.h
        Framework/LiveData/src/Kafka/private/Schema/is84_isis_events_generated.h
        Framework/LiveData/src/Kafka/private/Schema/flatbuffers/base.h
        Framework/LiveData/src/Kafka/private/Schema/flatbuffers/flatbuffers.h
        Framework/LiveData/src/Kafka/private/Schema/flatbuffers/stl_emulation.h
81
        MantidPlot/src/origin/OPJFile.h
82
        MantidPlot/src/origin/tree.hh
83
84
85
86
      )

  # setup the standard arguments
  set (_cppcheck_args "${CPPCHECK_ARGS}")
87
    list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} )
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
122
123
124
125
126
127
128
129
130
131
132
133
    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
134
    list( APPEND _cppcheck_xml_args  --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  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 )