mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
build: Add support for cppcheck to cmake
This commit is contained in:
@@ -25,6 +25,7 @@ option(IMHEX_ENABLE_IMGUI_TEST_ENGINE "Enable the ImGui Test Engine"
|
||||
option(IMHEX_ENABLE_PRECOMPILED_HEADERS "Enable precompiled headers" OFF)
|
||||
option(IMHEX_COMPRESS_DEBUG_INFO "Compress debug information" ON )
|
||||
option(IMHEX_ENABLE_CXX_MODULES "Enable C++20 Module compilation. Testing only!" OFF)
|
||||
option(IMHEX_ENABLE_CPPCHECK "Enable cppcheck static analysis" OFF)
|
||||
|
||||
set(IMHEX_BASE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(CMAKE_MODULE_PATH "${IMHEX_BASE_FOLDER}/cmake/modules")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
|
||||
20
dist/cppcheck.supp
vendored
Normal file
20
dist/cppcheck.supp
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
missingIncludeSystem
|
||||
constParameter
|
||||
unusedFunction
|
||||
preprocessorErrorDirective
|
||||
checkersReport
|
||||
noExplicitConstructor
|
||||
unmatchedSuppression
|
||||
useInitializationList
|
||||
useStlAlgorithm
|
||||
knownConditionTrueFalse
|
||||
internalAstError
|
||||
unsignedPositive
|
||||
variableScope
|
||||
unusedPrivateFunction
|
||||
constParameterCallback
|
||||
|
||||
*:*/lib/third_party/*
|
||||
*:*/external/pattern_language/external/*
|
||||
*:*/external/disassembler/external/*
|
||||
*:*/lib/libimhex/source/ui/imgui_imhex_extensions.cpp
|
||||
@@ -97,6 +97,8 @@ else()
|
||||
target_compile_definitions(libimhex PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}")
|
||||
endif()
|
||||
|
||||
addCppCheck(libimhex)
|
||||
|
||||
|
||||
if (DEFINED IMHEX_COMMIT_HASH_LONG AND DEFINED IMHEX_COMMIT_BRANCH)
|
||||
set(GIT_COMMIT_HASH_LONG "${IMHEX_COMMIT_HASH_LONG}")
|
||||
|
||||
@@ -28,6 +28,7 @@ add_executable(main ${APPLICATION_TYPE}
|
||||
)
|
||||
|
||||
target_include_directories(main PUBLIC include)
|
||||
addCppCheck(main)
|
||||
setupCompilerFlags(main)
|
||||
setupCompilerFlags(libimhex)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user