build: Add support for cppcheck to cmake

This commit is contained in:
WerWolv
2025-07-10 13:55:05 +02:00
parent d1840a2184
commit e58ce527c6
6 changed files with 51 additions and 0 deletions

View File

@@ -66,6 +66,32 @@ function(addCommonFlag)
addObjCFlag(${ARGV0} ${ARGV1})
endfunction()
function(addCppCheck target)
if (NOT IMHEX_ENABLE_CPPCHECK)
return()
endif()
find_program(cppcheck_exe NAMES cppcheck REQUIRED)
if (NOT cppcheck_exe)
return()
endif()
set(target_build_dir $<TARGET_FILE_DIR:${target}>)
set(cppcheck_opts
--enable=all
--inline-suppr
--quiet
--std=c++23
--check-level=exhaustive
--error-exitcode=10
--suppressions-list=${CMAKE_SOURCE_DIR}/dist/cppcheck.supp
--checkers-report=${target_build_dir}/cppcheck-report.txt
)
set_target_properties(${target} PROPERTIES
CXX_CPPCHECK "${cppcheck_exe};${cppcheck_opts}"
)
endfunction()
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "Disable deprecated warnings" FORCE)
include(FetchContent)

View File

@@ -56,6 +56,7 @@ macro(add_imhex_plugin)
# Enable required compiler flags
enableUnityBuild(${IMHEX_PLUGIN_NAME})
setupCompilerFlags(${IMHEX_PLUGIN_NAME})
addCppCheck(${IMHEX_PLUGIN_NAME})
# Configure build properties
set_target_properties(${IMHEX_PLUGIN_NAME}