forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/3.5'
Change-Id: Iebaabfc2f724cd493b7cab025406531cea5cd2dc
This commit is contained in:
@@ -177,7 +177,7 @@ void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QStri
|
||||
parseCMakeLists();
|
||||
}
|
||||
|
||||
QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget)
|
||||
QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget, QByteArray *cachedBuildNinja)
|
||||
{
|
||||
QString makeCommand = QDir::fromNativeSeparators(buildTarget.makeCommand);
|
||||
int startIndex = makeCommand.indexOf(QLatin1Char('\"'));
|
||||
@@ -206,32 +206,43 @@ QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget)
|
||||
// found
|
||||
// Get "all" target's working directory
|
||||
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);
|
||||
}
|
||||
if (cachedBuildNinja->isNull()) {
|
||||
QString buildNinjaFile = QDir::fromNativeSeparators(buildTargets().at(0).workingDirectory);
|
||||
buildNinjaFile += QLatin1String("/build.ninja");
|
||||
QFile buildNinja(buildNinjaFile);
|
||||
if (buildNinja.exists()) {
|
||||
buildNinja.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
*cachedBuildNinja = buildNinja.readAll();
|
||||
buildNinja.close();
|
||||
} else {
|
||||
*cachedBuildNinja = QByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
if (cachedBuildNinja->isEmpty())
|
||||
return QStringList();
|
||||
|
||||
QTextStream stream(cachedBuildNinja);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
@@ -338,13 +349,15 @@ bool CMakeProject::parseCMakeLists()
|
||||
|
||||
ppBuilder.setQtVersion(activeQtVersion);
|
||||
|
||||
QByteArray cachedBuildNinja;
|
||||
foreach (const CMakeBuildTarget &cbt, m_buildTargets) {
|
||||
// This explicitly adds -I. to the include paths
|
||||
QStringList includePaths = cbt.includeFiles;
|
||||
includePaths += projectDirectory().toString();
|
||||
ppBuilder.setIncludePaths(includePaths);
|
||||
ppBuilder.setCFlags(getCXXFlagsFor(cbt));
|
||||
ppBuilder.setCxxFlags(getCXXFlagsFor(cbt));
|
||||
QStringList cxxflags = getCXXFlagsFor(cbt, &cachedBuildNinja);
|
||||
ppBuilder.setCFlags(cxxflags);
|
||||
ppBuilder.setCxxFlags(cxxflags);
|
||||
ppBuilder.setDefines(cbt.defines);
|
||||
ppBuilder.setDisplayName(cbt.title);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user