2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
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"
|
2013-03-12 12:12:24 +01:00
|
|
|
#include "cmakeopenprojectwizard.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>
|
2015-02-26 13:38:54 +01:00
|
|
|
|
|
|
|
#include <utils/synchronousprocess.h>
|
|
|
|
|
|
|
|
#include <QAction>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDateTime>
|
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)),
|
|
|
|
m_runCMakeActionContextMenu(new QAction(QIcon(), tr("Run CMake"), 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);
|
2015-07-14 13:10:18 +02: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,
|
2015-07-14 13:10:18 +02: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
|
|
|
|
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-01-08 14:29:36 +01:00
|
|
|
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
2015-07-14 13:10:18 +02:00
|
|
|
this, &CMakeManager::updateRunCmakeAction);
|
2016-01-08 14:29:36 +01:00
|
|
|
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
2015-07-14 13:10:18 +02:00
|
|
|
this, &CMakeManager::updateRunCmakeAction);
|
|
|
|
|
2011-02-23 15:52:43 +01:00
|
|
|
}
|
|
|
|
|
2015-07-14 13:10:18 +02:00
|
|
|
void CMakeManager::updateRunCmakeAction()
|
2011-02-23 15:52:43 +01:00
|
|
|
{
|
2016-01-08 14:29:36 +01:00
|
|
|
auto project = qobject_cast<CMakeProject *>(SessionManager::startupProject());
|
|
|
|
m_runCMakeAction->setVisible(project && !BuildManager::isBuilding(project));
|
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
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
CMakeBuildConfiguration *bc
|
2012-07-04 13:05:52 +02:00
|
|
|
= static_cast<CMakeBuildConfiguration *>(cmakeProject->activeTarget()->activeBuildConfiguration());
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2013-07-22 15:53:57 +02:00
|
|
|
CMakeBuildInfo info(bc);
|
|
|
|
|
2016-01-07 17:30:49 +01:00
|
|
|
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), CMakeOpenProjectWizard::WantToUpdate, &info);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (copw.exec() == QDialog::Accepted)
|
2012-07-17 15:56:43 +02:00
|
|
|
cmakeProject->parseCMakeLists();
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-08 14:29:36 +01:00
|
|
|
Project *CMakeManager::openProject(const QString &fileName, QString *errorString)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-02-02 00:37:38 +02:00
|
|
|
Utils::FileName file = Utils::FileName::fromString(fileName);
|
|
|
|
if (!file.toFileInfo().isFile()) {
|
2013-05-27 11:17:47 +02:00
|
|
|
if (errorString)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorString = tr("Failed opening project \"%1\": Project is not a file")
|
2015-02-02 00:37:38 +02:00
|
|
|
.arg(file.toUserOutput());
|
2013-05-27 11:17:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
return new CMakeProject(this, file);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeManager::mimeType() const
|
|
|
|
{
|
2014-07-17 15:52:32 +02:00
|
|
|
return QLatin1String(Constants::CMAKEPROJECTMIMETYPE);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-01-21 16:25:21 +01:00
|
|
|
|
2016-01-07 17:30:49 +01:00
|
|
|
bool CMakeManager::preferNinja()
|
2013-02-16 14:54:13 +08:00
|
|
|
{
|
2015-02-04 17:54:46 +01:00
|
|
|
return CMakeToolManager::preferNinja();
|
2013-02-16 14:54:13 +08:00
|
|
|
}
|
|
|
|
|
2012-05-03 16:05:03 +02:00
|
|
|
// need to refactor this out
|
2009-01-23 16:57:38 +01:00
|
|
|
// we probably want the process instead of this function
|
|
|
|
// cmakeproject then could even run the cmake process in the background, adding the files afterwards
|
|
|
|
// sounds like a plan
|
2016-01-07 17:30:49 +01:00
|
|
|
void CMakeManager::createXmlFile(Utils::QtcProcess *proc, const QString &executable,
|
|
|
|
const QString &arguments, const QString &sourceDirectory,
|
2016-01-08 14:43:10 +01:00
|
|
|
const QDir &buildDirectory, const Utils::Environment &env)
|
2009-01-23 16:57:38 +01:00
|
|
|
{
|
|
|
|
QString buildDirectoryPath = buildDirectory.absolutePath();
|
|
|
|
buildDirectory.mkpath(buildDirectoryPath);
|
2009-10-21 13:45:49 +02:00
|
|
|
proc->setWorkingDirectory(buildDirectoryPath);
|
2010-10-19 11:14:03 +02:00
|
|
|
proc->setEnvironment(env);
|
2009-03-03 17:56:03 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
const QString srcdir = buildDirectory.exists(QLatin1String("CMakeCache.txt")) ?
|
|
|
|
QString(QLatin1Char('.')) : sourceDirectory;
|
2010-10-19 11:14:03 +02:00
|
|
|
QString args;
|
|
|
|
Utils::QtcProcess::addArg(&args, srcdir);
|
|
|
|
Utils::QtcProcess::addArgs(&args, arguments);
|
2016-01-08 14:43:10 +01:00
|
|
|
|
2015-02-24 21:57:00 +01:00
|
|
|
proc->setCommand(executable, args);
|
2010-10-19 11:14:03 +02:00
|
|
|
proc->start();
|
2009-01-23 16:57:38 +01:00
|
|
|
}
|
|
|
|
|
2009-03-09 18:13:19 +01:00
|
|
|
QString CMakeManager::findCbpFile(const QDir &directory)
|
|
|
|
{
|
|
|
|
// Find the cbp file
|
2012-05-03 16:05:03 +02:00
|
|
|
// the cbp file is named like the project() command in the CMakeList.txt file
|
2013-10-07 13:34:40 +02:00
|
|
|
// so this function below could find the wrong cbp file, if the user changes the project()
|
2009-03-09 18:13:19 +01:00
|
|
|
// 2name
|
2011-11-16 14:15:54 +01:00
|
|
|
QDateTime t;
|
|
|
|
QString file;
|
2009-03-09 18:13:19 +01:00
|
|
|
foreach (const QString &cbpFile , directory.entryList()) {
|
2011-11-16 14:15:54 +01:00
|
|
|
if (cbpFile.endsWith(QLatin1String(".cbp"))) {
|
|
|
|
QFileInfo fi(directory.path() + QLatin1Char('/') + cbpFile);
|
|
|
|
if (t.isNull() || fi.lastModified() > t) {
|
|
|
|
file = directory.path() + QLatin1Char('/') + cbpFile;
|
|
|
|
t = fi.lastModified();
|
|
|
|
}
|
|
|
|
}
|
2009-03-09 18:13:19 +01:00
|
|
|
}
|
2011-11-16 14:15:54 +01:00
|
|
|
return file;
|
2009-03-09 18:13:19 +01:00
|
|
|
}
|