CMakePM: Make internal codemodel aware of Qt

In case we have no Qt inside the current kit configured the
code model stumbles upon Qt constructs even if
CMAKE_PREFIX_PATH has been used correctly to allow cmake to
pick up a Qt.
Explicitly look into the found packages to see whether Qt
has been found and use this if possible for the codemodel.

This fixes some inline diagnostics as well as finding all
test information inside Qt Test related projects instead of
just the test cases when using a kit without a Qt.

Change-Id: Id3b5d2e818967cd3121948b818c75c4cf463546f
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Christian Stenger
2023-11-07 14:21:47 +01:00
parent 437797d1c4
commit c6d1c962ee

View File

@@ -1004,6 +1004,30 @@ void CMakeBuildSystem::updateProjectData()
QtSupport::CppKitInfo kitInfo(kit());
QTC_ASSERT(kitInfo.isValid(), return );
struct QtMajorToPkgNames
{
QtMajorVersion major = QtMajorVersion::None;
QStringList pkgNames;
};
auto qtVersionFromCMake = [this](const QList<QtMajorToPkgNames> &mapping) {
for (const QtMajorToPkgNames &m : mapping) {
for (const QString &pkgName : m.pkgNames) {
auto qt = m_findPackagesFilesHash.value(pkgName);
if (qt.hasValidTarget())
return m.major;
}
}
return QtMajorVersion::None;
};
QtMajorVersion qtVersion = kitInfo.projectPartQtVersion;
if (qtVersion == QtMajorVersion::None)
qtVersion = qtVersionFromCMake({{QtMajorVersion::Qt6, {"Qt6", "Qt6Core"}},
{QtMajorVersion::Qt5, {"Qt5", "Qt5Core"}},
{QtMajorVersion::Qt4, {"Qt4", "Qt4Core"}}
});
QString errorMessage;
RawProjectParts rpps = m_reader.createRawProjectParts(errorMessage);
if (!errorMessage.isEmpty())
@@ -1011,8 +1035,7 @@ void CMakeBuildSystem::updateProjectData()
qCDebug(cmakeBuildSystemLog) << "Raw project parts created." << errorMessage;
for (RawProjectPart &rpp : rpps) {
rpp.setQtVersion(
kitInfo.projectPartQtVersion); // TODO: Check if project actually uses Qt.
rpp.setQtVersion(qtVersion); // TODO: Check if project actually uses Qt.
const FilePath includeFileBaseDir = buildConfiguration()->buildDirectory();
QStringList cxxFlags = rpp.flagsForCxx.commandLineFlags;
QStringList cFlags = rpp.flagsForC.commandLineFlags;