summaryrefslogtreecommitdiff
path: root/src/plugins/cmakeprojectmanager
diff options
context:
space:
mode:
authorClaus Steuer <claus755@gmail.com>2015-04-20 15:59:18 +0200
committerDaniel Teske <daniel.teske@theqtcompany.com>2015-04-24 09:36:52 +0000
commit81f64f85a054125d053bfae8ba1c66294aab03ce (patch)
tree3b062de3b774e9d34a77cc636f9ff14cc5316fe6 /src/plugins/cmakeprojectmanager
parentd4bb5033b251e8afb612158011ebd89082664345 (diff)
downloadqt-creator-81f64f85a054125d053bfae8ba1c66294aab03ce.tar.gz
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>
Diffstat (limited to 'src/plugins/cmakeprojectmanager')
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeproject.cpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
index 4ae5adf480..a0392a8d00 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
@@ -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
// found
// Get "all" target's working directory
- QString buildNinjaFile = QDir::fromNativeSeparators(buildTarget.workingDirectory);
- buildNinjaFile += QLatin1String("/build.ninja");
- QFile buildNinja(buildNinjaFile);
- if (buildNinja.exists()) {
- buildNinja.open(QIODevice::ReadOnly | QIODevice::Text);
- QTextStream stream(&buildNinja);
- bool cxxFound = false;
- while (!stream.atEnd()) {
- QString line = stream.readLine().trimmed();
- // Look for a build rule which invokes CXX_COMPILER
- if (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);
+ 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();
+ 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);
+ }
}
}
}