diff options
author | Daniel Teske <daniel.teske@theqtcompany.com> | 2014-11-20 15:09:15 +0100 |
---|---|---|
committer | Daniel Teske <daniel.teske@theqtcompany.com> | 2014-11-20 16:30:38 +0100 |
commit | 0390ece76152cc6cd2e54495855819a09f91b5d6 (patch) | |
tree | f96a3aa7eea1861dffd0c67bae9e59efb969c705 /src/plugins/cmakeprojectmanager | |
parent | f88ad0ce424432325affcab8bd2f620c39243d95 (diff) | |
download | qt-creator-0390ece76152cc6cd2e54495855819a09f91b5d6.tar.gz |
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>
Diffstat (limited to 'src/plugins/cmakeprojectmanager')
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakeproject.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index a2ec61245f..b1e17ada63 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -852,6 +852,15 @@ void CMakeBuildSettingsWidget::runCMake() // 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 // this function tries to figure out to which CMakeBuildTarget // 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 last->files.append(fileName.toString()); } else { - int bestLength = -1; + int bestDistance = std::numeric_limits<int>::max(); int bestIndex = -1; int bestIncludeCount = -1; @@ -897,11 +906,11 @@ void CMakeCbpParser::sortFiles() const CMakeBuildTarget &target = m_buildTargets.at(i); if (target.includeFiles.isEmpty()) continue; - if (fileName.isChildOf(Utils::FileName::fromString(target.sourceDirectory)) && - (target.sourceDirectory.size() > bestLength || - (target.sourceDirectory.size() == bestLength && - target.includeFiles.count() > bestIncludeCount))) { - bestLength = target.sourceDirectory.size(); + int dist = distance(target.sourceDirectory, fileName); + if (dist < bestDistance || + (dist == bestDistance && + target.includeFiles.count() > bestIncludeCount)) { + bestDistance = dist; bestIncludeCount = target.includeFiles.count(); bestIndex = i; } |