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 <tobias.hunger@theqtcompany.com>
This commit is contained in:
Daniel Teske
2014-11-06 17:04:06 +01:00
committed by Daniel Teske
parent 21638efe9d
commit 6bb51244ca

View File

@@ -868,6 +868,20 @@ void CMakeCbpParser::sortFiles()
CMakeBuildTarget *last = 0; CMakeBuildTarget *last = 0;
Utils::FileName parentDirectory; 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) { foreach (const Utils::FileName &fileName, fileNames) {
if (fileName.parentDir() == parentDirectory && last) { if (fileName.parentDir() == parentDirectory && last) {
// easy case, same parent directory as last file // easy case, same parent directory as last file
@@ -890,7 +904,7 @@ void CMakeCbpParser::sortFiles()
} }
if (bestIndex == -1 && !m_buildTargets.isEmpty()) if (bestIndex == -1 && !m_buildTargets.isEmpty())
bestIndex = 0; bestIndex = fallbackIndex;
if (bestIndex != -1) { if (bestIndex != -1) {
m_buildTargets[bestIndex].files.append(fileName.toString()); m_buildTargets[bestIndex].files.append(fileName.toString());