Skip to content

Commit

Permalink
cmake: New CMake option CPPCHECK_EXTRA_FLAGS
Browse files Browse the repository at this point in the history
It can be used to pass additional command line flags to `cppcheck`.
  • Loading branch information
krivenko committed Jul 18, 2024
1 parent 9f7f09e commit bd58913
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ All notable changes to this project will be documented in this file.
Credits to Dr. Cezary Śliwa for providing the patch.
- Whenever possible, use compiler intrinsics to speed up complex bit
manipulation operations (``popcount``).
- New CMake option ``CPPCHECK_EXTRA_FLAGS``. It can be used to pass additional
command line flags to ``cppcheck``.

## [0.7.2] - 2022-11-12

Expand Down
9 changes: 9 additions & 0 deletions cmake/StaticAnalysis.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.10)
find_program(CPPCHECK_EXECUTABLE
NAMES "cppcheck" REQUIRED
DOC "Path to the cppcheck executable")
set(CPPCHECK_EXTRA_FLAGS "" CACHE STRING
"Semicolon-separated list of additional flags to be passed to cppcheck")

mark_as_advanced(CPPCHECK_EXECUTABLE)
mark_as_advanced(CPPCHECK_EXTRA_FLAGS)

message(STATUS "Using cppcheck: ${CPPCHECK_EXECUTABLE}")
set(CMAKE_CXX_CPPCHECK
Expand All @@ -41,6 +45,11 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.10)
"--force"
"--quiet"
)

if(CPPCHECK_EXTRA_FLAGS)
message(STATUS "Extra flags passed to cppcheck: ${CPPCHECK_EXTRA_FLAGS}")
list(APPEND CMAKE_CXX_CPPCHECK ${CPPCHECK_EXTRA_FLAGS})
endif(CPPCHECK_EXTRA_FLAGS)
else(CMAKE_VERSION VERSION_GREATER_EQUAL 3.10)
message(WARNING "CMake >= 3.10 is required to run cppcheck")
endif(CMAKE_VERSION VERSION_GREATER_EQUAL 3.10)
3 changes: 3 additions & 0 deletions doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ meaning.
+------------------------------+-----------------------------------------------+
| ``CPPCHECK_EXECUTABLE`` | [DEV] Path to the ``cppcheck`` executable. |
+------------------------------+-----------------------------------------------+
| ``CPPCHECK_EXTRA_FLAGS`` | [DEV] Semicolon-separated list of additional |
| | flags to be passed to ``cppcheck``. |
+------------------------------+-----------------------------------------------+

0 comments on commit bd58913

Please sign in to comment.