From 6bb51244cab5bd71cf9161ff4399ca9816aa5d2e Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Thu, 6 Nov 2014 17:04:06 +0100 Subject: [PATCH] Cmake: Fix include paths for some cmake projects The affected cmake projects have the CMakeLists.txt in a subdirectory of the project's root. We can't figure out the right project part in that case. Falling back to the "all" target is wrong though, since that has not every include path. Instead search for a good target that has more include paths. Change-Id: I1a874042fcb9533888a41c001fbf8adc2aa90a39 Reviewed-by: Tobias Hunger --- src/plugins/cmakeprojectmanager/cmakeproject.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index d19792f49f0..bf671f5136a 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -868,6 +868,20 @@ void CMakeCbpParser::sortFiles() CMakeBuildTarget *last = 0; Utils::FileName parentDirectory; + // find a good build target to fall back + int fallbackIndex = 0; + { + int bestIncludeCount = -1; + for (int i = 0; i < m_buildTargets.size(); ++i) { + const CMakeBuildTarget &target = m_buildTargets.at(i); + if (target.sourceDirectory == m_sourceDirectory + && target.includeFiles.count() > bestIncludeCount) { + bestIncludeCount = target.includeFiles.count(); + fallbackIndex = i; + } + } + } + foreach (const Utils::FileName &fileName, fileNames) { if (fileName.parentDir() == parentDirectory && last) { // easy case, same parent directory as last file @@ -890,7 +904,7 @@ void CMakeCbpParser::sortFiles() } if (bestIndex == -1 && !m_buildTargets.isEmpty()) - bestIndex = 0; + bestIndex = fallbackIndex; if (bestIndex != -1) { m_buildTargets[bestIndex].files.append(fileName.toString());