forked from qt-creator/qt-creator
CMakeProjectManager: Fix findCMakeNode function
Via CMake project we can add subdirectory like: > add_subdirectory("subdir/subsubdir" "enotherdir") Where "subdir" my not contain "CMakeLists.txt" file. And intermediate directory can contain CMakeLists.txt file that is not a part of the root node. This change fix it. Task-number: QTCREATORBUG-17721 Change-Id: Ice9fba1ca5a979955ec8f44324f75f3bc16ee198 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -573,17 +573,27 @@ static CMakeListsNode *findCMakeNode(CMakeListsNode *root, const Utils::FileName
|
|||||||
const Utils::FileName stepDir = dir;
|
const Utils::FileName stepDir = dir;
|
||||||
const Utils::FileName topDir = root->filePath().parentDir();
|
const Utils::FileName topDir = root->filePath().parentDir();
|
||||||
|
|
||||||
QStringList relative = stepDir.relativeChildPath(topDir).toString().split('/');
|
QStringList relative = stepDir.relativeChildPath(topDir).toString().split('/', QString::SkipEmptyParts);
|
||||||
|
|
||||||
CMakeListsNode *result = root;
|
CMakeListsNode *result = root;
|
||||||
|
|
||||||
|
QString relativePathElement;
|
||||||
while (!relative.isEmpty()) {
|
while (!relative.isEmpty()) {
|
||||||
const QString nextPathElement = relative.takeFirst();
|
const QString nextDirPath = result->filePath().parentDir().toString();
|
||||||
if (nextPathElement.isEmpty())
|
Utils::FileName nextFullPath;
|
||||||
continue;
|
// Some directory may not contain CMakeLists.txt file, skip it:
|
||||||
const QString nextFullPath
|
do {
|
||||||
= result->filePath().parentDir().toString() + '/' + nextPathElement + "/CMakeLists.txt";
|
relativePathElement += '/' + relative.takeFirst();
|
||||||
result = static_cast<CMakeListsNode *>(result->projectNode(Utils::FileName::fromString(nextFullPath)));
|
nextFullPath = Utils::FileName::fromString(nextDirPath + relativePathElement + "/CMakeLists.txt");
|
||||||
|
} while (!nextFullPath.exists() && !relative.isEmpty());
|
||||||
|
result = static_cast<CMakeListsNode *>(result->projectNode(nextFullPath));
|
||||||
|
// Intermediate directory can contain CMakeLists.txt file
|
||||||
|
// that is not a part of the root node, skip it:
|
||||||
|
if (!result && !relative.isEmpty()) {
|
||||||
|
result = root;
|
||||||
|
} else {
|
||||||
|
relativePathElement.clear();
|
||||||
|
}
|
||||||
QTC_ASSERT(result, return nullptr);
|
QTC_ASSERT(result, return nullptr);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user