Commit 6bb51244 authored by Daniel Teske's avatar Daniel Teske Committed by Daniel Teske

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: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 21638efe
......@@ -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());
......
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