From e732b675979037cb886fa408aecfa1cb28bece2e Mon Sep 17 00:00:00 2001 From: tbeu Date: Sun, 25 Feb 2024 09:53:11 +0100 Subject: [PATCH] Enable Cppcheck --- .github/workflows/cmake.yml | 2 +- CMakeLists.txt | 1 + cmake/options.cmake | 2 ++ cmake/staticAnalyzers.cmake | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 cmake/staticAnalyzers.cmake diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index a3ec48cf..a16e5e89 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -63,7 +63,7 @@ jobs: elif [ "${{ matrix.compiler }}" == "mingw" ]; then cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -G "MinGW Makefiles" else - cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF + cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DMATIO_ENABLE_CPPCHECK=ON fi - name: Build with ${{ matrix.compiler }} run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 745f549e..a99f4047 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/options.cmake b/cmake/options.cmake index f2e36459..4531d8e8 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -36,3 +36,5 @@ elseif(MATIO_DEFAULT_FILE_VERSION STREQUAL "7.3") else() message(ERROR "Unrecognized MAT file version") endif() + +option(MATIO_ENABLE_CPPCHECK "Enable static analysis with Cppcheck." OFF) diff --git a/cmake/staticAnalyzers.cmake b/cmake/staticAnalyzers.cmake new file mode 100644 index 00000000..085937ed --- /dev/null +++ b/cmake/staticAnalyzers.cmake @@ -0,0 +1,14 @@ +if(MATIO_ENABLE_CPPCHECK) + find_program(CPPCHECK cppcheck) + if(CPPCHECK) + set(CMAKE_C_CPPCHECK ${CPPCHECK} + --suppress=missingInclude + --enable=all + --inline-suppr + --inconclusive -i ${CMAKE_SOURCE_DIR}/imgui/lib + ) + message(VERBOSE "Cppcheck finished setting up.") + else() + message(SEND_ERROR "Cppcheck requested but executable not found.") + endif() +endif()