Commit 390afc10 authored by Adam Strzelecki's avatar Adam Strzelecki Committed by Daniel Teske
Browse files

CMakeProject: Set file target with most includes

This fixes regression 65c113bc

 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: default avatarDaniel Teske <>
Reviewed-by: default avatarStephen Kelly <>
parent f0251e7e
......@@ -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 =;
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;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment