From a244914ca34e69921c3ab20bb137bf4f418376fa Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 27 Sep 2018 02:43:28 +0200 Subject: [PATCH] cmake: Add Template and Inline Suppression support for CppCheck --- cmake/cppcheck.cmake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmake/cppcheck.cmake b/cmake/cppcheck.cmake index 032fbd69..652f91c9 100644 --- a/cmake/cppcheck.cmake +++ b/cmake/cppcheck.cmake @@ -26,14 +26,16 @@ function(cppcheck) set(CPPCHECK_FORCE_CPP OFF CACHE BOOL "Force checking with C++ language (overrides CPPCHECK_FORCE_C)") set(CPPCHECK_VERBOSE ON CACHE BOOL "Show more detailed error reports") set(CPPCHECK_QUIET ON CACHE BOOL "Hide progress reports") + set(CPPCHECK_ENABLE_INLINE_SUPPRESSION ON CACHE BOOL "Enable inline suppression of warnings via '// cppcheck-suppress id' comments") set(CPPCHECK_LIBRARIES "" CACHE STRING "List of Libraries to load separated by semicolon") set(CPPCHECK_EXCLUDE_DIRECTORIES "" CACHE STRING "List of directories to exclude separated by semicolon") set(CPPCHECK_PARALLEL_TASKS "4" CACHE STRING "Number of threads to use for cppcheck") + set(CPPCHECK_TEMPLATE "{file}({line}:{column}): {severity} {id}: {message}" CACHE STRING "Template for reported messages") if(WIN32) set(CPPCHECK_WIN32_UNICODE ON CACHE BOOL "Use Unicode character encoding for Win32") endif() - mark_as_advanced(CPPCHECK_BIN CPPCHECK_QUIET CPPCHECK_VERBOSE CPPCHECK_LIBRARIES CPPCHECK_ENABLE_INCONCLUSIVE CPPCHECK_PARALLEL_TASKS) + mark_as_advanced(CPPCHECK_BIN CPPCHECK_QUIET CPPCHECK_VERBOSE CPPCHECK_LIBRARIES CPPCHECK_ENABLE_INCONCLUSIVE CPPCHECK_PARALLEL_TASKS CPPCHECK_TEMPLATE) # Parse arguments set(cppcheck_options ) @@ -82,9 +84,7 @@ function(cppcheck) set(CPPCHECK_ARGUMENTS "") # Compiler - if(MSVC) - #list(APPEND CPPCHECK_ARGUMENTS --template="{file}|{line}|{severity}|{id}|{message}") - endif() + list(APPEND CPPCHECK_ARGUMENTS --template=${CPPCHECK_TEMPLATE}) # Flags if(CPPCHECK_ENABLE_INCONCLUSIVE) @@ -102,6 +102,9 @@ function(cppcheck) if(CPPCHECK_PARALLEL_TASKS) list(APPEND CPPCHECK_ARGUMENTS -j ${CPPCHECK_PARALLEL_TASKS}) endif() + if(CPPCHECK_ENABLE_INLINE_SUPPRESSION) + list(APPEND CPPCHECK_ARGUMENTS --inline-suppr) + endif() # Libraries foreach(_library ${CPPCHECK_LIBRARIES})