diff --git a/buildconfig/CMake/CppCheckSetup.cmake b/buildconfig/CMake/CppCheckSetup.cmake index 75d183a1a1004b0dc9d44e46e89a15ab336502f8..b825a1086b1f1f0569d34df41f0c47d72c40ccd5 100644 --- a/buildconfig/CMake/CppCheckSetup.cmake +++ b/buildconfig/CMake/CppCheckSetup.cmake @@ -1,133 +1,26 @@ find_package ( Cppcheck ) 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 - 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 - ) + configure_file(${CMAKE_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt.in ${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt) # 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}") 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) @@ -136,10 +29,12 @@ if ( CPPCHECK_EXECUTABLE ) 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} + COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_xml_args} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMENT "Running cppcheck" ) diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt b/buildconfig/CMake/CppCheck_Suppressions.txt deleted file mode 100644 index 8ea3af11393379dcf667cea4c56c76b7da6ad5cd..0000000000000000000000000000000000000000 --- a/buildconfig/CMake/CppCheck_Suppressions.txt +++ /dev/null @@ -1,14 +0,0 @@ -// suppress specific rule in specific files -// 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 -// Example: -// memsetClassFloat:/Users/builder/Jenkins/workspace/cppcheck-1.72/Framework/DataHandling/src/LoadRaw/isisraw.h - - -// 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 diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt.in b/buildconfig/CMake/CppCheck_Suppressions.txt.in new file mode 100644 index 0000000000000000000000000000000000000000..39acb57ee21a9297f059e03adac6b29ead72e7c5 --- /dev/null +++ b/buildconfig/CMake/CppCheck_Suppressions.txt.in @@ -0,0 +1,5 @@ +// suppress specific rule in specific files +// 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 +// Example: +// memsetClassFloat:/Users/builder/Jenkins/workspace/cppcheck-1.72/ diff --git a/buildconfig/CMake/FindCppcheck.cmake b/buildconfig/CMake/FindCppcheck.cmake index fad22793cb0533a477cdb92d454e4c8e37c9ece9..89bb0b88ec5e512df5d147450bf3893b278e7cf0 100644 --- a/buildconfig/CMake/FindCppcheck.cmake +++ b/buildconfig/CMake/FindCppcheck.cmake @@ -61,15 +61,6 @@ if(CPPCHECK_EXECUTABLE) endif() 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_GENERATE_XML OFF CACHE BOOL "Generate xml output files from cppcheck" )