forked from qt-creator/qt-creator
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:
committed by
Daniel Teske
parent
d4bb5033b2
commit
81f64f85a0
@@ -204,17 +204,26 @@ 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
|
||||
// found
|
||||
// Get "all" target's working directory
|
||||
QString buildNinjaFile = QDir::fromNativeSeparators(buildTarget.workingDirectory);
|
||||
if (!buildTargets().empty()) {
|
||||
QString buildNinjaFile = QDir::fromNativeSeparators(buildTargets().at(0).workingDirectory);
|
||||
buildNinjaFile += QLatin1String("/build.ninja");
|
||||
QFile buildNinja(buildNinjaFile);
|
||||
if (buildNinja.exists()) {
|
||||
buildNinja.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
QTextStream stream(&buildNinja);
|
||||
bool targetFound = false;
|
||||
bool cxxFound = false;
|
||||
QString targetSearchPattern = QString::fromLatin1("target %1").arg(buildTarget.title);
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
// 1. Look for a block that refers to the current target
|
||||
// 2. Look for a build rule which invokes CXX_COMPILER
|
||||
// 3. Return the FLAGS definition
|
||||
QString line = stream.readLine().trimmed();
|
||||
// Look for a build rule which invokes CXX_COMPILER
|
||||
if (line.startsWith(QLatin1String("build"))) {
|
||||
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 =
|
||||
@@ -222,6 +231,7 @@ QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user