forked from qt-creator/qt-creator
CMake: Further fine tune file -> target mapping
Instead of requiring that the target's source directory is a parent of all source files, use a distance between the source and directory and the file. This will find the wrong CMakeLists.txt in more cases but also is much more likely to lead to using the fallback target. This makes code completion work for http://github.com/dream3d/dream3d/ Change-Id: Ic035454c5eabe361bc7c46bd943e9a9cdee730e3 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -852,6 +852,15 @@ void CMakeBuildSettingsWidget::runCMake()
|
|||||||
// CMakeCbpParser
|
// CMakeCbpParser
|
||||||
////
|
////
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
int distance(const QString &targetDirectory, const Utils::FileName &fileName)
|
||||||
|
{
|
||||||
|
const QString commonParent = Utils::commonPath(QStringList() << targetDirectory << fileName.toString());
|
||||||
|
return targetDirectory.mid(commonParent.size()).count(QLatin1Char('/'))
|
||||||
|
+ fileName.toString().mid(commonParent.size()).count(QLatin1Char('/'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// called after everything is parsed
|
// called after everything is parsed
|
||||||
// this function tries to figure out to which CMakeBuildTarget
|
// this function tries to figure out to which CMakeBuildTarget
|
||||||
// each file belongs, so that it gets the appropriate defines and
|
// each file belongs, so that it gets the appropriate defines and
|
||||||
@@ -889,7 +898,7 @@ void CMakeCbpParser::sortFiles()
|
|||||||
// 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());
|
||||||
} else {
|
} else {
|
||||||
int bestLength = -1;
|
int bestDistance = std::numeric_limits<int>::max();
|
||||||
int bestIndex = -1;
|
int bestIndex = -1;
|
||||||
int bestIncludeCount = -1;
|
int bestIncludeCount = -1;
|
||||||
|
|
||||||
@@ -897,11 +906,11 @@ void CMakeCbpParser::sortFiles()
|
|||||||
const CMakeBuildTarget &target = m_buildTargets.at(i);
|
const CMakeBuildTarget &target = m_buildTargets.at(i);
|
||||||
if (target.includeFiles.isEmpty())
|
if (target.includeFiles.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
if (fileName.isChildOf(Utils::FileName::fromString(target.sourceDirectory)) &&
|
int dist = distance(target.sourceDirectory, fileName);
|
||||||
(target.sourceDirectory.size() > bestLength ||
|
if (dist < bestDistance ||
|
||||||
(target.sourceDirectory.size() == bestLength &&
|
(dist == bestDistance &&
|
||||||
target.includeFiles.count() > bestIncludeCount))) {
|
target.includeFiles.count() > bestIncludeCount)) {
|
||||||
bestLength = target.sourceDirectory.size();
|
bestDistance = dist;
|
||||||
bestIncludeCount = target.includeFiles.count();
|
bestIncludeCount = target.includeFiles.count();
|
||||||
bestIndex = i;
|
bestIndex = i;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user