1

Based on this answer, I've added the below code to my .vcxproj file, which nicely eliminates most warnings that I was getting from Qt include files, and its autogenerated moc files.

<PropertyGroup Condition="'$(Language)'=='C++'">
  <CAExcludePath>C:\Qt\5.13.1\msvc2017_64\include;.\ProjectName_autogen;$(CAExcludePath)</CAExcludePath>
</PropertyGroup>

This is great for one specific project, but since I use CMake, on multiple computers, this would get overwritten each time the CMake file changes, and I would have to add it to each Project I need it for (there's 3 projects that use Qt). Of course, the issue is also if I change the Qt path, then I would need to update the project files as well.

I am wondering, is there a CMake property I can set in order to add this to the projects? I know how to get Qt's include directory, just looking for the CMake property to actually set the CAExcludePath. If it helps, I'm using VS 2019, and this is to disable the warnings from Code Analysis.

I did check the cmake-properties page, but didn't find any predefined properties which seem to fit.

ChrisMM
  • 8,448
  • 13
  • 29
  • 48

1 Answers1

2

I figured it out. For anyone interested, I created a file called user.props which looks like the following:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Language)'=='C++'">
    <CAExcludePath>@QWT_INCLUDE_DIR@;@QT_INCLUDE_DIR@;.;$(CAExcludePath)</CAExcludePath>
  </PropertyGroup>
</Project>

Then, in the CMakeList.txt root file, I have

SET( RULESET_PATH ${CMAKE_CURRENT_BINARY_DIR}/user.props )
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/user.props ${RULESET_PATH} @ONLY)

Then for each project I want to apply it to, I have

SET_PROPERTY( TARGET "ProjectName" PROPERTY VS_USER_PROPS "${RULESET_PATH}" )

There might be a more direct way, but this works.

ChrisMM
  • 8,448
  • 13
  • 29
  • 48