Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Visual Studio's C++ Core Check analysis only on project files?

I am a big fan of the C++ Core Guidelines and I like to follow them in all projects I work on, so I enabled the following option in my project template in Visual Studio 2017:

The C++ Core Check project option

This tool is great and helps me write better code, but I simply cannot figure out how to make it only analyze my files. Whenever my project has a dependency such as Boost or OpenCV, I will get plastered with a wall of warnings:

C++ Core Check warnings on dependencies

These dependencies are added through vcpkg, however, the same thing happens when adding them manually with C/C++ > General > Additional Include Directories.

Is there any way to only make these warnings apply to project files, and not all included files?

like image 340
Michael Smith Avatar asked Mar 30 '18 20:03

Michael Smith


People also ask

How do I turn off code analysis in Visual Studio?

To open this page, right-click the project node in Solution Explorer and select Properties. Select the Code Analysis tab. To disable source analysis at build time, uncheck the Run on build option. To disable live source analysis, uncheck the Run on live analysis option.

How do I run a Visual Studio code analysis?

In Solution Explorer, select the project. On the Analyze menu, select Run Code Analysis on [Project Name].

How do I run a ReSharper code analysis?

ReSharper helps you resolve most of the discovered code issues automatically. All you need is to press Alt+Enter when the caret is on a code issue highlighted in the editor and check the suggested quick-fixes.


1 Answers

As mentioned in the comments, right after the following section in your .vcxproj near the end of the file:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
</ImportGroup>

The problem may be solved by adding the following after the section mentioned above:

<PropertyGroup Condition="'$(Language)'=='C++'">
  <CAExcludePath>$(QTDIR)\include;.\GeneratedFiles;$(CAExcludePath)</CAExcludePath>
</PropertyGroup>

Furthermore, if you are using vcpkg, which was the case in my situation, you will need to add the following element to the CAExcludePath:

$(VcpkgRoot)include

This will ensure that all headers from any packages will not be analyzed.

like image 104
Michael Smith Avatar answered Sep 21 '22 00:09

Michael Smith