CppCheckSetup.cmake 4.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
122
123
124
125
126
127
128
129
find_package ( Cppcheck )

if ( CPPCHECK_EXECUTABLE )
  set ( CPPCHECK_SOURCE_DIRS
        Framework
        MantidPlot
        MantidQt
        Vates
      )

  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/GPUAlgorithms/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
        Vates/VatesAPI/inc
        Vates/VatesSimpleGui/ViewWidgets/inc
        Vates/VatesSimpleGui/StandAloneExec/inc
        Vates/VatesSimpleGui/QtWidgets/inc
        MantidQt/MantidWidgets/inc
        MantidQt/CustomDialogs/inc
        MantidQt/DesignerPlugins/inc
        MantidQt/CustomInterfaces/inc
        MantidQt/API/inc
        MantidQt/Factory/inc
        MantidQt/SliceViewer/inc
      )

  set ( CPPCHECK_EXCLUDES
        Framework/DataHandling/src/LoadDAE/
        Framework/DataHandling/src/LoadRaw/
        Framework/ICat/inc/MantidICat/ICat3/GSoapGenerated/
        Framework/ICat/src/ICat3/GSoapGenerated/
        Framework/ICat/src/GSoapGenerated.cpp
        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
      )

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

  # setup the standard arguments
  set (_cppcheck_args "${CPPCHECK_ARGS}")
    list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} )
    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)
    list( APPEND _cppcheck_xml_args --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
  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 )