Commit 453bf557 authored by David Fairbrother's avatar David Fairbrother
Browse files

Update cppcheck in CMake build config

Updates the cppcheck target to run like a typical compilation. This
means CMake will fix-up the headers required on the fly. This reduces
the time compared to adding all headers, and improves the accuracy
significantly.
parent 419191fb
find_package ( Cppcheck ) find_package ( Cppcheck )
if ( CPPCHECK_EXECUTABLE ) if ( CPPCHECK_EXECUTABLE )
set ( CPPCHECK_SOURCE_DIRS
Framework
MantidPlot
qt/paraview_ext
qt/scientific_interfaces
qt/widgets/common
qt/widgets/instrumentView
qt/widgets/mplcpp
)
option ( CPPCHECK_USE_INCLUDE_DIRS "Use specified include directories. WARNING: cppcheck will run significantly slower." ) # We must export the compile commands for cppcheck to be able to check
# everything correctly
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set ( CPPCHECK_INCLUDE_DIRS configure_file(${CMAKE_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt.in ${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt)
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
qt/paraview_ext/VatesAPI/inc
qt/paraview_ext/VatesSimpleGui/ViewWidgets/inc
qt/paraview_ext/VatesSimpleGui/QtWidgets/inc
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
)
set ( CPPCHECK_EXCLUDES
Framework/LiveData/src/ISIS/DAE/
Framework/LiveData/src/Kafka/private/Schema/
Framework/DataHandling/src/LoadRaw/
Framework/ICat/inc/MantidICat/ICat3/GSoapGenerated/
Framework/ICat/src/ICat3/GSoapGenerated/
Framework/ICat/src/ICat3/ICat3GSoapGenerated.cpp
Framework/ICat/inc/MantidICat/ICat4/GSoapGenerated/
Framework/ICat/src/ICat4/GSoapGenerated/
Framework/ICat/src/ICat4/ICat4GSoapGenerated.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
MantidPlot/src/zlib123/minigzip.c
Framework/SINQ/src/PoldiPeakFit.cpp
qt/widgets/common/src/QtPropertyBrowser/
qt/widgets/common/inc/MantidQtWidgets/Common/QtPropertyBrowser/
)
# Header files to be ignored require different handling
set ( CPPCHECK_HEADER_EXCLUDES
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
MantidPlot/src/origin/OPJFile.h
MantidPlot/src/origin/tree.hh
)
# setup the standard arguments # setup the standard arguments
set ( CPPCHECK_ARGS --enable=all --inline-suppr --max-configs=120
--suppressions-list=${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt
--suppress=*:*${CMAKE_BINARY_DIR}/*
--project=${CMAKE_BINARY_DIR}/compile_commands.json
)
set (_cppcheck_args "${CPPCHECK_ARGS}") set (_cppcheck_args "${CPPCHECK_ARGS}")
list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} ) list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} )
if ( CPPCHECK_NUM_THREADS GREATER 0) if ( CPPCHECK_NUM_THREADS GREATER 0)
list ( APPEND _cppcheck_args -j ${CPPCHECK_NUM_THREADS} ) list ( APPEND _cppcheck_args -j ${CPPCHECK_NUM_THREADS} )
endif ( CPPCHECK_NUM_THREADS GREATER 0) 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 # put the finishing bits on the final command call
set (_cppcheck_xml_args) set (_cppcheck_xml_args)
if (CPPCHECK_GENERATE_XML) if (CPPCHECK_GENERATE_XML)
...@@ -136,10 +29,12 @@ if ( CPPCHECK_EXECUTABLE ) ...@@ -136,10 +29,12 @@ if ( CPPCHECK_EXECUTABLE )
list( APPEND _cppcheck_xml_args ${_cppcheck_source_dirs} ) list( APPEND _cppcheck_xml_args ${_cppcheck_source_dirs} )
endif (CPPCHECK_GENERATE_XML) endif (CPPCHECK_GENERATE_XML)
# generate the target # generate the target
if (NOT TARGET cppcheck) if (NOT TARGET cppcheck)
add_custom_target ( cppcheck add_custom_target ( cppcheck
COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_header_excludes} ${_cppcheck_xml_args} COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_xml_args}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running cppcheck" COMMENT "Running cppcheck"
) )
......
...@@ -2,13 +2,4 @@ ...@@ -2,13 +2,4 @@
// NOTE this needs the full path to the file, so would need this file to be generated by cmake // NOTE this needs the full path to the file, so would need this file to be generated by cmake
// as different build servers have different starts to the file path // as different build servers have different starts to the file path
// Example: // Example:
// memsetClassFloat:/Users/builder/Jenkins/workspace/cppcheck-1.72/Framework/DataHandling/src/LoadRaw/isisraw.h // memsetClassFloat:/Users/builder/Jenkins/workspace/cppcheck-1.72/
// suppress in all files - BE CAREFUL not to leave trailing spaces after the rule id. or empty lines
// For a library this is not a problem per se
// unusedFunction
// cppcheck has problems handling the number of pre-processor definitions used in the DLL_EXPORTs
class_X_Y
// the exported functions are not used in the cpp land
unusedFunction:Framework/PythonInterface/mantid/*/src/Exports/*.cpp
...@@ -61,15 +61,6 @@ if(CPPCHECK_EXECUTABLE) ...@@ -61,15 +61,6 @@ if(CPPCHECK_EXECUTABLE)
endif() endif()
mark_as_advanced(CPPCHECK_EXECUTABLE) mark_as_advanced(CPPCHECK_EXECUTABLE)
if(CPPCHECK_EXECUTABLE)
if (${CPPCHECK_VERSION} VERSION_LESS 1.71)
set ( CPPCHECK_ARGS --enable=all --inline-suppr --max-configs=120
--suppressions ${CMAKE_CURRENT_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt )
else()
set ( CPPCHECK_ARGS --enable=all --inline-suppr --max-configs=120
--suppressions-list=${CMAKE_CURRENT_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt )
endif()
endif()
set ( CPPCHECK_NUM_THREADS 0 CACHE STRING "Number of threads to use when running cppcheck" ) set ( CPPCHECK_NUM_THREADS 0 CACHE STRING "Number of threads to use when running cppcheck" )
set ( CPPCHECK_GENERATE_XML OFF CACHE BOOL "Generate xml output files from cppcheck" ) set ( CPPCHECK_GENERATE_XML OFF CACHE BOOL "Generate xml output files from cppcheck" )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment