forked from qt-creator/qt-creator
CMakeProject: Set file target with most includes
This fixes regression 65c113bcbc that caused
files to be likely assigned to "all" target when all CMake targets were having
sources residing in same directory using Ninja generator. As "all" came first
then it became best match in such case.
This introduces slight modification, so target with most include paths is
chosen from these having best file system proximity to source file. Doing so we
select likely real target and get all #include preprocessor directives resolved
properly in the editor.
Change-Id: Ifb85bb5954b4cf5618a6d8444c993c69ebab2259
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Reviewed-by: Stephen Kelly <steveire@gmail.com>
This commit is contained in:
committed by
Daniel Teske
parent
f0251e7e4f
commit
390afc104d
@@ -875,12 +875,16 @@ void CMakeCbpParser::sortFiles()
|
||||
} else {
|
||||
int bestLength = -1;
|
||||
int bestIndex = -1;
|
||||
int bestIncludeCount = -1;
|
||||
|
||||
for (int i = 0; i < m_buildTargets.size(); ++i) {
|
||||
const CMakeBuildTarget &target = m_buildTargets.at(i);
|
||||
if (fileName.isChildOf(Utils::FileName::fromString(target.sourceDirectory))
|
||||
&& target.sourceDirectory.size() > bestLength) {
|
||||
if (fileName.isChildOf(Utils::FileName::fromString(target.sourceDirectory)) &&
|
||||
(target.sourceDirectory.size() > bestLength ||
|
||||
(target.sourceDirectory.size() == bestLength &&
|
||||
target.includeFiles.count() > bestIncludeCount))) {
|
||||
bestLength = target.sourceDirectory.size();
|
||||
bestIncludeCount = target.includeFiles.count();
|
||||
bestIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user