Menu

Running CppCheck on Visual Studio sln/vcxproj file from CMake project

Ali S
2017-03-22
2017-03-22
  • Ali S

    Ali S - 2017-03-22

    Hi,

    Using CppCheck 1.77, I'm trying to use the ‘--project' option on a 64-bit Visual Studio 2015 project that is created using CMake 3.6.2, but have encountered difficulties, detailed below.

    Using a basic new project created using Visual Studio 2015 (with some deliberate flaws added for CppCheck to detect), the '--project' option has worked successfully using the sln file and ALL_BUILD.vcxproj, which confirms that the option does work correctly for me in more basic circumstances.

    The behaviour I've observed on CMake projects is:
    1. Running on directory of source code: various errors detected and documented in xml
    2. Running on sln file: xml created but no errors listed in the errors section
    3. Running on ALL_BUILD.vcxproj: error 'No C or C++ source files found' and completely empty xml
    I’ve tried this on three different CMake projects and got the same behaviour each time, so I don’t believe the misbehaviour is down to a particular idiosyncrasy of my main project.

    Unfortunately I can’t share the exact code that I’m trying to analyse, but here are the equivalent steps for the GoogleTest project, which results in the same difficulties. The extra flags are just to increase the chance of issues and to provide distinct xml files for easier comparison.


    Download GTest (https://github.com/google/googletest)
    Extract to C:\Temp\googletest-master
    In Temp, run CppCheck on the folder of source code: "C:\Program Files\Cppcheck\cppcheck.exe" "C:\Temp\googletest-master" --enable=all --inconclusive --xml-version=2 2>cppcheck1_dir.xml
    This takes a moment to run and the created xml contains various suggestions mainly on style. Mine is a little under 500 lines long. (This is not intended a criticism of Google, by the way.)

    Create build folder alongside googletest-master: mkdir build
    Move into build folder: cd build
    Run CMake: cmake ..\googletest-master -G "Visual Studio 14 2015 Win64"
    Now have googletest-distribition.sln and ALL_BUILD.vcxproj in build folder. cd back up a level.

    In Temp, run CppCheck on the solution file: "C:\Program Files\Cppcheck\cppcheck.exe" --project="C:\Temp\build\googletest-distribution.sln" --enable=all --inconclusive --xml-version=2 2>cppcheck2_sln.xml
    This runs really quickly and this second created xml contains no errors.

    In Temp, run CppCheck on ALL_BUILD.vcxproj: "C:\Program Files\Cppcheck\cppcheck.exe" --project="C:\Temp\build\ALL_BUILD.vcxproj" --enable=all --inconclusive --xml-version=2 2>cppcheck3_vcxproj.xml
    This gives "cppcheck: No C or C++ source files found", and, unsurprisingly, the created xml is completely empty.


    Until now I have been running CppCheck on the project's folders of source code, but due to the folder structure some source files are in a different location to their headers, which is reducing CppCheck’s thoroughness. If needed I can perserve with this option, adding more configuration, or I could use a different generator so that CMAKE_EXPORT_COMPILE_COMMANDS is an option. However, I understand that using the sln/vcxproj file ought to work in theory so I’d prefer to use that if possible.

    In any case, it would be very helpful to know if other people have encountered the same problem, and guidance on how to resolve the issue would be greatly appreciated. Please let me know if there's any further information that I can provide.

    Thanks,
    Ali

     
  • Daniel Marjamäki

    sorry that it doesn't work well. I guess the importer is not perfect yet.

    I am not an expert in inner workings of Visual Studio configurations, in fact I rarelly use Visual Studio. I believe it helps if somebody who knows that well would take a look and try to see what part of the configuration that Cppcheck does not handle..

     
  • Ali S

    Ali S - 2017-04-03

    That's alright, thank you very much for the reply! Were you able to reproduce the problem using the GTest example?

    Unfortunately I am no expert on Visual Studio either, it is something of a necessary evil ;-)

     
  • Daniel Marjamäki

    Were you able to reproduce the problem using the GTest example?

    I've been looking at other stuff. there are so many problems.

     
  • Ali S

    Ali S - 2017-04-06

    No worries, I was just curious :)

    I got the --project option working successfully on the compile_commands.json file from a Ninja build made with the CMAKE_EXPORT_COMPILE_COMMANDS CMake option. From a practical perspective it provides what I needed, so that mitigates my immediate need for running CppCheck on a sln/vcxproj file.

    Amidst all the problems, I'd like you to know that my team has been really grateful for the value that CppCheck has given us. It's prompted discussions and has encouraged us to aim higher, which I really appreciate, so thank you.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.