2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeprojectmanager.h"
|
2016-03-10 12:01:30 +01:00
|
|
|
#include "builddirmanager.h"
|
|
|
|
#include "cmakebuildconfiguration.h"
|
|
|
|
#include "cmakekitinformation.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeprojectconstants.h"
|
|
|
|
#include "cmakeproject.h"
|
2014-09-12 13:02:40 +04:00
|
|
|
#include "cmakesettingspage.h"
|
2015-02-04 17:54:46 +01:00
|
|
|
#include "cmaketoolmanager.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-23 16:57:38 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2011-02-23 15:52:43 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2015-07-14 13:10:18 +02:00
|
|
|
#include <projectexplorer/buildmanager.h>
|
2015-01-13 15:50:37 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2015-07-14 13:10:18 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/target.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <utils/synchronousprocess.h>
|
|
|
|
|
|
|
|
#include <QAction>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDateTime>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <QIcon>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-01-08 14:29:36 +01:00
|
|
|
using namespace ProjectExplorer;
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace CMakeProjectManager::Internal;
|
|
|
|
|
2016-01-07 15:22:53 +01:00
|
|
|
CMakeManager::CMakeManager() :
|
|
|
|
m_runCMakeAction(new QAction(QIcon(), tr("Run CMake"), this)),
|
2016-03-10 12:01:30 +01:00
|
|
|
m_clearCMakeCacheAction(new QAction(QIcon(), tr("Clear CMake Configuration"), this)),
|
2016-12-04 03:36:12 +10:00
|
|
|
m_runCMakeActionContextMenu(new QAction(QIcon(), tr("Run CMake"), this)),
|
2017-04-05 14:03:07 +02:00
|
|
|
m_rescanProjectAction(new QAction(QIcon(), tr("Rescan Project"), this))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-02-23 15:52:43 +01:00
|
|
|
Core::ActionContainer *mbuild =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_BUILDPROJECT);
|
2011-02-23 15:52:43 +01:00
|
|
|
Core::ActionContainer *mproject =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
|
2011-02-23 15:52:43 +01:00
|
|
|
Core::ActionContainer *msubproject =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
|
2011-02-23 15:52:43 +01:00
|
|
|
|
2011-04-12 12:17:19 +02:00
|
|
|
const Core::Context projectContext(CMakeProjectManager::Constants::PROJECTCONTEXT);
|
2016-03-10 12:01:30 +01:00
|
|
|
const Core::Context globalContext(Core::Constants::C_GLOBAL);
|
2011-04-12 12:17:19 +02:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(m_runCMakeAction,
|
2016-03-10 12:01:30 +01:00
|
|
|
Constants::RUNCMAKE, globalContext);
|
2011-02-23 15:52:43 +01:00
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
2012-04-26 19:28:59 +02:00
|
|
|
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
|
2014-09-12 14:09:40 +04:00
|
|
|
connect(m_runCMakeAction, &QAction::triggered, [this]() {
|
2016-01-08 14:29:36 +01:00
|
|
|
runCMake(SessionManager::startupProject());
|
2014-09-12 14:09:40 +04:00
|
|
|
});
|
2011-02-23 15:52:43 +01:00
|
|
|
|
2016-03-10 12:01:30 +01:00
|
|
|
command = Core::ActionManager::registerAction(m_clearCMakeCacheAction,
|
|
|
|
Constants::CLEARCMAKECACHE, globalContext);
|
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
|
|
|
|
connect(m_clearCMakeCacheAction, &QAction::triggered, [this]() {
|
|
|
|
clearCMakeCache(SessionManager::startupProject());
|
|
|
|
});
|
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(m_runCMakeActionContextMenu,
|
|
|
|
Constants::RUNCMAKECONTEXTMENU, projectContext);
|
2011-02-23 15:52:43 +01:00
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
|
|
|
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
2014-09-12 14:09:40 +04:00
|
|
|
connect(m_runCMakeActionContextMenu, &QAction::triggered, [this]() {
|
2016-01-08 14:29:36 +01:00
|
|
|
runCMake(ProjectTree::currentProject());
|
2014-09-12 14:09:40 +04:00
|
|
|
});
|
2011-02-23 15:52:43 +01:00
|
|
|
|
2016-12-04 03:36:12 +10:00
|
|
|
command = Core::ActionManager::registerAction(m_rescanProjectAction,
|
|
|
|
Constants::RESCANPROJECT, globalContext);
|
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
|
|
|
|
connect(m_rescanProjectAction, &QAction::triggered, [this]() {
|
|
|
|
rescanProject(ProjectTree::currentProject());
|
|
|
|
});
|
|
|
|
|
2016-01-08 14:29:36 +01:00
|
|
|
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
2016-03-10 12:01:30 +01:00
|
|
|
this, &CMakeManager::updateCmakeActions);
|
2016-01-08 14:29:36 +01:00
|
|
|
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
2016-03-10 12:01:30 +01:00
|
|
|
this, &CMakeManager::updateCmakeActions);
|
2015-07-14 13:10:18 +02:00
|
|
|
|
2016-03-10 12:01:30 +01:00
|
|
|
updateCmakeActions();
|
2011-02-23 15:52:43 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:01:30 +01:00
|
|
|
void CMakeManager::updateCmakeActions()
|
2011-02-23 15:52:43 +01:00
|
|
|
{
|
2016-01-08 14:29:36 +01:00
|
|
|
auto project = qobject_cast<CMakeProject *>(SessionManager::startupProject());
|
2016-03-10 12:01:30 +01:00
|
|
|
const bool visible = project && !BuildManager::isBuilding(project);
|
|
|
|
m_runCMakeAction->setVisible(visible);
|
|
|
|
m_clearCMakeCacheAction->setVisible(visible);
|
2016-12-04 03:36:12 +10:00
|
|
|
m_rescanProjectAction->setVisible(visible);
|
2016-03-10 12:01:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeManager::clearCMakeCache(Project *project)
|
|
|
|
{
|
|
|
|
if (!project || !project->activeTarget())
|
|
|
|
return;
|
|
|
|
auto bc = qobject_cast<CMakeBuildConfiguration *>(project->activeTarget()->activeBuildConfiguration());
|
|
|
|
if (!bc)
|
|
|
|
return;
|
|
|
|
|
2016-10-06 11:31:27 +02:00
|
|
|
bc->clearCache();
|
2011-02-23 15:52:43 +01:00
|
|
|
}
|
|
|
|
|
2016-01-08 14:29:36 +01:00
|
|
|
void CMakeManager::runCMake(Project *project)
|
2011-02-23 15:52:43 +01:00
|
|
|
{
|
|
|
|
if (!project)
|
|
|
|
return;
|
|
|
|
CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(project);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration())
|
2011-02-23 15:52:43 +01:00
|
|
|
return;
|
2013-06-18 17:54:11 +02:00
|
|
|
|
2016-01-08 14:29:36 +01:00
|
|
|
if (!ProjectExplorerPlugin::saveModifiedFiles())
|
2013-06-18 17:54:11 +02:00
|
|
|
return;
|
2011-02-23 15:52:43 +01:00
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
cmakeProject->runCMake();
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2016-12-04 03:36:12 +10:00
|
|
|
void CMakeManager::rescanProject(Project *project)
|
|
|
|
{
|
|
|
|
if (!project)
|
|
|
|
return;
|
|
|
|
CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(project);
|
|
|
|
if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration())
|
|
|
|
return;
|
|
|
|
|
|
|
|
cmakeProject->scanProjectTree();
|
|
|
|
cmakeProject->runCMake(); // by my experience: every rescan run requires cmake run too
|
|
|
|
}
|