Skip to content

Commit

Permalink
CMake: Add support for Cppcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Jan 19, 2022
1 parent d754cb4 commit 9e8ff66
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .cppcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// clang-format off
constParameter
unusedFunction
missingIncludeSystem
noConstructor
noExplicitConstructor
redundantAssignment
uselessAssignmentPtrArg
preprocessorErrorDirective
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ option(WITH_STOKESIAN_DYNAMICS "Build with Stokesian Dynamics" OFF)
option(WITH_BENCHMARKS "Enable benchmarks" OFF)
option(WITH_VALGRIND_INSTRUMENTATION
"Build with valgrind instrumentation markers" OFF)
option(WITH_CPPCHECK "Run Cppcheck during compilation" OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
option(WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF)
endif()
Expand Down Expand Up @@ -421,6 +422,19 @@ if(WITH_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};--extra-arg=--cuda-host-only")
endif()

if(WITH_CPPCHECK)
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
if(NOT CMAKE_CXX_CPPCHECK)
message(FATAL_ERROR "Could not find the program cppcheck.")
endif()
list(APPEND CMAKE_CXX_CPPCHECK "--enable=all"
"--std=c++${CMAKE_CXX_STANDARD}" "--quiet" "--inline-suppr"
"--suppressions-list=${CMAKE_CURRENT_SOURCE_DIR}/.cppcheck")
if(WARNINGS_ARE_ERRORS)
list(APPEND CMAKE_CXX_CPPCHECK "--error-exitcode=2")
endif()
endif()

#
# Testing
#
Expand Down
1 change: 1 addition & 0 deletions src/core/CellStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ struct CellStructure {
*/
void update_particle_index(int id, Particle *p) {
assert(id >= 0);
// cppcheck-suppress assertWithSideEffect
assert(not p or id == p->identity());

if (id >= m_particle_index.size())
Expand Down

0 comments on commit 9e8ff66

Please sign in to comment.