CMakeProject: Fix CXX Flags parsing for ninja projects

For ninja projects the "build.ninja" file is parsed to extract the cxx
flags for each target. This file is located in the working directory
of the "all" target, however since commit "65c113bc" qtcreator searches
in the build directory of the current target. I have restored the
search behavior to the previous state and added some code to ensure
that the parsed flags really belong to the target

Change-Id: I7cc7f6dbd4f12aec698133206da889037131bb13
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
Claus Steuer
2015-04-20 15:59:18 +02:00
committed by Daniel Teske
parent d4bb5033b2
commit 81f64f85a0

View File

@@ -204,21 +204,31 @@ QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget)
// Attempt to find build.ninja file and obtain FLAGS (CXX_FLAGS) from there if no suitable flags.make were // Attempt to find build.ninja file and obtain FLAGS (CXX_FLAGS) from there if no suitable flags.make were
// found // found
// Get "all" target's working directory // Get "all" target's working directory
QString buildNinjaFile = QDir::fromNativeSeparators(buildTarget.workingDirectory); if (!buildTargets().empty()) {
buildNinjaFile += QLatin1String("/build.ninja"); QString buildNinjaFile = QDir::fromNativeSeparators(buildTargets().at(0).workingDirectory);
QFile buildNinja(buildNinjaFile); buildNinjaFile += QLatin1String("/build.ninja");
if (buildNinja.exists()) { QFile buildNinja(buildNinjaFile);
buildNinja.open(QIODevice::ReadOnly | QIODevice::Text); if (buildNinja.exists()) {
QTextStream stream(&buildNinja); buildNinja.open(QIODevice::ReadOnly | QIODevice::Text);
bool cxxFound = false; QTextStream stream(&buildNinja);
while (!stream.atEnd()) { bool targetFound = false;
QString line = stream.readLine().trimmed(); bool cxxFound = false;
// Look for a build rule which invokes CXX_COMPILER QString targetSearchPattern = QString::fromLatin1("target %1").arg(buildTarget.title);
if (line.startsWith(QLatin1String("build"))) {
cxxFound = line.indexOf(QLatin1String("CXX_COMPILER")) != -1; while (!stream.atEnd()) {
} else if (cxxFound && line.startsWith(QLatin1String("FLAGS ="))) { // 1. Look for a block that refers to the current target
// Skip past = // 2. Look for a build rule which invokes CXX_COMPILER
return line.mid(7).trimmed().split(QLatin1Char(' '), QString::SkipEmptyParts); // 3. Return the FLAGS definition
QString line = stream.readLine().trimmed();
if (line.startsWith(QLatin1String("#"))) {
if (!line.startsWith(QLatin1String("# Object build statements for"))) continue;
targetFound = line.endsWith(targetSearchPattern);
} else if (targetFound && line.startsWith(QLatin1String("build"))) {
cxxFound = line.indexOf(QLatin1String("CXX_COMPILER")) != -1;
} else if (cxxFound && line.startsWith(QLatin1String("FLAGS ="))) {
// Skip past =
return line.mid(7).trimmed().split(QLatin1Char(' '), QString::SkipEmptyParts);
}
} }
} }
} }