CMake: Fix up file group information in server-mode

Server-mode reports a filegroup for all the listed headers and will
provide that without any information on the files (no language, include
paths, etc.).

Fix up file groups like these by using the best (with that being the
settings that effect the most other files) possible information for
these files.

CMake has no idea what headers are, so it has no way to provide any
better information, so Creator has to fix things up again:-/

Task-number: QTCREATORBUG-17971
Change-Id: Ib5ddab23cf725c7e03717b577cc9f9edc5bbfc61
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Tobias Hunger
2017-04-20 15:57:32 +02:00
parent ff46e67971
commit cad16c4bee
2 changed files with 47 additions and 0 deletions

View File

@@ -470,6 +470,8 @@ ServerModeReader::Target *ServerModeReader::extractTargetData(const QVariantMap
target->fileGroups.append(extractFileGroupData(fgData, srcDir, target));
}
fixTarget(target);
m_targets.append(target);
return target;
}
@@ -548,6 +550,49 @@ void ServerModeReader::extractCacheData(const QVariantMap &data)
m_cmakeCache = config;
}
void ServerModeReader::fixTarget(ServerModeReader::Target *target) const
{
QHash<QString, const FileGroup *> languageFallbacks;
for (const FileGroup *group : Utils::asConst(target->fileGroups)) {
if (group->includePaths.isEmpty() && group->compileFlags.isEmpty()
&& group->defines.isEmpty())
continue;
const FileGroup *fallback = languageFallbacks.value(group->language);
if (!fallback || fallback->sources.count() < group->sources.count())
languageFallbacks.insert(group->language, group);
}
if (!languageFallbacks.value(""))
return; // No empty language groups found, no need to proceed.
const FileGroup *fallback = languageFallbacks.value("CXX");
if (!fallback)
fallback = languageFallbacks.value("C");
if (!fallback)
fallback = languageFallbacks.value("");
if (!fallback)
return;
for (auto it = target->fileGroups.begin(); it != target->fileGroups.end(); ++it) {
if (!(*it)->language.isEmpty())
continue;
(*it)->language = fallback->language.isEmpty() ? "CXX" : fallback->language;
if (*it == fallback
|| !(*it)->includePaths.isEmpty() || !(*it)->defines.isEmpty()
|| !(*it)->compileFlags.isEmpty())
continue;
for (const IncludePath *ip : fallback->includePaths)
(*it)->includePaths.append(new IncludePath(*ip));
(*it)->defines = fallback->defines;
(*it)->compileFlags = fallback->compileFlags;
}
}
QHash<Utils::FileName, ProjectNode *>
ServerModeReader::addCMakeLists(CMakeProjectNode *root, const QList<FileNode *> &cmakeLists)
{

View File

@@ -113,6 +113,8 @@ private:
void extractCMakeInputsData(const QVariantMap &data);
void extractCacheData(const QVariantMap &data);
void fixTarget(Target *target) const;
QHash<Utils::FileName, ProjectExplorer::ProjectNode *>
addCMakeLists(CMakeProjectNode *root, const QList<ProjectExplorer::FileNode *> &cmakeLists);
void addProjects(const QHash<Utils::FileName, ProjectExplorer::ProjectNode *> &cmakeListsNodes,