forked from qt-creator/qt-creator
cmake: Fix finding corresponding source directory from build directory
When trying to find the corresponding source directory for a build directory, it is better to just read it out of the CMakeDirectoryInformation.cmake file found in the CMakeFiles subdirectory of the build directory, instead of guessing it using the relative paths. Change-Id: Ie96b3255a27f46bcd7f0ab1566dfb91ac52f3be9 Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -1057,11 +1057,29 @@ void CMakeCbpParser::parseBuildTargetOption()
|
|||||||
m_buildTarget.targetType = TargetType(value.toInt());
|
m_buildTarget.targetType = TargetType(value.toInt());
|
||||||
} else if (attributes().hasAttribute(QLatin1String("working_dir"))) {
|
} else if (attributes().hasAttribute(QLatin1String("working_dir"))) {
|
||||||
m_buildTarget.workingDirectory = attributes().value(QLatin1String("working_dir")).toString();
|
m_buildTarget.workingDirectory = attributes().value(QLatin1String("working_dir")).toString();
|
||||||
|
|
||||||
|
QFile cmakeSourceInfoFile(m_buildTarget.workingDirectory
|
||||||
|
+ QStringLiteral("/CMakeFiles/CMakeDirectoryInformation.cmake"));
|
||||||
|
if (cmakeSourceInfoFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QTextStream stream(&cmakeSourceInfoFile);
|
||||||
|
const QLatin1String searchSource("SET(CMAKE_RELATIVE_PATH_TOP_SOURCE \"");
|
||||||
|
while (!stream.atEnd()) {
|
||||||
|
const QString lineTopSource = stream.readLine().trimmed();
|
||||||
|
if (lineTopSource.startsWith(searchSource)) {
|
||||||
|
m_buildTarget.sourceDirectory = lineTopSource.mid(searchSource.size());
|
||||||
|
m_buildTarget.sourceDirectory.chop(2); // cut off ")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_buildTarget.sourceDirectory.isEmpty()) {
|
||||||
QDir dir(m_buildDirectory);
|
QDir dir(m_buildDirectory);
|
||||||
QString relative = dir.relativeFilePath(m_buildTarget.workingDirectory);
|
const QString relative = dir.relativeFilePath(m_buildTarget.workingDirectory);
|
||||||
m_buildTarget.sourceDirectory
|
m_buildTarget.sourceDirectory
|
||||||
= Utils::FileName::fromString(m_sourceDirectory).appendPath(relative).toString();
|
= Utils::FileName::fromString(m_sourceDirectory).appendPath(relative).toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
if (isEndElement())
|
if (isEndElement())
|
||||||
|
|||||||
Reference in New Issue
Block a user