I am setting the build system for my C++ project first time. I am trying to integrate the Cppcheck static analysis tool with the CMake build system generator.
I have tried to set a few things and those seem is not working for me.
Please find below:
Code:
#include <iostream> int main(int argc, char **argv) { std::cout << "Hello, Stackoverflow!" << std::endl; char a[10]; a[10] = 0; std::cin.get(); return 0; } Cppcheck.cmake
if(ENABLE_CPPCHECK) find_program(CPPCHECK cppcheck) if(CPPCHECK) message("Path: ${CPPCHECK}") set(CPPCHECK_TEMPLATE "cppcheck:{file}:{line}: {severity}:{message}") # set(CMAKE_CXX_CPPCHECK ${CPPCHECK} # --enable=all # --enable=all # --inconclusive # --force # --inline-suppr # --template=${CPPCHECK_TEMPLATE} # --verbose # -i ${CMAKE_CURRENT_SOURCE_DIR}/src/ # ) add_custom_target(cppcheck COMMAND ${CPPCHECK} --enable=all --inconclusive --force --inline-suppr --template=${CPPCHECK_TEMPLATE} --verbose WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ COMMENT "Checking ..." VERBATIM ) message("debug value : ${CMAKE_CXX_CPPCHECK}") else() message(SEND_ERROR "cppcheck requested but executable not found") endif() endif() Result of cmake ..
-- Building for: Visual Studio 14 2015 -- Selecting Windows SDK version to target Windows 10.0.17763. -- The CXX compiler identification is MSVC 19.0.24215.1 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done Default build type: Debug Path: C:/Program Files/Cppcheck/cppcheck.exe debug value : C:/Program Files/Cppcheck/cppcheck.exe;--enable=all;--enable=all;--inconclusive;--force;--inline-suppr;--template=cppcheck:{file}:{line}: {severity}:{message};--verbose;-i;C:/dev/my-project/src/ -- Configuring done -- Generating done -- Build files have been written to: C:/dev/my-project/build cmake --build . result
PS C:\dev\my-project\build> cmake --build . Microsoft (R) Build Engine version 14.0.25420.1 Copyright (C) Microsoft Corporation. All rights reserved. Checking Build System Building Custom Rule C:/dev/my-project/src/CMakeLists.txt start.cpp start.vcxproj -> C:\dev\my-project\build\bin\Debug\start.exe start.vcxproj -> C:/dev/my-project/build/bin/Debug/start.pdb (Full PDB) Building Custom Rule C:/dev/my-project/CMakeLists.txt PS C:\dev\my-project\build> .\bin\Debug\start.exe Hello, Stackoverflow! I am using Visual studio code on windows. The CMake version is 3.18.
I am expecting here to get a warning from the Cppcheck on the terminal. Please let me know what is going wrong here.
https://stackoverflow.com/questions/65525407/how-do-i-compile-and-integrate-cppcheck-with-cmake-on-vs-code January 01, 2021 at 04:42AM
没有评论:
发表评论