forked from qt-creator/qt-creator
CMake: Handle files being in multiple targets when parsing cbp files
Change-Id: Ic85a7318e91e8a10a48c8433f22947fb71071832 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -97,8 +97,10 @@ void CMakeCbpParser::sortFiles()
|
|||||||
|
|
||||||
foreach (const FileName &fileName, fileNames) {
|
foreach (const FileName &fileName, fileNames) {
|
||||||
qCDebug(log) << fileName;
|
qCDebug(log) << fileName;
|
||||||
const QString unitTarget = m_unitTargetMap[fileName];
|
const QStringList unitTargets = m_unitTargetMap[fileName];
|
||||||
if (!unitTarget.isEmpty()) { // target was explicitly specified for that file
|
if (!unitTargets.isEmpty()) {
|
||||||
|
// cmake >= 3.3:
|
||||||
|
foreach (const QString &unitTarget, unitTargets) {
|
||||||
int index = Utils::indexOf(m_buildTargets, Utils::equal(&CMakeBuildTarget::title, unitTarget));
|
int index = Utils::indexOf(m_buildTargets, Utils::equal(&CMakeBuildTarget::title, unitTarget));
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
m_buildTargets[index].files.append(fileName.toString());
|
m_buildTargets[index].files.append(fileName.toString());
|
||||||
@@ -106,6 +108,10 @@ void CMakeCbpParser::sortFiles()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback for cmake < 3.3:
|
||||||
if (fileName.parentDir() == parentDirectory && last) {
|
if (fileName.parentDir() == parentDirectory && last) {
|
||||||
// easy case, same parent directory as last file
|
// easy case, same parent directory as last file
|
||||||
last->files.append(fileName.toString());
|
last->files.append(fileName.toString());
|
||||||
@@ -447,7 +453,7 @@ void CMakeCbpParser::parseUnit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_parsingCMakeUnit = false;
|
m_parsingCMakeUnit = false;
|
||||||
m_unitTarget.clear();
|
m_unitTargets.clear();
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
if (isEndElement()) {
|
if (isEndElement()) {
|
||||||
@@ -468,8 +474,7 @@ void CMakeCbpParser::parseUnit()
|
|||||||
else
|
else
|
||||||
m_fileList.append( new ProjectExplorer::FileNode(fileName, ProjectExplorer::SourceType, generated));
|
m_fileList.append( new ProjectExplorer::FileNode(fileName, ProjectExplorer::SourceType, generated));
|
||||||
}
|
}
|
||||||
if (!m_unitTarget.isEmpty())
|
m_unitTargetMap.insert(fileName, m_unitTargets);
|
||||||
m_unitTargetMap.insert(fileName, m_unitTarget);
|
|
||||||
m_processedUnits.insert(fileName);
|
m_processedUnits.insert(fileName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -485,7 +490,9 @@ void CMakeCbpParser::parseUnitOption()
|
|||||||
{
|
{
|
||||||
const QXmlStreamAttributes optionAttributes = attributes();
|
const QXmlStreamAttributes optionAttributes = attributes();
|
||||||
m_parsingCMakeUnit = optionAttributes.hasAttribute(QLatin1String("virtualFolder"));
|
m_parsingCMakeUnit = optionAttributes.hasAttribute(QLatin1String("virtualFolder"));
|
||||||
m_unitTarget = optionAttributes.value(QLatin1String("target")).toString();
|
const QString target = optionAttributes.value(QLatin1String("target")).toString();
|
||||||
|
if (!target.isEmpty())
|
||||||
|
m_unitTargets.append(target);
|
||||||
|
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ private:
|
|||||||
void parseUnknownElement();
|
void parseUnknownElement();
|
||||||
void sortFiles();
|
void sortFiles();
|
||||||
|
|
||||||
QMap<Utils::FileName, QString> m_unitTargetMap;
|
QMap<Utils::FileName, QStringList> m_unitTargetMap;
|
||||||
const ProjectExplorer::Kit *m_kit = 0;
|
const ProjectExplorer::Kit *m_kit = 0;
|
||||||
QList<ProjectExplorer::FileNode *> m_fileList;
|
QList<ProjectExplorer::FileNode *> m_fileList;
|
||||||
QList<ProjectExplorer::FileNode *> m_cmakeFileList;
|
QList<ProjectExplorer::FileNode *> m_cmakeFileList;
|
||||||
@@ -85,7 +85,7 @@ private:
|
|||||||
QString m_compiler;
|
QString m_compiler;
|
||||||
QString m_sourceDirectory;
|
QString m_sourceDirectory;
|
||||||
QString m_buildDirectory;
|
QString m_buildDirectory;
|
||||||
QString m_unitTarget;
|
QStringList m_unitTargets;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user