summaryrefslogtreecommitdiff
path: root/src/plugins/cmakeprojectmanager
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@theqtcompany.com>2015-09-01 12:57:51 +0200
committerEike Ziller <eike.ziller@theqtcompany.com>2015-09-01 12:57:51 +0200
commit3b1a966cc8ec6899097035386d37a2f9b6107e58 (patch)
tree6b89da17f7b646c3f00ebb711edf8891962e60eb /src/plugins/cmakeprojectmanager
parentfb73a87033c35c6a8199a2136381814e5a2e2e87 (diff)
parenta80f4d179b5ef0dd8a149c96c08d56004f916a70 (diff)
downloadqt-creator-3b1a966cc8ec6899097035386d37a2f9b6107e58.tar.gz
Merge remote-tracking branch 'origin/3.5'
Change-Id: Iebaabfc2f724cd493b7cab025406531cea5cd2dc
Diffstat (limited to 'src/plugins/cmakeprojectmanager')
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeproject.cpp65
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeproject.h2
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp23
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.h3
4 files changed, 55 insertions, 38 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
index 22894371d5..3fbc00f746 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
@@ -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);
+ 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();
+ }
+ }
- 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->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);
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h
index 27d88b1613..304413cdc4 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.h
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.h
@@ -139,7 +139,7 @@ private:
QString uiHeaderFile(const QString &uiFile);
void updateRunConfigurations(ProjectExplorer::Target *t);
void updateApplicationAndDeploymentTargets();
- QStringList getCXXFlagsFor(const CMakeBuildTarget &buildTarget);
+ QStringList getCXXFlagsFor(const CMakeBuildTarget &buildTarget, QByteArray *cachedBuildNinja);
Internal::CMakeManager *m_manager;
ProjectExplorer::Target *m_activeTarget;
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
index 476d3da3d9..a50d483d24 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
@@ -39,9 +39,11 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
+#include <projectexplorer/buildmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projecttree.h>
+#include <projectexplorer/session.h>
#include <utils/synchronousprocess.h>
@@ -52,10 +54,6 @@ using namespace CMakeProjectManager::Internal;
CMakeManager::CMakeManager()
{
- ProjectExplorer::ProjectTree *tree = ProjectExplorer::ProjectTree::instance();
- connect(tree, &ProjectExplorer::ProjectTree::aboutToShowContextMenu,
- this, &CMakeManager::updateContextMenu);
-
Core::ActionContainer *mbuild =
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_BUILDPROJECT);
Core::ActionContainer *mproject =
@@ -64,14 +62,15 @@ CMakeManager::CMakeManager()
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
const Core::Context projectContext(CMakeProjectManager::Constants::PROJECTCONTEXT);
+ const Core::Context globalcontext(Core::Constants::C_GLOBAL);
m_runCMakeAction = new QAction(QIcon(), tr("Run CMake"), this);
Core::Command *command = Core::ActionManager::registerAction(m_runCMakeAction,
- Constants::RUNCMAKE, projectContext);
+ Constants::RUNCMAKE, globalcontext);
command->setAttribute(Core::Command::CA_Hide);
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
connect(m_runCMakeAction, &QAction::triggered, [this]() {
- runCMake(ProjectExplorer::ProjectTree::currentProject());
+ runCMake(ProjectExplorer::SessionManager::startupProject());
});
m_runCMakeActionContextMenu = new QAction(QIcon(), tr("Run CMake"), this);
@@ -81,14 +80,20 @@ CMakeManager::CMakeManager()
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(m_runCMakeActionContextMenu, &QAction::triggered, [this]() {
- runCMake(m_contextProject);
+ runCMake(ProjectExplorer::ProjectTree::currentProject());
});
+ connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::startupProjectChanged,
+ this, &CMakeManager::updateRunCmakeAction);
+ connect(ProjectExplorer::BuildManager::instance(), &ProjectExplorer::BuildManager::buildStateChanged,
+ this, &CMakeManager::updateRunCmakeAction);
+
}
-void CMakeManager::updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node *)
+void CMakeManager::updateRunCmakeAction()
{
- m_contextProject = project;
+ auto project = qobject_cast<CMakeProject *>(ProjectExplorer::SessionManager::startupProject());
+ m_runCMakeAction->setVisible(project && !ProjectExplorer::BuildManager::isBuilding(project));
}
void CMakeManager::runCMake(ProjectExplorer::Project *project)
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h
index 6c50ea34cf..0d8af0b35c 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h
@@ -69,14 +69,13 @@ public:
static QString findCbpFile(const QDir &);
private:
- void updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node *node);
+ void updateRunCmakeAction();
void runCMake(ProjectExplorer::Project *project);
private:
CMakeSettingsPage *m_settingsPage;
QAction *m_runCMakeAction;
QAction *m_runCMakeActionContextMenu;
- ProjectExplorer::Project *m_contextProject;
};
} // namespace Internal