2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/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
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt 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"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
|
|
|
|
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>
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDateTime>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
using namespace CMakeProjectManager::Internal;
|
|
|
|
|
2009-01-21 16:25:21 +01:00
|
|
|
CMakeManager::CMakeManager(CMakeSettingsPage *cmakeSettingsPage)
|
|
|
|
: m_settingsPage(cmakeSettingsPage)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-02-23 15:52:43 +01:00
|
|
|
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
|
2014-09-12 14:09:40 +04:00
|
|
|
connect(projectExplorer, &ProjectExplorer::ProjectExplorerPlugin::aboutToShowContextMenu,
|
|
|
|
this, &CMakeManager::updateContextMenu);
|
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);
|
|
|
|
|
2011-03-31 09:57:24 +02:00
|
|
|
m_runCMakeAction = new QAction(QIcon(), tr("Run CMake"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(m_runCMakeAction,
|
|
|
|
Constants::RUNCMAKE, projectContext);
|
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]() {
|
|
|
|
runCMake(ProjectExplorer::ProjectExplorerPlugin::currentProject());
|
|
|
|
});
|
2011-02-23 15:52:43 +01:00
|
|
|
|
2011-03-31 09:57:24 +02:00
|
|
|
m_runCMakeActionContextMenu = new QAction(QIcon(), tr("Run CMake"), this);
|
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]() {
|
|
|
|
runCMake(m_contextProject);
|
|
|
|
});
|
2011-02-23 15:52:43 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-12 14:09:40 +04:00
|
|
|
void CMakeManager::updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node *)
|
2011-02-23 15:52:43 +01:00
|
|
|
{
|
|
|
|
m_contextProject = project;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeManager::runCMake(ProjectExplorer::Project *project)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->saveModifiedFiles())
|
|
|
|
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);
|
|
|
|
|
2014-03-26 17:36:06 +01:00
|
|
|
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), this, 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
|
|
|
}
|
|
|
|
|
2011-09-05 13:47:29 +02:00
|
|
|
ProjectExplorer::Project *CMakeManager::openProject(const QString &fileName, QString *errorString)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-05-27 11:17:47 +02:00
|
|
|
if (!QFileInfo(fileName).isFile()) {
|
|
|
|
if (errorString)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorString = tr("Failed opening project \"%1\": Project is not a file")
|
2013-05-27 11:17:47 +02:00
|
|
|
.arg(fileName);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
return new CMakeProject(this, fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-01-23 16:57:38 +01:00
|
|
|
QString CMakeManager::cmakeExecutable() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->cmakeExecutable();
|
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
bool CMakeManager::isCMakeExecutableValid() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->isCMakeExecutableValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeManager::setCMakeExecutable(const QString &executable)
|
|
|
|
{
|
|
|
|
m_settingsPage->setCMakeExecutable(executable);
|
|
|
|
}
|
|
|
|
|
2009-07-02 11:30:29 +02:00
|
|
|
bool CMakeManager::hasCodeBlocksMsvcGenerator() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->hasCodeBlocksMsvcGenerator();
|
|
|
|
}
|
|
|
|
|
2012-10-02 17:46:12 +02:00
|
|
|
bool CMakeManager::hasCodeBlocksNinjaGenerator() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->hasCodeBlocksNinjaGenerator();
|
|
|
|
}
|
|
|
|
|
2013-02-16 14:54:13 +08:00
|
|
|
bool CMakeManager::preferNinja() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->preferNinja();
|
|
|
|
}
|
|
|
|
|
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
|
2010-10-19 11:14:03 +02:00
|
|
|
void CMakeManager::createXmlFile(Utils::QtcProcess *proc, const QString &arguments,
|
2010-09-23 10:35:23 +02:00
|
|
|
const QString &sourceDirectory, const QDir &buildDirectory,
|
|
|
|
const Utils::Environment &env, const QString &generator)
|
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);
|
|
|
|
Utils::QtcProcess::addArg(&args, generator);
|
|
|
|
proc->setCommand(cmakeExecutable(), args);
|
|
|
|
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
|
|
|
}
|