Skip to content

Commit

Permalink
Enable cppcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Feb 25, 2024
1 parent 06413da commit 96c43bf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ jobs:
if [ "${{ matrix.compiler }}" == "msvc" ]; then
cmake -S . -B build -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF
elif [ "${{ matrix.compiler }}" == "mingw" ]; then
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -G "MinGW Makefiles"
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DMATIO_ENABLE_CPPCHECK=ON -G "MinGW Makefiles"
elif [ "${{ matrix.compiler }}" == "gcc" ]; then
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DMATIO_ENABLE_CPPCHECK=ON
else
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF
fi
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ include(GNUInstallDirs)
include(cmake/options.cmake)
include(cmake/conan.cmake)
include(cmake/thirdParties.cmake)
include(cmake/staticAnalyzers.cmake)
include(cmake/compilerOptions.cmake)
include(cmake/getopt.cmake)
include(cmake/src.cmake)
Expand Down
4 changes: 4 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ elseif(MATIO_DEFAULT_FILE_VERSION STREQUAL "7.3")
else()
message(ERROR "Unrecognized MAT file version")
endif()

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.10")
option(MATIO_ENABLE_CPPCHECK "Enable static analysis with Cppcheck." OFF)
endif()
22 changes: 22 additions & 0 deletions cmake/staticAnalyzers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if(MATIO_ENABLE_CPPCHECK)
find_program(CPPCHECK cppcheck)
if(CPPCHECK)
set(CMAKE_C_CPPCHECK ${CPPCHECK}
--language=c
--check-level=exhaustive
--suppress=checkersReport
--suppress=unusedFunction
--suppress=unmatchedSuppression
--suppress=missingIncludeSystem
--enable=all
--inline-suppr
--inconclusive
-i ${CMAKE_SOURCE_DIR}/test
-i ${CMAKE_SOURCE_DIR}/snprintf
-i ${CMAKE_SOURCE_DIR}/getopt
)
message(VERBOSE "Cppcheck finished setting up.")
else()
message(SEND_ERROR "Cppcheck requested but executable not found.")
endif()
endif()
8 changes: 6 additions & 2 deletions cmake/thirdParties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ if(MATIO_WITH_HDF5)
endif()

if(MATIO_USE_CONAN)
set(MATIO_CONAN_REQUIRES "hdf5/[>=1.8 <1.15]" "zlib/[>=1.2.3]")
if(MATIO_ENABLE_CPPCHECK)
list(APPEND MATIO_CONAN_REQUIRES "cppcheck/[>=2.13.3]")
endif()
if(HDF5_USE_STATIC_LIBRARIES)
conan_cmake_run(
REQUIRES "hdf5/[>=1.8 <1.15]" "zlib/[>=1.2.3]"
REQUIRES ${MATIO_CONAN_REQUIRES}
BASIC_SETUP CMAKE_TARGETS
OPTIONS hdf5:shared=False zlib:shared=False
BUILD missing
)
else()
conan_cmake_run(
REQUIRES "hdf5/[>=1.8 <1.15]" "zlib/[>=1.2.3]"
REQUIRES ${MATIO_CONAN_REQUIRES}
BASIC_SETUP CMAKE_TARGETS
OPTIONS hdf5:shared=True zlib:shared=True
BUILD missing)
Expand Down

0 comments on commit 96c43bf

Please sign in to comment.